Brought back the ilink3/ilink2 encoding abstraction.

This commit is contained in:
Pedro Pinto committed 2020-06-25 16:49:46 -04:00
1 parent b2471d45b2
commit 45aa75e8bb
10 files changed
+202 -379

No files matched your search

@@ -63,7 +63,9 @@ iLink2OrderEncoder::~iLink2OrderEncoder() {}
void iLink2OrderEncoder::init(OrderKey key,
api::orderman::RoutingRecord const &rr,
api::Security const &security,
api::orderman::OrderDefinition const &def) {
api::orderman::OrderDefinition const &def,
int price_encoding_precision,
bool stop_order_has_been_triggered) {
me->security = &security;
me->order_type = def.custom_def().custom_case();
@@ -92,6 +94,7 @@ void iLink2OrderEncoder::init(OrderKey key,
create_encoding.add<fix::ClOrdID>(clordid);
create_encoding.add<fix::CustOrderHandlingInst>(
get_cust_order_handling_inst(rr));
if (rr.smp_id().size()) {
create_encoding.add<fix::SelfMatchPreventionID>(rr.smp_id());
if (rr.smp_instruction() != SELF_MATCH_PREVENTION_INSTRUCTION_UNDEFINED)
@@ -167,43 +170,78 @@ void iLink2OrderEncoder::init(OrderKey key,
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
// price
me->create_price_bm = create_encoding.add<fix::Price>(0, 9, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(0, 9, price_sz());
me->create_price_bm = create_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
break;
case CustomOrderDefinition::kStop: {
// type
create_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP);
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP);
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP);
// stop px
auto stop_px = def.custom_def().stop().stop_price();
auto encoded_stop_px =
securities::encode_exchange_price(*me->security, Price(stop_px))
.value();
create_encoding.add<fix::StopPx>(encoded_stop_px, 9, -1);
// Stop orders go through two stages. Before the stop price is
// triggered they are stop orders and have no price field, only
// stop px. After being triggered they become regular limit
// orders and have only price, not stop px fields.
if (stop_order_has_been_triggered) {
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
me->update_price_bm = update_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
me->update_stop_px_bm = {};
} else {
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP);
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP);
me->update_price_bm = {};
me->update_stop_px_bm = update_encoding.add<fix::StopPx>(
0, price_encoding_precision, price_sz());
}
create_encoding.add<fix::StopPx>(encoded_stop_px,
price_encoding_precision, -1);
break;
}
case CustomOrderDefinition::kStopLimit: {
// type
create_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP_LIMIT);
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP_LIMIT);
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP_LIMIT);
// stop px
auto stop_px = def.custom_def().stop_limit().stop_price();
auto encoded_stop_px =
securities::encode_exchange_price(*me->security, Price(stop_px))
.value();
create_encoding.add<fix::StopPx>(encoded_stop_px, 9, -1);
me->update_stop_px_bm =
update_encoding.add<fix::StopPx>(encoded_stop_px, 9, -1);
// price
me->create_price_bm = create_encoding.add<fix::Price>(0, 9, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(0, 9, price_sz());
// Like stop orders, stop limits go through two stages. Before
// the stop price is triggered they are stop limit orders and
// have both a price and a stop px price field. After being
// triggered they become regular limit orders and have only
// price, not stop px fields.
if (stop_order_has_been_triggered) {
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
me->update_price_bm = update_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
me->update_stop_px_bm = {};
} else {
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP_LIMIT);
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_STOP_LIMIT);
me->create_price_bm = create_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
me->update_stop_px_bm = update_encoding.add<fix::StopPx>(
0, price_encoding_precision, price_sz());
}
create_encoding.add<fix::StopPx>(encoded_stop_px,
price_encoding_precision, -1);
break;
}
case CustomOrderDefinition::kGlbxIceberg: {
@@ -214,8 +252,10 @@ void iLink2OrderEncoder::init(OrderKey key,
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
// price
me->create_price_bm = create_encoding.add<fix::Price>(0, 9, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(0, 9, price_sz());
me->create_price_bm = create_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
me->update_price_bm = update_encoding.add<fix::Price>(
0, price_encoding_precision, price_sz());
// max show qty
auto max_show_qty = def.custom_def().glbx_iceberg().max_show_quantity();
@@ -288,7 +328,6 @@ void iLink2OrderEncoder::update_cancel_replace_encoding(
Price p, int price_precision, Quantity q, OrderServices &services) {
auto &encoding = me->update_encoding;
// All good
me->update_price_bm = encoding.overwrite(
me->update_price_bm,
securities::encode_exchange_price(*me->security, p).value(),
@@ -303,6 +342,35 @@ void iLink2OrderEncoder::update_cancel_replace_encoding(
me->update_corid_bm = update_corid(me->update_corid_bm, encoding, corid);
}
void iLink2OrderEncoder::update_cancel_replace_encoding(
Quantity q, OrderServices &services) {
auto &encoding = me->update_encoding;
me->update_quantity_bm =
encoding.overwrite(me->update_quantity_bm, q.value(), quantity_sz());
auto &ts = services.get_time_str();
auto corid = services.corid();
me->update_transact_time_bm = encoding.overwrite(
me->update_transact_time_bm, &ts.value()[0], ts.value().size());
me->update_corid_bm = update_corid(me->update_corid_bm, encoding, corid);
}
void iLink2OrderEncoder::update_cancel_replace_encoding(
Price p, int price_precision, OrderServices &services) {
auto &encoding = me->update_encoding;
me->update_price_bm = encoding.overwrite(
me->update_price_bm,
securities::encode_exchange_price(*me->security, p).value(),
price_precision, price_sz());
auto &ts = services.get_time_str();
auto corid = services.corid();
me->update_transact_time_bm = encoding.overwrite(
me->update_transact_time_bm, &ts.value()[0], ts.value().size());
me->update_corid_bm = update_corid(me->update_corid_bm, encoding, corid);
}
void iLink2OrderEncoder::update_cancel_encoding(OrderServices &services) {
auto &encoding = me->cancel_encoding;
auto &ts = services.get_time_str();