Brought back the ilink3/ilink2 encoding abstraction.
This commit is contained in:
1 parent
b2471d45b2
commit
45aa75e8bb
10 files changed
+202
-379
No files matched your search
@@ -1 +1 @@
|
||||
set(sources /home/eric/spark/doc/user/build.sh;content/_index.md;content/bts_spark/Glossary/_index.md;content/bts_spark/Help/_index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Launcher/_index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Logging-In-to-the-System/_index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Market/_index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/_index.md;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/Settings/_index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Spreader/_index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Trading/OrderTypes/index.md;content/bts_spark/Trading/_index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/release_notes/_index.md;content/system_requirements/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
|
||||
set(sources /home/ppinto/Dropbox/bts/spark/doc/user/build.sh;content/_index.md;content/bts_spark/Glossary/_index.md;content/bts_spark/Help/_index.md;content/bts_spark/Help/about_spark.png;content/bts_spark/Help/image39.png;content/bts_spark/Help/image58.png;content/bts_spark/Launcher/_index.md;content/bts_spark/Launcher/image38.png;content/bts_spark/Launcher/image68.png;content/bts_spark/Logging-In-to-the-System/_index.md;content/bts_spark/Logging-In-to-the-System/image3.png;content/bts_spark/Logging-In-to-the-System/image64.png;content/bts_spark/Market/_index.md;content/bts_spark/Market/change_securities.png;content/bts_spark/Market/image11.png;content/bts_spark/Market/image14.png;content/bts_spark/Market/image20.png;content/bts_spark/Market/image21.png;content/bts_spark/Market/image23.png;content/bts_spark/Market/image24.png;content/bts_spark/Market/image34.png;content/bts_spark/Market/image49.png;content/bts_spark/Market/image53.png;content/bts_spark/Market/image66.png;content/bts_spark/Market/image69.png;content/bts_spark/Market/market_view.png;content/bts_spark/Market/settings_icon.png;content/bts_spark/Market/time_and_sales.png;content/bts_spark/My-Windows/_index.md;content/bts_spark/My-Windows/image15.png;content/bts_spark/My-Windows/image16.png;content/bts_spark/My-Windows/image37.png;content/bts_spark/Settings/_index.md;content/bts_spark/Settings/image51.png;content/bts_spark/Settings/image9.png;content/bts_spark/Spreader/_index.md;content/bts_spark/Spreader/image10.png;content/bts_spark/Spreader/image13.png;content/bts_spark/Spreader/image18.png;content/bts_spark/Spreader/image19.png;content/bts_spark/Spreader/image28.png;content/bts_spark/Spreader/image29.png;content/bts_spark/Spreader/image31.png;content/bts_spark/Spreader/image35.png;content/bts_spark/Spreader/image40.png;content/bts_spark/Spreader/image43.png;content/bts_spark/Spreader/image54.png;content/bts_spark/Spreader/image55.png;content/bts_spark/Spreader/image56.png;content/bts_spark/Spreader/image6.png;content/bts_spark/Spreader/image7.png;content/bts_spark/Spreader/image70.png;content/bts_spark/Spreader/image72.png;content/bts_spark/Spreader/image8.png;content/bts_spark/Trading/OrderTypes/index.md;content/bts_spark/Trading/_index.md;content/bts_spark/Trading/algo_studio.png;content/bts_spark/Trading/collapse_all_icon.png;content/bts_spark/Trading/cover_algo_control.png;content/bts_spark/Trading/expand_all_icon.png;content/bts_spark/Trading/image1.png;content/bts_spark/Trading/image17.png;content/bts_spark/Trading/image2.png;content/bts_spark/Trading/image25.png;content/bts_spark/Trading/image27.png;content/bts_spark/Trading/image33.png;content/bts_spark/Trading/image42.png;content/bts_spark/Trading/image44.png;content/bts_spark/Trading/image47.png;content/bts_spark/Trading/image48.png;content/bts_spark/Trading/image5.png;content/bts_spark/Trading/image50.png;content/bts_spark/Trading/image52.png;content/bts_spark/Trading/image57.png;content/bts_spark/Trading/image59.png;content/bts_spark/Trading/image60.png;content/bts_spark/Trading/image61.png;content/bts_spark/Trading/image62.png;content/bts_spark/Trading/image73.png;content/bts_spark/Trading/image74.png;content/bts_spark/Trading/join_algo_control.png;content/bts_spark/Trading/ladder.png;content/bts_spark/Trading/ladder_badges.png;content/bts_spark/Trading/ladder_main_part.png;content/bts_spark/Trading/lean_algo_control.png;content/bts_spark/Trading/mini_orderbook.png;content/bts_spark/Trading/oco_algo_control.png;content/bts_spark/Trading/offset_algo_control.png;content/bts_spark/Trading/pnl_calculation.png;content/bts_spark/Trading/pnl_window.png;content/bts_spark/Trading/recreate_icon.png;content/bts_spark/Trading/settings_icon.png;content/bts_spark/Trading/spark_menu_order_book.png;content/bts_spark/Trading/top_algo_control.png;content/bts_spark/Trading/trigger_algo_control.png;content/bts_spark/_index.md;content/release_notes/_index.md;content/system_requirements/_index.md;static/book.js;static/favicon.ico;static/image.js;templates/index.html;templates/page.html;templates/section.html;templates/shortcodes/back_button.html)
|
||||
@@ -264,7 +264,7 @@ const char* translate_establish_reject(int reason) {
|
||||
return "Unknown or invalid Establish reject reason.";
|
||||
}
|
||||
|
||||
std::string encode_clordid(bts::orderman::OrderKey key, SecurityKey security) {
|
||||
std::string encode_clordid(bts::orderman::OrderKey key, SecurityKey ) {
|
||||
// 20 character string
|
||||
//
|
||||
return utils::to_base_62(key.value());
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/config/protos/orderman_cfg.pb.h"
|
||||
#include "lib/config/protos/toggles.pb.h"
|
||||
#include "lib/domain_model/Security.h"
|
||||
#include "lib/jetfix/codec/FIXFragment.h"
|
||||
@@ -12,10 +13,12 @@
|
||||
#include "lib/orderman/orderman_utils/ExecutionReport.h"
|
||||
#include "lib/orderman/orderman_utils/fix_order_codec.h"
|
||||
#include "lib/orderman/orders/PreActivationOrderServices.h"
|
||||
#include "lib/orderman/orders/glbx/IGLBXOrderEncoder.h"
|
||||
#include "lib/orderman/orders/glbx/iLink2OrderEncoder.h"
|
||||
#include "lib/orderman/orders/glbx/iLink3OrderEncoder.h"
|
||||
#include "lib/orderman/securities/ISecurityDB.h"
|
||||
#include "lib/utils/PBUtils.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
#include "lib/config/protos/orderman_cfg.pb.h"
|
||||
|
||||
#include "lib/orderman/actors/order_manager/OrderServices.h"
|
||||
|
||||
@@ -49,6 +52,8 @@ struct NativeOrder::PImpl {
|
||||
SessionServices *session_services;
|
||||
|
||||
const api::Security *sec;
|
||||
std::unique_ptr<IGLBXOrderEncoder> encoder;
|
||||
|
||||
Quantity previous_working_position;
|
||||
|
||||
OrderDefinition definition;
|
||||
@@ -56,42 +61,15 @@ struct NativeOrder::PImpl {
|
||||
int price_encoding_precision;
|
||||
std::string exchange_order_id;
|
||||
|
||||
jetfix::FIXFragment update_encoding;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::Price> update_price_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::OrderQty> update_quantity_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::MaxShow> update_max_show_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::StopPx> update_stop_px_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::TransactTimeStr>
|
||||
update_transact_time_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::Text> update_corid_bm;
|
||||
|
||||
jetfix::FIXFragment create_encoding;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::Price> create_price_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::OrderQty> create_quantity_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::TransactTimeStr>
|
||||
create_transact_time_bm;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::Text> create_corid_bm;
|
||||
|
||||
jetfix::FIXFragment cancel_encoding;
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::TransactTimeStr>
|
||||
cancel_transact_time_bm;
|
||||
|
||||
OrderServices::ExeReportSubID exe_report_sid;
|
||||
OrderServices::CancelRejectSubID cancel_reject_sid;
|
||||
|
||||
bool buffered_cancel = false;
|
||||
std::optional<api::orderman::Update> buffered_update;
|
||||
RoutingRecord routing_record;
|
||||
bool stop_order_still_has_stop_px = true;
|
||||
};
|
||||
|
||||
jetfix::FIXFragment::Bookmark<jetfix::fix::Text>
|
||||
update_corid(jetfix::FIXFragment::Bookmark<jetfix::fix::Text> const &bm,
|
||||
jetfix::FIXFragment &encoding, trace::CorID const &cid) {
|
||||
std::array<char, corid_sz()+1> buffer;
|
||||
encode_corid(cid.channel, cid.sn, buffer);
|
||||
return encoding.overwrite(bm, &buffer[0], corid_sz());
|
||||
}
|
||||
|
||||
NativeOrder::NativeOrder() : me(new PImpl()) {}
|
||||
|
||||
OrderDefinition const &NativeOrder::definition() const {
|
||||
@@ -163,7 +141,7 @@ void NativeOrder::on_init_new(OrderDefinition const &def,
|
||||
me->routing_record = rq.routing_record;
|
||||
*native_state.mutable_routing_record() = rq.routing_record;
|
||||
|
||||
init_fix();
|
||||
init_encodings();
|
||||
}
|
||||
|
||||
void NativeOrder::on_init_recovered(OrderRecord const &rec,
|
||||
@@ -199,22 +177,25 @@ void NativeOrder::on_init_recovered(OrderRecord const &rec,
|
||||
}
|
||||
|
||||
auto rq = serv.order_router.get_routing_record(
|
||||
UserID(def.user_id()), AccountID(def.account_id()), *me->sec);
|
||||
UserID(def.user_id()), AccountID(def.account_id()), *me->sec);
|
||||
if (!rq.has_route) {
|
||||
auto msg = fmt::format("Could not route order: {}", rq.error_msg);
|
||||
LOG(OrderMan, Error, "Unable to route order {} recovered from disk. Message: {}",
|
||||
LOG(OrderMan, Error,
|
||||
"Unable to route order {} recovered from disk. Message: {}",
|
||||
rec.key(), msg);
|
||||
transition_to_error(NativeOrderState::SUB_ERROR_UNKNOWN_FIX_SESSION,
|
||||
"Could not route order");
|
||||
return;
|
||||
}
|
||||
// if we made it this far we are good.
|
||||
me->routing_record = rq.routing_record;
|
||||
me->routing_record = rq.routing_record;
|
||||
*native_state.mutable_routing_record() = rq.routing_record;
|
||||
|
||||
if (me->state.status() != ORDER_STATUS_PENDING_WORKING)
|
||||
|
||||
init_encodings();
|
||||
if (me->state.status() != ORDER_STATUS_PENDING_WORKING) {
|
||||
me->exchange_order_id = native_state.exchange_order_id();
|
||||
init_fix();
|
||||
me->encoder->update_exchange_order_id(me->exchange_order_id);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,12 +299,12 @@ NativeOrder::on_init_from_exe_report(ExecutionReport const &er,
|
||||
}
|
||||
|
||||
auto &native_state = get_native_state(state);
|
||||
native_state.set_exchange_order_id(to_trim_str(
|
||||
std::get<ExchangeOrderID>(er.exchange_order_id)));
|
||||
native_state.set_exchange_order_id(
|
||||
to_trim_str(std::get<ExchangeOrderID>(er.exchange_order_id)));
|
||||
native_state.set_last_msg_seq_num(er.msg_seq_num);
|
||||
native_state.set_native_type(er.order_type);
|
||||
native_state.set_stop_px(er.stop_price.value());
|
||||
|
||||
|
||||
auto &rr = *native_state.mutable_routing_record();
|
||||
rr.set_session(er.cfg->name());
|
||||
rr.set_account(to_trim_str(er.account_name));
|
||||
@@ -366,7 +347,7 @@ void NativeOrder::warm_up_activate(OrderServicesData &data,
|
||||
OrderOpResult
|
||||
NativeOrder::_on_activate(log::Level reject_level, log::Level transition_level,
|
||||
Price p, Quantity q,
|
||||
bts::orderman::OrderServices &services) {
|
||||
bts::orderman::OrderServices &order_services) {
|
||||
me->state.set_price(p.value());
|
||||
me->state.set_quantity(q.value());
|
||||
me->state.set_filled_quantity(0);
|
||||
@@ -445,34 +426,8 @@ NativeOrder::_on_activate(log::Level reject_level, log::Level transition_level,
|
||||
*me->session_services,
|
||||
[this](auto const &gw) { this->on_gateway_status(gw); });
|
||||
|
||||
// send out order
|
||||
auto &encoding = me->create_encoding;
|
||||
|
||||
switch (me->definition.custom_def().custom_case()) {
|
||||
case CustomOrderDefinition::kLimit:
|
||||
case CustomOrderDefinition::kStopLimit:
|
||||
case CustomOrderDefinition::kGlbxIceberg:
|
||||
me->create_price_bm = encoding.overwrite(
|
||||
me->create_price_bm,
|
||||
securities::encode_exchange_price(*me->sec, p).value(),
|
||||
me->price_encoding_precision, price_sz());
|
||||
break;
|
||||
case CustomOrderDefinition::kStop:
|
||||
case CustomOrderDefinition::kMarket:
|
||||
break;
|
||||
default:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
|
||||
me->create_quantity_bm =
|
||||
encoding.overwrite(me->create_quantity_bm, q.value(), quantity_sz());
|
||||
auto const &ts = services.get_time_str();
|
||||
me->create_transact_time_bm = encoding.overwrite(
|
||||
me->create_transact_time_bm, &ts.value()[0], ts.value().size());
|
||||
|
||||
me->create_corid_bm =
|
||||
update_corid(me->create_corid_bm,encoding, services.corid());
|
||||
me->encoder->update_create_order_encoding(p, me->price_encoding_precision, q,
|
||||
order_services);
|
||||
|
||||
return OrderOpResult{};
|
||||
}
|
||||
@@ -485,16 +440,14 @@ OrderOpResult NativeOrder::on_activate(Price p, Quantity q,
|
||||
switch (me->state.status()) {
|
||||
|
||||
case ORDER_STATUS_INACTIVE: {
|
||||
// this is a brand new order
|
||||
|
||||
auto scoped_log =
|
||||
services.log_scope("NativeOrder::on_activate", key().value());
|
||||
// this is a brand new order
|
||||
|
||||
result = _on_activate(Warn, Info, p, q, services);
|
||||
if (result.ok()) {
|
||||
me->services->queue_fix(*me->session_services,
|
||||
jetfix::MessageTypes::NewOrderSingle,
|
||||
me->create_encoding);
|
||||
|
||||
me->encoder->send_create(*me->services, *me->session_services);
|
||||
me->services->governor(*me->session_services).record_sent();
|
||||
me->state.set_status(ORDER_STATUS_PENDING_WORKING);
|
||||
|
||||
@@ -636,8 +589,6 @@ OrderOpResult NativeOrder::on_update(api::orderman::Update const &update) {
|
||||
break;
|
||||
}
|
||||
|
||||
auto &encoding = me->update_encoding;
|
||||
|
||||
if (update.has_custom()) {
|
||||
bts_assert(update.custom().custom_case() ==
|
||||
me->definition.custom_def().custom_case());
|
||||
@@ -651,10 +602,8 @@ OrderOpResult NativeOrder::on_update(api::orderman::Update const &update) {
|
||||
->mutable_stop()
|
||||
->set_stop_price(stop_px.value());
|
||||
me->services->report_definition(me->definition);
|
||||
me->update_stop_px_bm = encoding.overwrite(
|
||||
me->update_stop_px_bm,
|
||||
securities::encode_exchange_price(*me->sec, stop_px).value(),
|
||||
me->price_encoding_precision, price_sz());
|
||||
me->encoder->update_cancel_replace_stop_px(
|
||||
stop_px, me->price_encoding_precision);
|
||||
}
|
||||
} else if (update.custom().custom_case() ==
|
||||
CustomOrderDefinition::CustomOrderDefinition::kStopLimit) {
|
||||
@@ -665,10 +614,9 @@ OrderOpResult NativeOrder::on_update(api::orderman::Update const &update) {
|
||||
->mutable_stop_limit()
|
||||
->set_stop_price(stop_px.value());
|
||||
me->services->report_definition(me->definition);
|
||||
me->update_stop_px_bm = encoding.overwrite(
|
||||
me->update_stop_px_bm,
|
||||
securities::encode_exchange_price(*me->sec, stop_px).value(),
|
||||
me->price_encoding_precision, price_sz());
|
||||
|
||||
me->encoder->update_cancel_replace_stop_px(
|
||||
stop_px, me->price_encoding_precision);
|
||||
}
|
||||
} else if (update.custom().custom_case() ==
|
||||
CustomOrderDefinition::kGlbxIceberg) {
|
||||
@@ -683,32 +631,20 @@ OrderOpResult NativeOrder::on_update(api::orderman::Update const &update) {
|
||||
ignore_or_cancel(msg, ORDER_ERROR_INVALID_PARAMETER, &result);
|
||||
break;
|
||||
}
|
||||
me->update_max_show_bm = encoding.overwrite(
|
||||
me->update_max_show_bm, ib.max_show_quantity(), quantity_sz());
|
||||
me->encoder->update_cancel_replace_max_show(
|
||||
Quantity(ib.max_show_quantity()));
|
||||
}
|
||||
}
|
||||
|
||||
// All good
|
||||
if (is_stop_limit_order() || !is_stop_order() || stop_order_has_been_triggered()) {
|
||||
if (is_stop_limit_order() || !is_stop_order() ||
|
||||
stop_order_has_been_triggered()) {
|
||||
// Stop orders become limit orders when triggered
|
||||
me->update_price_bm = encoding.overwrite(
|
||||
me->update_price_bm,
|
||||
securities::encode_exchange_price(*me->sec, p).value(),
|
||||
me->price_encoding_precision, price_sz());
|
||||
me->encoder->update_cancel_replace_encoding(
|
||||
p, me->price_encoding_precision, *me->services);
|
||||
}
|
||||
me->update_quantity_bm =
|
||||
encoding.overwrite(me->update_quantity_bm, q.value(), quantity_sz());
|
||||
|
||||
auto const &ts = me->services->get_time_str();
|
||||
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, me->services->corid());
|
||||
|
||||
me->services->queue_fix(*me->session_services,
|
||||
jetfix::MessageTypes::CancelReplace,
|
||||
me->update_encoding);
|
||||
me->encoder->update_cancel_replace_encoding(q, *me->services);
|
||||
me->encoder->send_cancel_replace(*me->services, *me->session_services);
|
||||
|
||||
me->services->governor(*me->session_services).record_sent();
|
||||
update_working_position();
|
||||
@@ -769,7 +705,9 @@ void NativeOrder::on_attached(
|
||||
|
||||
auto &native_state = get_native_state(me->state);
|
||||
*native_state.mutable_routing_record() = rq.routing_record;
|
||||
init_fix();
|
||||
init_encodings();
|
||||
if (has_exchange_order_id())
|
||||
me->encoder->update_exchange_order_id(me->exchange_order_id);
|
||||
|
||||
// Update user, account and manual order indicator based on new parent
|
||||
me->definition.set_manual_order_indicator(
|
||||
@@ -805,15 +743,8 @@ OrderOpResult NativeOrder::on_cancel() {
|
||||
switch (me->state.status()) {
|
||||
|
||||
case ORDER_STATUS_WORKING: {
|
||||
auto &encoding = me->cancel_encoding;
|
||||
auto const &ts = me->services->get_time_str();
|
||||
me->cancel_transact_time_bm = encoding.overwrite(
|
||||
me->cancel_transact_time_bm, &ts.value()[0], ts.value().size());
|
||||
|
||||
me->services->queue_fix(*me->session_services,
|
||||
jetfix::MessageTypes::Cancel,
|
||||
me->cancel_encoding);
|
||||
|
||||
me->encoder->update_cancel_encoding(*me->services);
|
||||
me->encoder->send_cancel(*me->services, *me->session_services);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -862,16 +793,14 @@ bool NativeOrder::is_old_exe_report(
|
||||
sizeof(mercury::TimeStampStr))
|
||||
return false;
|
||||
|
||||
auto& ts = std::get<mercury::TimeStampStr>(er.data->transact_time);
|
||||
auto &ts = std::get<mercury::TimeStampStr>(er.data->transact_time);
|
||||
if (std::lexicographical_compare(native_state.last_transact_time().begin(),
|
||||
native_state.last_transact_time().end(),
|
||||
ts.value().begin(),
|
||||
ts.value().end()))
|
||||
ts.value().begin(), ts.value().end()))
|
||||
return false;
|
||||
|
||||
if (std::equal(native_state.last_transact_time().begin(),
|
||||
native_state.last_transact_time().end(),
|
||||
ts.value().begin(),
|
||||
native_state.last_transact_time().end(), ts.value().begin(),
|
||||
ts.value().end()))
|
||||
return native_state.last_msg_seq_num() >= er.data->msg_seq_num;
|
||||
|
||||
@@ -903,8 +832,8 @@ void NativeOrder::on_exe_report(const NewExecutionReportEvent &er) {
|
||||
}
|
||||
|
||||
native_state.set_last_msg_seq_num(er.data->msg_seq_num);
|
||||
native_state.set_last_transact_time(to_str(
|
||||
std::get<mercury::TimeStampStr>(er.data->transact_time)));
|
||||
native_state.set_last_transact_time(
|
||||
to_str(std::get<mercury::TimeStampStr>(er.data->transact_time)));
|
||||
|
||||
auto external_status = map_external_status(er.data->order_status);
|
||||
|
||||
@@ -934,21 +863,23 @@ void NativeOrder::on_exe_report(const NewExecutionReportEvent &er) {
|
||||
native_state.set_native_status(er.data->order_status);
|
||||
native_state.set_native_type(er.data->order_type);
|
||||
native_state.set_stop_px(er.data->stop_price.value());
|
||||
bool got_first_exchange_order_id = !has_exchange_order_id();
|
||||
|
||||
if (got_first_exchange_order_id) {
|
||||
me->exchange_order_id = to_trim_str(
|
||||
std::get<ExchangeOrderID>(er.data->exchange_order_id));
|
||||
native_state.set_exchange_order_id(me->exchange_order_id);
|
||||
add_exchange_order_id_to_fix();
|
||||
}
|
||||
|
||||
// The FIX message we send for updates has to change once a stop
|
||||
// order is triggered. Post triggering we no longer can update the
|
||||
// stop px. Instead the stop order turns into a regular limit
|
||||
// order, which means we can now update the actual price.
|
||||
if (is_stop_order() && stop_order_has_been_triggered() && fix_has_stop_px())
|
||||
init_fix();
|
||||
if (is_stop_order() && stop_order_has_been_triggered() && me->stop_order_still_has_stop_px) {
|
||||
me->stop_order_still_has_stop_px = false;
|
||||
init_encodings();
|
||||
}
|
||||
|
||||
bool got_first_exchange_order_id = !has_exchange_order_id();
|
||||
if (got_first_exchange_order_id) {
|
||||
me->exchange_order_id =
|
||||
to_trim_str(std::get<ExchangeOrderID>(er.data->exchange_order_id));
|
||||
native_state.set_exchange_order_id(me->exchange_order_id);
|
||||
me->encoder->update_exchange_order_id(me->exchange_order_id);
|
||||
}
|
||||
|
||||
if (!terminal_state(me->state.status())) {
|
||||
state.set_price(er.data->price.value());
|
||||
@@ -1130,248 +1061,33 @@ void NativeOrder::report_state() {
|
||||
me->services->report_state(me->state);
|
||||
}
|
||||
|
||||
std::string NativeOrder::get_cust_order_handling_inst(api::orderman::RoutingRecord const&rr) {
|
||||
std::string NativeOrder::get_cust_order_handling_inst(
|
||||
api::orderman::RoutingRecord const &rr) {
|
||||
if (rr.cust_order_handling_inst().size())
|
||||
return rr.cust_order_handling_inst();
|
||||
else
|
||||
return config::get<config::OrdermanCfg>().fallback_cust_order_handling_inst();
|
||||
return config::get<config::OrdermanCfg>()
|
||||
.fallback_cust_order_handling_inst();
|
||||
}
|
||||
|
||||
void NativeOrder::init_fix() {
|
||||
bts_assert(me->sec);
|
||||
|
||||
using namespace jetfix;
|
||||
me->create_encoding = FIXFragment{};
|
||||
me->update_encoding = FIXFragment{};
|
||||
me->cancel_encoding = FIXFragment{};
|
||||
|
||||
auto const &def = me->definition;
|
||||
auto const &sec = *me->sec;
|
||||
auto const &rr = me->routing_record;
|
||||
|
||||
std::string clordid(clordid_sz(), ' ');
|
||||
encode_clorid(key(), SecurityKey(sec.id()), &clordid);
|
||||
|
||||
// initialize create FIX
|
||||
auto &create_encoding = me->create_encoding;
|
||||
create_encoding.add<fix::SenderSubID>(rr.operator_id());
|
||||
create_encoding.add<fix::SenderLocationID>(rr.location());
|
||||
create_encoding.add<fix::Account>(rr.account());
|
||||
create_encoding.add<fix::Side>(def.side());
|
||||
create_encoding.add<fix::TimeInForce>(def.time_in_force());
|
||||
create_encoding.add<fix::ManualOrderIndicator>(def.manual_order_indicator());
|
||||
create_encoding.add<fix::CustomerOrFirm>(rr.customer_or_firm());
|
||||
create_encoding.add<fix::CtiCode>(rr.cti_code());
|
||||
create_encoding.add<fix::SecurityDesc>(sec.glbx().security_desc());
|
||||
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)
|
||||
create_encoding.add<fix::SelfMatchPreventionInstruction>(
|
||||
rr.smp_instruction());
|
||||
}
|
||||
|
||||
me->create_transact_time_bm = create_encoding.add<fix::TransactTimeStr>(
|
||||
datetime::FIX_timestamp(datetime::now()));
|
||||
me->create_quantity_bm =
|
||||
create_encoding.add<fix::OrderQty>(0, quantity_sz());
|
||||
me->create_corid_bm =
|
||||
create_encoding.add<fix::Text>(std::string(corid_sz(), ' '));
|
||||
|
||||
// initialize update FIX
|
||||
auto &update_encoding = me->update_encoding;
|
||||
update_encoding.add<fix::SenderSubID>(rr.operator_id());
|
||||
update_encoding.add<fix::SenderLocationID>(rr.location());
|
||||
update_encoding.add<fix::Account>(rr.account());
|
||||
update_encoding.add<fix::Side>(def.side());
|
||||
update_encoding.add<fix::TimeInForce>(def.time_in_force());
|
||||
update_encoding.add<fix::ManualOrderIndicator>(def.manual_order_indicator());
|
||||
update_encoding.add<fix::CtiCode>(rr.cti_code());
|
||||
update_encoding.add<fix::CustomerOrFirm>(rr.customer_or_firm());
|
||||
update_encoding.add<fix::SecurityDesc>(sec.glbx().security_desc());
|
||||
update_encoding.add<fix::ClOrdID>(clordid);
|
||||
update_encoding.add<fix::OrigClOrdID>(clordid);
|
||||
update_encoding.add<fix::CorrelationClOrdID>(clordid);
|
||||
update_encoding.add<fix::InFlightMitigation>(true);
|
||||
update_encoding.add<fix::CustOrderHandlingInst> (get_cust_order_handling_inst(rr));
|
||||
// Self Match Protection
|
||||
if (rr.smp_id().size()) {
|
||||
update_encoding.add<fix::SelfMatchPreventionID>(rr.smp_id());
|
||||
if (rr.smp_instruction() != SELF_MATCH_PREVENTION_INSTRUCTION_UNDEFINED)
|
||||
update_encoding.add<fix::SelfMatchPreventionInstruction>(
|
||||
rr.smp_instruction());
|
||||
}
|
||||
me->update_transact_time_bm = update_encoding.add<fix::TransactTimeStr>(
|
||||
datetime::FIX_timestamp(datetime::now()));
|
||||
me->update_quantity_bm =
|
||||
update_encoding.add<fix::OrderQty>(0, quantity_sz());
|
||||
me->update_corid_bm =
|
||||
update_encoding.add<fix::Text>(std::string(corid_sz(), ' '));
|
||||
|
||||
// initialize cancel FIX
|
||||
auto &cancel_encoding = me->cancel_encoding;
|
||||
cancel_encoding.add<fix::SenderSubID>(rr.operator_id());
|
||||
cancel_encoding.add<fix::SenderLocationID>(rr.location());
|
||||
cancel_encoding.add<fix::Account>(rr.account());
|
||||
cancel_encoding.add<fix::Side>(def.side());
|
||||
cancel_encoding.add<fix::TimeInForce>(def.time_in_force());
|
||||
cancel_encoding.add<fix::ManualOrderIndicator>(def.manual_order_indicator());
|
||||
cancel_encoding.add<fix::SecurityDesc>(sec.glbx().security_desc());
|
||||
cancel_encoding.add<fix::ClOrdID>(clordid);
|
||||
cancel_encoding.add<fix::OrigClOrdID>(clordid);
|
||||
cancel_encoding.add<fix::CorrelationClOrdID>(clordid);
|
||||
me->cancel_transact_time_bm = cancel_encoding.add<fix::TransactTimeStr>(
|
||||
datetime::FIX_timestamp(datetime::now()));
|
||||
|
||||
// special tags
|
||||
switch (def.custom_def().custom_case()) {
|
||||
case CustomOrderDefinition::kMarket:
|
||||
// type
|
||||
create_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_MARKET);
|
||||
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_MARKET);
|
||||
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_MARKET);
|
||||
break;
|
||||
|
||||
case CustomOrderDefinition::kLimit:
|
||||
// type
|
||||
create_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
|
||||
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
|
||||
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
|
||||
|
||||
// price
|
||||
me->create_price_bm = create_encoding.add<fix::Price>(
|
||||
0, me->price_encoding_precision, price_sz());
|
||||
me->update_price_bm = update_encoding.add<fix::Price>(
|
||||
0, me->price_encoding_precision, price_sz());
|
||||
break;
|
||||
|
||||
case CustomOrderDefinition::kStop: {
|
||||
// type
|
||||
create_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->sec, Price(stop_px)).value();
|
||||
create_encoding.add<fix::StopPx>(encoded_stop_px,
|
||||
me->price_encoding_precision, -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, me->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, me->price_encoding_precision, price_sz());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case CustomOrderDefinition::kStopLimit: {
|
||||
// type
|
||||
create_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->sec, Price(stop_px)).value();
|
||||
create_encoding.add<fix::StopPx>(encoded_stop_px,
|
||||
me->price_encoding_precision, -1);
|
||||
|
||||
// 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, me->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, me->price_encoding_precision, price_sz());
|
||||
me->update_price_bm = update_encoding.add<fix::Price>(
|
||||
0, me->price_encoding_precision, price_sz());
|
||||
me->update_stop_px_bm = update_encoding.add<fix::StopPx>(
|
||||
0, me->price_encoding_precision, price_sz());
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case CustomOrderDefinition::kGlbxIceberg: {
|
||||
|
||||
// type, still a limit order but we use a show quantity
|
||||
create_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
|
||||
update_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
|
||||
cancel_encoding.add<fix::OrdType>(NATIVE_ORDER_TYPE_LIMIT);
|
||||
|
||||
// price
|
||||
me->create_price_bm = create_encoding.add<fix::Price>(
|
||||
0, me->price_encoding_precision, price_sz());
|
||||
me->update_price_bm = update_encoding.add<fix::Price>(
|
||||
0, me->price_encoding_precision, price_sz());
|
||||
|
||||
// max show qty
|
||||
auto max_show_qty = def.custom_def().glbx_iceberg().max_show_quantity();
|
||||
create_encoding.add<fix::MaxShow>(max_show_qty);
|
||||
me->update_max_show_bm =
|
||||
update_encoding.add<fix::MaxShow>(max_show_qty, max_show_sz());
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
bts_assert(false);
|
||||
break;
|
||||
}
|
||||
if (has_exchange_order_id())
|
||||
add_exchange_order_id_to_fix();
|
||||
}
|
||||
|
||||
bool NativeOrder::is_stop_order() {
|
||||
bool NativeOrder::is_stop_order() {
|
||||
auto const &def = me->definition;
|
||||
return (def.custom_def().custom_case() == CustomOrderDefinition::kStop ||
|
||||
def.custom_def().custom_case() == CustomOrderDefinition::kStopLimit);
|
||||
}
|
||||
|
||||
bool NativeOrder::is_stop_limit_order() {
|
||||
bool NativeOrder::is_stop_limit_order() {
|
||||
auto const &def = me->definition;
|
||||
return def.custom_def().custom_case() == CustomOrderDefinition::kStopLimit;
|
||||
}
|
||||
|
||||
bool NativeOrder::stop_order_has_been_triggered() {
|
||||
bool NativeOrder::stop_order_has_been_triggered() {
|
||||
bts_assert(is_stop_order());
|
||||
auto const &native_state = get_native_state(me->state);
|
||||
return has_exchange_order_id() &&
|
||||
native_state.native_type() == NATIVE_ORDER_TYPE_LIMIT;
|
||||
}
|
||||
|
||||
bool NativeOrder::fix_has_stop_px() {
|
||||
bts_assert(is_stop_order());
|
||||
return me->update_stop_px_bm.valid();
|
||||
}
|
||||
|
||||
void NativeOrder::add_exchange_order_id_to_fix() {
|
||||
bts_assert(has_exchange_order_id());
|
||||
me->update_encoding.add<jetfix::fix::OrderID>(me->exchange_order_id);
|
||||
me->cancel_encoding.add<jetfix::fix::OrderID>(me->exchange_order_id);
|
||||
}
|
||||
|
||||
OrderStatus map_external_status(NativeOrderStatus status) {
|
||||
switch (status) {
|
||||
case NATIVE_ORDER_STATUS_NEW:
|
||||
@@ -1537,5 +1253,16 @@ void NativeOrder::ignore_or_cancel(std::string const &msg,
|
||||
*out = {error, msg};
|
||||
}
|
||||
|
||||
void NativeOrder::init_encodings() {
|
||||
auto rr = get_native_state(me->state).routing_record();
|
||||
if (use_ilink3(rr.session()))
|
||||
me->encoder = std::make_unique<iLink3OrderEncoder>();
|
||||
else
|
||||
me->encoder = std::make_unique<iLink2OrderEncoder>();
|
||||
me->encoder->init(key(), rr, *me->sec, definition(),
|
||||
me->price_encoding_precision,
|
||||
stop_order_has_been_triggered());
|
||||
}
|
||||
|
||||
} // namespace orderman
|
||||
} // namespace bts
|
||||
@@ -40,6 +40,8 @@ class NativeOrder : public NativeOrderBase {
|
||||
private:
|
||||
struct PImpl;
|
||||
std::unique_ptr<PImpl> me;
|
||||
void init_encodings();
|
||||
|
||||
void on_exe_report(const NewExecutionReportEvent &);
|
||||
void on_cancel_reject(const CancelRejectEvent &);
|
||||
void on_gateway_status(const GatewayStatusChangeEvent &);
|
||||
@@ -75,7 +77,6 @@ class NativeOrder : public NativeOrderBase {
|
||||
bool stop_order_has_been_triggered() ;
|
||||
bool is_stop_order() ;
|
||||
bool is_stop_limit_order() ;
|
||||
bool fix_has_stop_px() ;
|
||||
};
|
||||
|
||||
typedef NativeOrder GLBXNativeOrder;
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace orderman {
|
||||
class OrderServices;
|
||||
class SessionServices;
|
||||
|
||||
// Abstraction of actualy byte encoding of order messages so that we
|
||||
// can support iLink2 and iLink3 using the same base order logic.
|
||||
// Abstraction of the byte encoding of order messages, necessary to
|
||||
// support iLink2 and iLink3 using the same base order logic.
|
||||
// GLBXNativeOrder will consume this interface.
|
||||
|
||||
class IGLBXOrderEncoder {
|
||||
@@ -23,7 +23,9 @@ class IGLBXOrderEncoder {
|
||||
virtual ~IGLBXOrderEncoder() {}
|
||||
virtual void init(OrderKey key, api::orderman::RoutingRecord const &,
|
||||
api::Security const &security,
|
||||
api::orderman::OrderDefinition const &def) = 0;
|
||||
api::orderman::OrderDefinition const &def,
|
||||
int price_encoding_precision,
|
||||
bool stop_order_has_been_triggered) = 0;
|
||||
|
||||
virtual void update_exchange_order_id(std::string const &) = 0;
|
||||
|
||||
@@ -35,6 +37,10 @@ class IGLBXOrderEncoder {
|
||||
virtual void update_cancel_replace_max_show(Quantity max_show) = 0;
|
||||
virtual void update_cancel_replace_encoding(Price p, int price_precision,
|
||||
Quantity q, OrderServices &) = 0;
|
||||
virtual void update_cancel_replace_encoding(Quantity q, OrderServices &) = 0;
|
||||
virtual void update_cancel_replace_encoding(Price p,
|
||||
int price_precision,
|
||||
OrderServices &) = 0;
|
||||
virtual void update_cancel_encoding(OrderServices&) = 0;
|
||||
virtual void send_create(OrderServices&,SessionServices&) = 0;
|
||||
virtual void send_cancel_replace(OrderServices&,SessionServices&) = 0;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -11,7 +11,9 @@ class iLink2OrderEncoder : public IGLBXOrderEncoder {
|
||||
|
||||
virtual void init(OrderKey key, api::orderman::RoutingRecord const &,
|
||||
api::Security const &security,
|
||||
api::orderman::OrderDefinition const &def) override;
|
||||
api::orderman::OrderDefinition const &def,
|
||||
int price_encoding_precision,
|
||||
bool stop_order_has_been_triggered) override;
|
||||
void update_exchange_order_id(std::string const &) override;
|
||||
void update_create_order_encoding(Price p, int price_precision, Quantity q,
|
||||
OrderServices &services) override;
|
||||
@@ -20,6 +22,9 @@ class iLink2OrderEncoder : public IGLBXOrderEncoder {
|
||||
void update_cancel_replace_max_show(Quantity max_show) override;
|
||||
void update_cancel_replace_encoding(Price, int price_precision, Quantity,
|
||||
OrderServices &) override;
|
||||
void update_cancel_replace_encoding(Quantity q, OrderServices &) override;
|
||||
void update_cancel_replace_encoding(Price p, int price_precision,
|
||||
OrderServices &) override;
|
||||
void update_cancel_encoding(OrderServices &) override;
|
||||
void send_create(OrderServices &, SessionServices &) override;
|
||||
void send_cancel_replace(OrderServices &, SessionServices &) override;
|
||||
|
||||
@@ -39,7 +39,9 @@ iLink3OrderEncoder::~iLink3OrderEncoder() {}
|
||||
void iLink3OrderEncoder::init(OrderKey key,
|
||||
api::orderman::RoutingRecord const &rec,
|
||||
api::Security const &security,
|
||||
api::orderman::OrderDefinition const &def) {
|
||||
api::orderman::OrderDefinition const &def,
|
||||
int ,
|
||||
bool) {
|
||||
using namespace jetfix;
|
||||
|
||||
me->security = &security;
|
||||
@@ -149,6 +151,16 @@ void iLink3OrderEncoder::update_cancel_replace_encoding(Price p, int,
|
||||
me->cancel_replace.create_fields.quantity = q;
|
||||
}
|
||||
|
||||
void iLink3OrderEncoder::update_cancel_replace_encoding(Quantity q, OrderServices &) {
|
||||
me->cancel_replace.create_fields.quantity = q;
|
||||
}
|
||||
|
||||
void iLink3OrderEncoder::update_cancel_replace_encoding(Price p, int,
|
||||
OrderServices &) {
|
||||
me->cancel_replace.create_fields.price =
|
||||
securities::encode_exchange_price(*me->security, p);
|
||||
}
|
||||
|
||||
void iLink3OrderEncoder::update_cancel_encoding(OrderServices&) {}
|
||||
|
||||
void iLink3OrderEncoder::send_create(OrderServices&s,SessionServices&os) {
|
||||
|
||||
@@ -10,7 +10,9 @@ class iLink3OrderEncoder : public IGLBXOrderEncoder {
|
||||
~iLink3OrderEncoder() override;
|
||||
virtual void init(OrderKey key, api::orderman::RoutingRecord const &,
|
||||
api::Security const &security,
|
||||
api::orderman::OrderDefinition const &def) override;
|
||||
api::orderman::OrderDefinition const &def,
|
||||
int price_encoding_precision,
|
||||
bool stop_order_has_been_triggered) override;
|
||||
void update_exchange_order_id(std::string const &) override;
|
||||
void update_create_order_encoding(Price p, int price_precision, Quantity q,
|
||||
OrderServices &services) override;
|
||||
@@ -19,6 +21,8 @@ class iLink3OrderEncoder : public IGLBXOrderEncoder {
|
||||
void update_cancel_replace_max_show(Quantity max_show) override;
|
||||
void update_cancel_replace_encoding(Price, int price_precision, Quantity,
|
||||
OrderServices &) override;
|
||||
void update_cancel_replace_encoding(Quantity, OrderServices &) override;
|
||||
void update_cancel_replace_encoding(Price, int, OrderServices &) override;
|
||||
void update_cancel_encoding(OrderServices &) override;
|
||||
void send_create(OrderServices &, SessionServices &) override;
|
||||
void send_cancel_replace(OrderServices &, SessionServices &) override;
|
||||
|
||||
@@ -1 +1 @@
|
||||
set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/BasePositionService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarginService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/MarketDataService.proto;../lib/api/services/MoneyFileService.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/node_modules/exit/test/fixtures/create-files.sh;api/node_modules/object.assign/test.sh;api/node_modules/protobufjs/cli/node_modules/acorn-jsx/node_modules/acorn/bin/update_authors.sh;api/node_modules/watch/release.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/Util/StreamUtils.fs)
|
||||
set(sources ../../externals/linux/include/google/protobuf/descriptor.proto;../../externals/linux/include/google/protobuf/timestamp.proto;../lib/api/apicore.proto;../lib/api/apigateway.proto;../lib/api/apioptions.proto;../lib/api/services/AdminService.proto;../lib/api/services/AlgoDefinitionService.proto;../lib/api/services/AlgoService.proto;../lib/api/services/ApiUnitTestService.proto;../lib/api/services/AuthService.proto;../lib/api/services/BasePositionService.proto;../lib/api/services/ErrorReportService.proto;../lib/api/services/HelloService.proto;../lib/api/services/MBOService.proto;../lib/api/services/MarginService.proto;../lib/api/services/MarketDataAuxiliaryService.proto;../lib/api/services/MarketDataRelay.proto;../lib/api/services/MarketDataService.proto;../lib/api/services/MoneyFileService.proto;../lib/api/services/OrderService.proto;../lib/api/services/OutOfProcessURLListener.proto;../lib/api/services/PersistenceService.proto;../lib/api/services/PositionService.proto;../lib/api/services/ShellDiagnosticService.proto;../lib/api/services/ShellLatencyService.proto;../lib/api/services/SyntheticSecurityService.proto;../lib/domain_model/Security.proto;../lib/md/protos/co2.proto;../lib/sparkproto/SparkProtos.proto;api/build.sh;api/quiet_build.sh;api/src/DynamicService.ts;api/src/ServiceContext.ts;api/src/bts_assert.ts;ui/src/Access.fs;ui/src/Accounts/ClipLimits.fs;ui/src/Accounts/ProductLimits.fs;ui/src/Accounts/SecurityLimits.fs;ui/src/Accounts/State.fs;ui/src/Accounts/Types.fs;ui/src/Accounts/View.fs;ui/src/App.fs;ui/src/Cmd.fs;ui/src/Controls/Button.fs;ui/src/Controls/DataGrid.fs;ui/src/Controls/Fields.fs;ui/src/Controls/Modal.fs;ui/src/Controls/ReactGrid.fs;ui/src/Controls/Table.fs;ui/src/Controls/nbsp.fs;ui/src/Global.fs;ui/src/Imports.fs;ui/src/Lens.fs;ui/src/Login/Login.fs;ui/src/Nav.fs;ui/src/State.fs;ui/src/Types.fs;ui/src/Users/State.fs;ui/src/Users/Types.fs;ui/src/Users/View.fs;ui/src/Util/EnumUtils.fs;ui/src/Util/JSMap.fs;ui/src/Util/StreamUtils.fs;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs)
|
||||
Reference in new issue
Block a user