More gateway work.
This commit is contained in:
1 parent
26702a1a7e
commit
70e58edacb
34 files changed
+1052
-213
No files matched your search
@@ -36,6 +36,7 @@ namespace bts {
|
||||
Plugin,
|
||||
ClientSdk,
|
||||
Http,
|
||||
OrderMan2,
|
||||
// Please keep this list in sync with logging.h/logging.cpp
|
||||
}
|
||||
|
||||
@@ -105,6 +106,7 @@ namespace bts {
|
||||
internal static Logger DataFlow => new Logger(Subsystem.DataFlow);
|
||||
public static Logger ClientSdk => new Logger(Subsystem.ClientSdk);
|
||||
public static Logger Http => new Logger(Subsystem.Http);
|
||||
public static Logger OrderMan2 => new Logger(Subsystem.OrderMan2);
|
||||
|
||||
internal static void log_at(this Logger logger, Level level, string message) {
|
||||
switch (level) {
|
||||
|
||||
@@ -1 +1 @@
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/FillStore.cpp;orderman/actors/GLBXExecutionGateway.cpLine truncated
|
||||
set(sources api/apicore.proto;api/apigateway.proto;api/apioptions.proto;api/core/ApiClientInterop.cpp;api/core/ApiServerInterop.cpp;api/public/ApiServer.cpp;api/public/ClientChannel.cpp;api/public/QuickbusClientChannel.cpp;api/public/ServerChannel.cpp;api/public/ServiceContext.cpp;api/service_helpers/AdminServiceUtils.cpp;api/service_helpers/AlgoServiceUtils.cpp;api/service_helpers/PositionUtilities.cpp;api/services/AdminService.proto;api/services/AlgoDefinitionService.proto;api/services/AlgoService.proto;api/services/ApiUnitTestService.proto;api/services/AuthService.proto;api/services/BasePositionService.proto;api/services/ErrorReportService.proto;api/services/HelloService.proto;api/services/MBOService.proto;api/services/MarginService.proto;api/services/MarketDataAuxiliaryService.proto;api/services/MarketDataRelay.proto;api/services/MoneyFileService.proto;api/services/OrderService.proto;api/services/OutOfProcessURLListener.proto;api/services/PersistenceService.proto;api/services/PositionService.proto;api/services/ShellDiagnosticService.proto;api/services/ShellLatencyService.proto;api/services/SyntheticSecurityService.proto;api/test/ApiTests.cpp;api/test/HelloServiceServer.cpp;config/ConfigCheck.cpp;config/ConfigDownloader.cpp;config/ConfigErrorCollector.cpp;config/ConfigLog.cpp;config/ConfigPropertyEvaluator.cpp;config/ConfigValueQueue.cpp;config/ConfigurationException.cpp;config/ConfigurationState.cpp;config/PreprocessInputStream.cpp;config/config.cpp;config/defaults/MarketData.conf;config/defaults/Ports.conf;config/defaults/Symbols.conf;config/defaults/cme_reference_data.conf;config/defaults/edge.conf;config/defaults/jetfix.conf;config/defaults/keycode.conf;config/defaults/logging.conf;config/defaults/orderman_cfg.conf;config/defaults/orders_fills_cleanup.conf;config/defaults/position_cfg.conf;config/defaults/span.conf;config/defaults/spreader.conf;config/defaults/testkeys.conf;config/defaults/threads.conf;config/defaults/toggles.conf;config/extensions/extensions.proto;config/invalid/invalid.proto;config/protos/ExchangeSimCfg.proto;config/protos/MarketData.proto;config/protos/Ports.proto;config/protos/Symbols.proto;config/protos/UI.proto;config/protos/cme_reference_data.proto;config/protos/jetfix.proto;config/protos/keycode.proto;config/protos/logging.proto;config/protos/mercury_cfg.proto;config/protos/orderman_cfg.proto;config/protos/orders_fills_cleanup.proto;config/protos/perflog_cfg.proto;config/protos/position_cfg.proto;config/protos/quickbus_cfg.proto;config/protos/span.proto;config/protos/spreader.proto;config/protos/system.proto;config/protos/testkeys.proto;config/protos/threads.proto;config/protos/toggles.proto;config/tests/HTTPServer.cpp;config/tests/config_ref_tests.cpp;config/tests/config_tests.cpp;config/text_format/text_format.cpp;domain_model/Security.cpp;domain_model/Security.proto;domain_model/SecurityTests.cpp;domain_model/sod.cpp;domain_model/tests/domain_tests.cpp;expression/BooleanGrammar.cpp;expression/ExpressionEvaluator.cpp;expression/ParserExceptions.cpp;expression/Value.cpp;expression/tests/expression_parser_tests.cpp;jetfix/codec/FIXArray.cpp;jetfix/common/OutFIX.cpp;jetfix/connection/AsyncReader.cpp;jetfix/connection/IConnection.cpp;jetfix/connection/SocketConnection.cpp;jetfix/gateway/CoreGateway.cpp;jetfix/gateway/JetFIXGateway.cpp;jetfix/gateway/Session.cpp;jetfix/store/FIXFileStore.cpp;jetfix/store/session_name.cpp;jetfix/tests/async_reader_tests.cpp;jetfix/tests/decoding_tests.cpp;jetfix/tests/fix_encoding_stream_tests.cpp;jetfix/tests/fix_fragment_tests.cpp;jetfix/tests/jetfix_performance_tests.cpp;jetfix/tests/sample_fix.cpp;jetfix/tests/store_tests.cpp;logging/LoggerHub.cpp;logging/Sink.cpp;logging/logging.cpp;logging/tests/logging_tests.cpp;md/Diag/MDPeriodicDumper.cpp;md/Diag/ShmDumper.cpp;md/MBOProcessor.cpp;md/MBOServiceServer.cpp;md/MDClient.cpp;md/MDConsumer.cpp;md/MDConsumerHandle.cpp;md/MDConsumerInterop.cpp;md/MDProducer.cpp;md/MDProducerHandle.cpp;md/MemorySegmentUtils.cpp;md/PlatformLoader.cpp;md/PriceSize.cpp;md/SecurityCache.cpp;md/SecurityDB.cpp;md/SecurityIDRecorder.cpp;md/SecurityMapper.cpp;md/SecurityOracle.cpp;md/SettlementRecorder.cpp;md/Shm/FixedSecurity.cpp;md/SyntheticSecurityService.cpp;md/cme/MDP3Utils.cpp;md/common.cpp;md/ice/ICEUtils.cpp;md/protos/co2.proto;md/relay/QueryServer.cpp;md/relay/RelayClient.cpp;md/relay/RelayRecorder.cpp;md/test/Co2ManagedTestHelper.cpp;md/test/Co2TestInstrument.cpp;md/test/mbo_tests.cpp;md/test/md2_tests.cpp;md/test/md_test_utils.cpp;md/test/synthetic_book_merge_tests.cpp;md/vendor/OnixsUtils.cpp;mercury/actors/IPollableActor.cpp;mercury/broker/Broker.cpp;mercury/broker/BrokerProxy.cpp;mercury/broker/ILocalBroker.cpp;mercury/broker/IRemoteBroker.cpp;mercury/common/mercury_common.cpp;mercury/events/TimerEvent.cpp;mercury/executor/Executor.cpp;mercury/topics/Topic.cpp;metrics/metrics.cpp;metrics/system_metrics.cpp;orderman/actors/AsyncFactory.cpp;orderman/actors/FillStore.cpp;orderman/actors/GLBXExecutionGateway.cpLine truncated
|
||||
@@ -120,6 +120,7 @@ void configure_logging(bts::config::Logging const&cfg, bts::config::ThreadGroupC
|
||||
{log::Plugin,"Plugin"},
|
||||
{log::ClientSdk,"ClientSdk"},
|
||||
{log::Http,"Http"},
|
||||
{log::OrderMan2,"OrderMan2"},
|
||||
};
|
||||
|
||||
real_cfg.sinks["console"] =
|
||||
|
||||
@@ -24,7 +24,8 @@ constexpr log::Level Sys {log::Level::Max-1};
|
||||
|
||||
namespace log {
|
||||
|
||||
// Please keep this list in sync with Log.cs
|
||||
// Please keep this list in sync with Log.cs and make sure
|
||||
// to replicate the change in logging.cpp
|
||||
constexpr log::Subsystem Gen {0 };
|
||||
constexpr log::Subsystem Cfg {Gen.ordinal+1 };
|
||||
constexpr log::Subsystem QBus {Cfg.ordinal+1 };
|
||||
@@ -46,6 +47,7 @@ constexpr log::Subsystem DataFlow {Latency.ordinal+1 };
|
||||
constexpr log::Subsystem Plugin {DataFlow.ordinal+1 };
|
||||
constexpr log::Subsystem ClientSdk {Plugin.ordinal+1 };
|
||||
constexpr log::Subsystem Http {ClientSdk.ordinal+1 };
|
||||
constexpr log::Subsystem OrderMan2 {Http.ordinal+1 };
|
||||
|
||||
struct LoggerHandle {
|
||||
LoggerHandle(LoggerHandle const&) = delete;
|
||||
|
||||
@@ -1,30 +1,506 @@
|
||||
#include "lib/orderman_v2/actors/Gateway.h"
|
||||
#include <unordered_map>
|
||||
|
||||
#include "lib/logging/logging.h"
|
||||
#include "lib/orderman/limiter/Limiter.h"
|
||||
#include "lib/orderman_v2/execution/ICancelMsg.h"
|
||||
#include "lib/orderman_v2/execution/ICancelReplaceMsg.h"
|
||||
#include "lib/orderman_v2/execution/ILimiter.h"
|
||||
#include "lib/orderman_v2/execution/INewOrderSingleMsg.h"
|
||||
#include "lib/orderman_v2/execution/IRouter.h"
|
||||
#include "lib/orderman_v2/execution/IVenue.h"
|
||||
#include "lib/orderman_v2/execution/UserAccountVenue.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
|
||||
#include <boost/pool/object_pool.hpp>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
struct GW_OrderRecord2 {};
|
||||
using OrderMap = std::map<uint32_t,GW_OrderRecord2*>;
|
||||
struct GW_OrderRecord {
|
||||
GW_OrderRecord(OM_ID om_id, GW_BoundOrder const &order)
|
||||
: order(order), cancel_replace(nullptr), cancel(nullptr),
|
||||
originator(om_id) {}
|
||||
|
||||
GW_BoundOrder order;
|
||||
ICancelReplaceMsg *cancel_replace;
|
||||
ICancelMsg *cancel;
|
||||
OM_ID originator;
|
||||
|
||||
struct AndDuck {int x;};
|
||||
void clear_msgs() {
|
||||
cancel_replace = nullptr;
|
||||
cancel = nullptr;
|
||||
}
|
||||
|
||||
struct Gateway::PImpl {
|
||||
IVenueConnection &venue;
|
||||
OrderMap orders;
|
||||
boost::object_pool<AndDuck> orec_pool {1024*1024*20};
|
||||
bool is_routable() const { return cancel_replace != nullptr; }
|
||||
|
||||
void set_msgs(ICancelReplaceMsg const &cr, ICancelMsg &can) {
|
||||
cancel_replace = &cr.clone();
|
||||
cancel = &can.clone();
|
||||
}
|
||||
};
|
||||
|
||||
Gateway::Gateway(IVenueConnection &venue) :
|
||||
on_native_order_update(this),
|
||||
on_unknown_native_order_update(this),
|
||||
on_gw_error(this),
|
||||
me(new PImpl{venue,{}})
|
||||
{}
|
||||
enum class Gateway::State {
|
||||
W_BOOTSTRAP,
|
||||
W_SCHEDULE,
|
||||
PAUSED,
|
||||
W_LOGON,
|
||||
READY,
|
||||
W_LOGOUT
|
||||
};
|
||||
|
||||
struct Gateway::Hot {
|
||||
using OrderMap = std::unordered_map<OrderKey, GW_OrderRecord *>;
|
||||
using MsgTemplatesMap =
|
||||
std::unordered_map<UserAccountVenue, MsgTemplates, UserAccountVenueHash>;
|
||||
|
||||
Hot(IVenue &v, ILimiter &l)
|
||||
: state(State::W_BOOTSTRAP), venue(v), limiter(l), working_orders(),
|
||||
msg_templates(), orec_pool(1024 * 1024) {}
|
||||
|
||||
State state;
|
||||
IVenue &venue;
|
||||
ILimiter &limiter;
|
||||
OrderMap working_orders;
|
||||
MsgTemplatesMap msg_templates;
|
||||
boost::container::small_vector<IVenueMsg *, 8> pending_msg;
|
||||
boost::object_pool<GW_OrderRecord> orec_pool;
|
||||
};
|
||||
|
||||
struct Gateway::Cold {
|
||||
Cold(IRouter &r, IClock &c, GatewayCfg const &cfg)
|
||||
: router(r), clock(c), admin_data(), cfg(cfg), start_of_pause(),
|
||||
current_exponential_backoff(0), bootstrap_orders() {}
|
||||
IRouter &router;
|
||||
IClock &clock;
|
||||
api::admin::AdminData const *admin_data;
|
||||
GatewayCfg cfg;
|
||||
TimeStamp start_of_pause;
|
||||
size_t current_exponential_backoff;
|
||||
std::pair<TimeStamp, TimeStamp> venue_session;
|
||||
std::map<OM_ID, std::vector<GW_OrderBind> *> bootstrap_orders;
|
||||
};
|
||||
|
||||
struct Gateway::PImpl {
|
||||
PImpl(IVenue &v, ILimiter &l, IRouter &r, IClock &c, GatewayCfg const &cfg)
|
||||
: hot(v, l), cold(r, c, cfg) {}
|
||||
Hot hot;
|
||||
Cold cold;
|
||||
};
|
||||
|
||||
Gateway::Gateway(IVenue &v, ILimiter &l, IRouter &r, IClock &c,
|
||||
GatewayCfg const &cfg)
|
||||
: on_order_report(this), on_unknown_native_order_update(this),
|
||||
on_gw_error(this), me(new PImpl(v, l, r, c, cfg)) {}
|
||||
|
||||
Gateway::~Gateway() {}
|
||||
|
||||
void Gateway::do_slow_work() {
|
||||
switch (me->hot.state) {
|
||||
case State::W_BOOTSTRAP:
|
||||
if (has_bootstrap_data()) {
|
||||
transition(State::W_SCHEDULE);
|
||||
setup_bootstrap_orders();
|
||||
}
|
||||
break;
|
||||
case State::W_SCHEDULE:
|
||||
me->cold.venue_session = me->hot.venue.get_current_session();
|
||||
if (in_active_schedule()) {
|
||||
me->cold.start_of_pause = me->cold.clock.now();
|
||||
transition(State::PAUSED);
|
||||
}
|
||||
break;
|
||||
case State::PAUSED: {
|
||||
auto now = me->cold.clock.now();
|
||||
if (sec_diff(now, me->cold.start_of_pause) >
|
||||
(me->cold.cfg.pause_seconds
|
||||
<< me->cold.current_exponential_backoff)) {
|
||||
transition(State::W_LOGOUT);
|
||||
me->hot.venue.login();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case State::READY: {
|
||||
if (!in_active_schedule()) {
|
||||
me->hot.venue.logout();
|
||||
transition(State::W_LOGOUT);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case State::W_LOGON:
|
||||
case State::W_LOGOUT:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Gateway::on_om_bootstrap_orders(OM_BootstrapOrders const &orders) {
|
||||
auto &bso_map = me->cold.bootstrap_orders;
|
||||
bts_assert(me->hot.state == State::W_BOOTSTRAP);
|
||||
bts_assert(bso_map.size() < me->cold.cfg.om_count);
|
||||
bts_assert(bso_map.count(orders.originator) == 0);
|
||||
bts_assert(orders.target == me->cold.cfg.my_id);
|
||||
bts_assert(orders.originator.value < me->cold.cfg.om_count);
|
||||
bso_map[orders.originator] = orders.orders;
|
||||
}
|
||||
|
||||
void Gateway::on_gw_ops(const GW_Op_Batch &op_batch) {
|
||||
op_batch.visit(*this);
|
||||
send_pending_msg();
|
||||
}
|
||||
|
||||
void Gateway::on_account_pnl(const AccountPnLUpdate &pnl) {
|
||||
me->hot.limiter.update(pnl);
|
||||
}
|
||||
|
||||
void Gateway::on_position(const PositionUpdate &pos) {
|
||||
me->hot.limiter.update(pos);
|
||||
}
|
||||
|
||||
void Gateway::on_excess_liquidity(const ExcessLiquidityUpdate &l) {
|
||||
me->hot.limiter.update(l);
|
||||
}
|
||||
|
||||
void Gateway::on_admin_data(AdminDataUpdate const &admin) {
|
||||
me->cold.admin_data = admin.admin_data;
|
||||
me->hot.limiter.update(*me->cold.admin_data);
|
||||
me->cold.router.update(*me->cold.admin_data);
|
||||
|
||||
switch (me->hot.state) {
|
||||
case State::W_BOOTSTRAP:
|
||||
break;
|
||||
default:
|
||||
rebuild_msg_templates();
|
||||
}
|
||||
}
|
||||
|
||||
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderCreate &create) {
|
||||
auto &bound_order = create.bound_order;
|
||||
bts_assert_d(me->hot.working_orders.count(bound_order.key) == 0);
|
||||
|
||||
// Construct new order record
|
||||
auto gw_rec = me->hot.orec_pool.construct(om_id, bound_order);
|
||||
auto &order = gw_rec->order;
|
||||
|
||||
GW_OrderReport reply;
|
||||
switch (me->hot.state) {
|
||||
case State::READY: {
|
||||
|
||||
// Validate route
|
||||
auto &msg_templates = me->hot.msg_templates;
|
||||
INewOrderSingleMsg *new_order_single;
|
||||
auto it = msg_templates.find(order.uav);
|
||||
if (it == msg_templates.end()) {
|
||||
reply.set_ack(GW_OP_Result::ERROR_NO_ROUTE);
|
||||
break;
|
||||
}
|
||||
|
||||
// Set msgs in order record
|
||||
new_order_single = &it->second.new_order->clone();
|
||||
gw_rec->set_msgs(*it->second.cancel_replace, *it->second.cancel);
|
||||
|
||||
// Validate limit
|
||||
auto lqt = me->hot.limiter.can_send_new_order(
|
||||
order.uav.account, *order.security, order.side, order.quantity);
|
||||
if (lqt.error()) {
|
||||
reply.set_ack(lqt.result, lqt.message);
|
||||
break;
|
||||
}
|
||||
|
||||
// Validate messaging limits
|
||||
if (!me->hot.venue.under_messaging_limit()) {
|
||||
reply.set_ack(GW_OP_Result::ERROR_MESSAGING_BREACH);
|
||||
break;
|
||||
}
|
||||
|
||||
// All is good. Index the order record, copy the order params to
|
||||
// the order message and queue the message for sending.
|
||||
me->hot.working_orders.insert({bound_order.key, gw_rec});
|
||||
new_order_single->set_order_params(bound_order);
|
||||
me->hot.pending_msg.push_back(new_order_single);
|
||||
|
||||
// For speed we do not send acks for the operation until we hear
|
||||
// from the exchange.
|
||||
return;
|
||||
}
|
||||
default:
|
||||
reply.set_ack(GW_OP_Result::ERROR_GATEWAY_DISCONNECTED);
|
||||
break;
|
||||
}
|
||||
|
||||
// If we got to this point something went wrong and the creation of
|
||||
// the order failed. We skip the indexing of the order record,
|
||||
// since we will not need to lookup this order by key, and instead
|
||||
// send out a order report that details the cause of the failure.
|
||||
bts_assert_d(reply.last_ack.result != GW_OP_Result::OK);
|
||||
gw_rec->clear_msgs();
|
||||
reply.last_ack.req_id = create.req_id;
|
||||
reply.target = om_id;
|
||||
reply.last_exe_report = gw_rec->order.last_exe_report;
|
||||
reply.om_record = bound_order.om_record;
|
||||
reply.gw_record = gw_rec;
|
||||
on_order_report(reply);
|
||||
}
|
||||
|
||||
// When an order is recovered from disk or from the exchange (meaning
|
||||
// the exchange sends a report on an order we do not have a record of
|
||||
// creating) we are left in a situation where we have to create the
|
||||
// order record that represents the order but we do not have to
|
||||
// actually send the order. This is what the bind order operation is
|
||||
// for.
|
||||
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderBind &bind) {
|
||||
auto &order = bind.bound_order;
|
||||
bts_assert_d(me->hot.working_orders.count(order.key) == 0);
|
||||
|
||||
// Construct and index new order record
|
||||
auto gw_rec = me->hot.working_orders[order.key];
|
||||
bts_assert(!gw_rec);
|
||||
gw_rec = me->hot.orec_pool.construct(om_id, order);
|
||||
|
||||
GW_OrderReport reply;
|
||||
// Find the message templates for this UAV and clone them for this
|
||||
// order
|
||||
auto &msg_templates = me->hot.msg_templates;
|
||||
auto it = msg_templates.find(order.uav);
|
||||
if (it == msg_templates.end())
|
||||
reply.set_ack(GW_OP_Result::ERROR_NO_ROUTE);
|
||||
|
||||
reply.last_ack.req_id = bind.req_id;
|
||||
reply.target = om_id;
|
||||
reply.last_exe_report = order.last_exe_report;
|
||||
reply.om_record = order.om_record;
|
||||
reply.gw_record = gw_rec;
|
||||
on_order_report(reply);
|
||||
}
|
||||
|
||||
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderQuickUpdate &quick_update) {
|
||||
auto gw_rec = quick_update.gw_order_record;
|
||||
auto &order = gw_rec->order;
|
||||
|
||||
GW_OrderReport reply;
|
||||
switch (me->hot.state) {
|
||||
case State::READY: {
|
||||
|
||||
// Make sure the order can be routed
|
||||
if (!gw_rec->is_routable()) {
|
||||
reply.set_ack(GW_OP_Result::ERROR_ORDER_IS_NOT_ACTIVE);
|
||||
break;
|
||||
}
|
||||
|
||||
// Validate trading limits
|
||||
auto delta_q = quick_update.quantity.value - order.quantity.value;
|
||||
auto lqr = me->hot.limiter.can_update_order(
|
||||
order.uav.account, *order.security, order.side, delta_q);
|
||||
if (lqr.error()) {
|
||||
reply.set_ack(lqr.result, lqr.message);
|
||||
break;
|
||||
}
|
||||
|
||||
// Validate messaging limits
|
||||
if (!me->hot.venue.under_messaging_limit()) {
|
||||
reply.set_ack(GW_OP_Result::ERROR_MESSAGING_BREACH);
|
||||
break;
|
||||
}
|
||||
order.price = quick_update.price;
|
||||
order.quantity = quick_update.quantity;
|
||||
gw_rec->cancel_replace->update(order);
|
||||
me->hot.pending_msg.push_back(gw_rec->cancel_replace);
|
||||
|
||||
// We do not send out a order report for performance
|
||||
// reasons. Instead we delay the report until the exchange
|
||||
// reponds our order update.
|
||||
return;
|
||||
}
|
||||
default:
|
||||
reply.set_ack(GW_OP_Result::ERROR_GATEWAY_DISCONNECTED);
|
||||
break;
|
||||
}
|
||||
|
||||
// If we got here something went wrong and the update failed. This
|
||||
// is the exceptional path and it should almost never happen. In
|
||||
// this case we send out a new order report detailing the reasons
|
||||
// for the failure.
|
||||
bts_assert_d(reply.last_ack.result != GW_OP_Result::OK);
|
||||
reply.last_ack.req_id = quick_update.req_id;
|
||||
reply.target = om_id;
|
||||
reply.last_exe_report = order.last_exe_report;
|
||||
reply.om_record = order.om_record;
|
||||
reply.gw_record = gw_rec;
|
||||
on_order_report(reply);
|
||||
}
|
||||
|
||||
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderCancel &cancel) {
|
||||
auto gw_rec = cancel.gw_order_record;
|
||||
auto last_er = gw_rec->order.last_exe_report;
|
||||
auto &order = gw_rec->order;
|
||||
|
||||
bts_assert_d(last_er);
|
||||
|
||||
GW_OrderReport reply;
|
||||
switch (me->hot.state) {
|
||||
case State::READY: {
|
||||
|
||||
// Make sure the order is routable
|
||||
if (!gw_rec->is_routable()) {
|
||||
reply.set_ack(GW_OP_Result::ERROR_NO_ROUTE);
|
||||
break;
|
||||
}
|
||||
|
||||
gw_rec->cancel->update(order);
|
||||
me->hot.pending_msg.push_back(gw_rec->cancel);
|
||||
|
||||
// We do not send out a order report for performance
|
||||
// reasons. Instead we delay the report until the exchange
|
||||
// reponds to our cancel
|
||||
return;
|
||||
}
|
||||
default:
|
||||
reply.set_ack(GW_OP_Result::ERROR_GATEWAY_DISCONNECTED);
|
||||
break;
|
||||
}
|
||||
|
||||
// If we got here something went wrong and the cancel failed. This
|
||||
// is the exceptional path and it should almost never happen. In
|
||||
// this case we send out a new order report detailing the reasons
|
||||
// for the failure.
|
||||
bts_assert_d(reply.last_ack.result != GW_OP_Result::OK);
|
||||
reply.last_ack.req_id = cancel.req_id;
|
||||
reply.target = om_id;
|
||||
reply.last_exe_report = order.last_exe_report;
|
||||
reply.om_record = order.om_record;
|
||||
reply.gw_record = gw_rec;
|
||||
on_order_report(reply);
|
||||
}
|
||||
|
||||
// The difference between a full update and a quick update is that in
|
||||
// a full update we allow for the account / user to change. In this
|
||||
// case we have to re-create the messages for cancel and update since
|
||||
// these messages embed in them account and user specific information.
|
||||
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderFullUpdate &full_update) {
|
||||
auto gw_rec = full_update.gw_order_record;
|
||||
auto &order = gw_rec->order;
|
||||
|
||||
GW_OrderReport reply;
|
||||
switch (me->hot.state) {
|
||||
case State::READY: {
|
||||
|
||||
auto &msg_templates = me->hot.msg_templates;
|
||||
auto it = msg_templates.find(order.uav);
|
||||
if (it == msg_templates.end()) {
|
||||
reply.set_ack(GW_OP_Result::ERROR_NO_ROUTE);
|
||||
break;
|
||||
}
|
||||
|
||||
// Update existing record with the non quick parts of the full
|
||||
// order update. There is a bit of inconsistency here. We are
|
||||
// already setting the message tamplates, uav, moi and tif
|
||||
// fields below, even though the quick update might later fail
|
||||
// to set the quantity and price, leaving the order in a
|
||||
// half-updated half not-updated state. This should be benign
|
||||
// enough.
|
||||
gw_rec->set_msgs(*it->second.cancel_replace, *it->second.cancel);
|
||||
gw_rec->order.uav = full_update.uav;
|
||||
gw_rec->order.moi = full_update.moi;
|
||||
gw_rec->order.tif = full_update.tif;
|
||||
|
||||
// Fake a quick update for the rest
|
||||
GW_OrderQuickUpdate quick_update;
|
||||
quick_update.gw_order_record = full_update.gw_order_record;
|
||||
quick_update.quantity = full_update.quantity;
|
||||
quick_update.price = full_update.price;
|
||||
quick_update.req_id = full_update.req_id;
|
||||
on_gw_op(om_id, quick_update);
|
||||
}
|
||||
default:
|
||||
reply.set_ack(GW_OP_Result::ERROR_GATEWAY_DISCONNECTED);
|
||||
break;
|
||||
}
|
||||
|
||||
// If we got to this point something went wrong and the update of
|
||||
// the order failed. This should be very rare. In this case we send
|
||||
// a reply right away.
|
||||
bts_assert_d(reply.last_ack.result != GW_OP_Result::OK);
|
||||
gw_rec->clear_msgs();
|
||||
reply.last_ack.req_id = full_update.req_id;
|
||||
reply.target = om_id;
|
||||
reply.last_exe_report = gw_rec->order.last_exe_report;
|
||||
reply.om_record = order.om_record;
|
||||
reply.gw_record = gw_rec;
|
||||
on_order_report(reply);
|
||||
}
|
||||
|
||||
void Gateway::send_pending_msg() {
|
||||
auto &pending = me->hot.pending_msg;
|
||||
me->hot.venue.send(pending.data(), pending.data() + pending.size());
|
||||
pending.clear();
|
||||
}
|
||||
|
||||
bool Gateway::has_bootstrap_data() const {
|
||||
return me->cold.bootstrap_orders.size() == me->cold.cfg.om_count &&
|
||||
me->cold.admin_data != nullptr;
|
||||
}
|
||||
|
||||
bool Gateway::in_active_schedule() const {
|
||||
auto now = me->cold.clock.now();
|
||||
return now >= me->cold.venue_session.first &&
|
||||
now < me->cold.venue_session.second;
|
||||
}
|
||||
|
||||
void Gateway::transition(State state) {
|
||||
LOG(OrderMan, Info, "Transitioning gateway {} from {} to {}",
|
||||
me->cold.cfg.my_id.value, state_name(me->hot.state), state_name(state));
|
||||
me->hot.state = state;
|
||||
}
|
||||
|
||||
void Gateway::rebuild_msg_templates() {
|
||||
// First just rebuild our template cache
|
||||
me->hot.msg_templates.clear();
|
||||
auto all_uav = me->hot.limiter.get_all_user_account_venue();
|
||||
for (auto const &uav : all_uav) {
|
||||
auto rq = me->cold.router.get_route(uav);
|
||||
if (rq.has_route) {
|
||||
me->hot.msg_templates[uav] =
|
||||
me->hot.venue.get_msg_templates(rq.routing_record);
|
||||
}
|
||||
}
|
||||
|
||||
// Now go through every order and update its messages
|
||||
for (auto &p : me->hot.working_orders) {
|
||||
auto orec = p.second;
|
||||
orec->clear_msgs();
|
||||
if (auto it = me->hot.msg_templates.find(orec->order.uav);
|
||||
it != me->hot.msg_templates.end()) {
|
||||
orec->set_msgs(*it->second.cancel_replace, *it->second.cancel);
|
||||
} else {
|
||||
LOG(OrderMan, Error, "Order {} can no longer be routed. {}",
|
||||
orec->order.key, orec->order.uav.to_str());
|
||||
orec->clear_msgs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Gateway::setup_bootstrap_orders() {
|
||||
bts_assert(me->hot.state == State::W_BOOTSTRAP);
|
||||
for (auto [om_id, order_vec] : me->cold.bootstrap_orders)
|
||||
for (auto &bind_order : *order_vec)
|
||||
on_gw_op(om_id, bind_order);
|
||||
}
|
||||
|
||||
log::CharPtrWrapper Gateway::state_name(State state) {
|
||||
switch (state) {
|
||||
case State::W_BOOTSTRAP:
|
||||
return {"W_BOOTSTRAP"};
|
||||
case State::W_SCHEDULE:
|
||||
return {"W_SCHEDULE"};
|
||||
case State::PAUSED:
|
||||
return {"PAUSED"};
|
||||
case State::W_LOGON:
|
||||
return {"W_LOGON"};
|
||||
case State::READY:
|
||||
return {"READY"};
|
||||
case State::W_LOGOUT:
|
||||
return {"W_LOGOUT"};
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace orderman_v2
|
||||
} // namespace bts
|
||||
@@ -1,38 +1,63 @@
|
||||
#pragma once
|
||||
|
||||
#include "Actor.h"
|
||||
#include "lib/orderman_v2/events/events.h"
|
||||
#include "lib/orderman_v2/common.h"
|
||||
#include "lib/orderman_v2/events/events.h"
|
||||
#include "lib/orderman_v2/interconnect/ISlowWorker.h"
|
||||
#include "lib/orderman_v2/interconnect/Signal.h"
|
||||
#include "lib/logging/logging.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
class IVenueConnection;
|
||||
class IVenue;
|
||||
class ILimiter;
|
||||
class IRouter;
|
||||
class IClock;
|
||||
|
||||
class Gateway : public Actor {
|
||||
public:
|
||||
Gateway(IVenueConnection &);
|
||||
struct GatewayCfg;
|
||||
class Gateway : public Actor, ISlowWorker, IGW_Op_Visitor {
|
||||
public:
|
||||
Gateway(IVenue &, ILimiter &, IRouter &, IClock &c, GatewayCfg const &);
|
||||
~Gateway();
|
||||
|
||||
void do_work();
|
||||
|
||||
//Inputs
|
||||
void on_om_bootstrap_orders(OM_BootstrapOrders const&) {};
|
||||
void on_gw_ops (const GW_Op_Batch &) {};
|
||||
void on_account_pnl (const AccountPnLUpdate &) {}
|
||||
void on_excess_liquidity (const ExcessLiquidityUpdate &) {}
|
||||
void on_admin_data(const AdminDataUpdate &) {}
|
||||
void on_position(const PositionUpdate &) {}
|
||||
|
||||
void do_slow_work() override;
|
||||
|
||||
// Inputs
|
||||
void on_om_bootstrap_orders(OM_BootstrapOrders const &);
|
||||
void on_gw_ops(const GW_Op_Batch &);
|
||||
void on_account_pnl(const AccountPnLUpdate &);
|
||||
void on_position(const PositionUpdate &);
|
||||
void on_excess_liquidity(const ExcessLiquidityUpdate &);
|
||||
void on_admin_data(const AdminDataUpdate &);
|
||||
|
||||
// Signals
|
||||
Signal<GW_ExeReport> on_native_order_update;
|
||||
Signal<GW_OrderReport> on_order_report;
|
||||
Signal<GW_UnknownOrderExeReport> on_unknown_native_order_update;
|
||||
Signal<GW_Error> on_gw_error;
|
||||
|
||||
private:
|
||||
private:
|
||||
enum class State;
|
||||
struct PImpl;
|
||||
struct Hot;
|
||||
struct Cold;
|
||||
std::unique_ptr<PImpl> me;
|
||||
|
||||
// Destructuring of GW_Op_Batch
|
||||
void on_gw_op(OM_ID, const GW_OrderCreate &) override;
|
||||
void on_gw_op(OM_ID, const GW_OrderBind &) override;
|
||||
void on_gw_op(OM_ID, const GW_OrderQuickUpdate &) override;
|
||||
void on_gw_op(OM_ID, const GW_OrderCancel &) override;
|
||||
void on_gw_op(OM_ID, const GW_OrderFullUpdate &) override;
|
||||
|
||||
void send_pending_msg();
|
||||
bool has_bootstrap_data() const;
|
||||
bool in_active_schedule() const;
|
||||
void transition(State);
|
||||
void rebuild_msg_templates();
|
||||
void setup_bootstrap_orders();
|
||||
static log::CharPtrWrapper state_name(State) ;
|
||||
};
|
||||
|
||||
}}
|
||||
} // namespace orderman_v2
|
||||
} // namespace bts
|
||||
@@ -14,7 +14,7 @@ public:
|
||||
|
||||
// Inputs
|
||||
void on_bootstrap_orders(BootstrapOrders) {}
|
||||
void on_native_order_update (GW_ExeReport const&) {}
|
||||
void on_native_order_update (GW_OrderReport const&) {}
|
||||
void on_unknown_native_order_update(GW_UnknownOrderExeReport const&) {}
|
||||
void on_create_order (CreateOrderRequest const&) {}
|
||||
void on_update_order (UpdateOrderRequest const&) {}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "common.h"
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "lib/domain_model/common.h"
|
||||
#include "lib/md/PriceSize.h"
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
|
||||
@@ -22,7 +24,7 @@ struct hash<bts::orderman_v2::Value<Tag, Value>> {
|
||||
return hash<Value>()(k.value);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
@@ -43,20 +45,36 @@ std::ostream &operator<<(std::ostream &s, Value<Tag, V> const &v) {
|
||||
}
|
||||
|
||||
using BookSide = std::array<md::PriceSize, 5>;
|
||||
using OrderKey = Value<struct OrderKeyTag,uint32_t>;
|
||||
using Price = Value<struct PriceTag,double>;
|
||||
using Quantity = Value<struct QuantityTag,double>;
|
||||
using OM_Id = Value<struct OM_IdTag,uint8_t>;
|
||||
using GW_Id = Value<struct GW_IdTag,uint8_t>;
|
||||
using RequestID = Value<struct RequestIDTag,uint32_t>;
|
||||
using UserID = Value<struct UserIDTag,uint16_t>;
|
||||
using AccountID = Value<struct AccountIDTag,uint16_t>;
|
||||
using SecurityKey = Value<struct SecurityKeyTag,uint32_t>;
|
||||
using Side = Value<struct SideTag,uint8_t>;
|
||||
using ManualOrderIndicator = Value<struct ManualOrderIndicatorTag,uint8_t>;
|
||||
using TimeInForce = Value<struct TimeInForceTag,uint8_t>;
|
||||
using OrderKey = Value<struct OrderKeyTag, uint32_t>;
|
||||
using Price = Value<struct PriceTag, double>;
|
||||
using Quantity = Value<struct QuantityTag, double>;
|
||||
using OM_ID = Value<struct OM_IDTag, uint8_t>;
|
||||
using GW_ID = Value<struct GW_IDTag, uint8_t>;
|
||||
using OM_Request_ID = Value<struct OM_Request_IDTag, uint32_t>;
|
||||
using GW_Request_ID = Value<struct GW_Request_IDTag, uint32_t>;
|
||||
using UserID = Value<struct UserIDTag, uint16_t>;
|
||||
using AccountID = Value<struct AccountIDTag, uint16_t>;
|
||||
using SecurityKey = Value<struct SecurityKeyTag, uint32_t>;
|
||||
using Side = Value<struct SideTag, uint8_t>;
|
||||
using ManualOrderIndicator = Value<struct ManualOrderIndicatorTag, uint8_t>;
|
||||
using TimeInForce = Value<struct TimeInForceTag, uint8_t>;
|
||||
|
||||
enum class OrderStatus : uint8_t { WORKING, COMPLETED, CANCELED };
|
||||
enum class OrderStatus : uint8_t { WORKING, COMPLETED, CANCELED, REJECTED };
|
||||
|
||||
enum GW_OP_Result {
|
||||
OK,
|
||||
ERROR_NO_ROUTE,
|
||||
ERROR_MESSAGING_BREACH,
|
||||
ERROR_GATEWAY_DISCONNECTED,
|
||||
ERROC_SEC_LONG_POS_BREACHED,
|
||||
ERROR_PROD_LONG_POS_BREACHED,
|
||||
ERROR_SEC_SHORT_POS_BREACHED,
|
||||
ERROR_PROD_SHORT_POS_BREACHED,
|
||||
ERROR_CLIP_SIZE_BREACHED,
|
||||
ERROR_LOSS_LIMIT_BREACHED,
|
||||
ERROR_MARGIN_LIMIT_BREACHED,
|
||||
ERROR_ORDER_IS_NOT_ACTIVE
|
||||
};
|
||||
|
||||
class Book {
|
||||
public:
|
||||
@@ -96,5 +114,10 @@ class Book {
|
||||
std::array<BookSide, 2> _book;
|
||||
};
|
||||
|
||||
class IClock {
|
||||
public:
|
||||
virtual TimeStamp now() = 0;
|
||||
};
|
||||
|
||||
} // namespace orderman_v2
|
||||
} // namespace bts
|
||||
@@ -1,8 +1,10 @@
|
||||
* Header
|
||||
#+TITLE: V2 docs
|
||||
#+OPTIONS: ^:nil
|
||||
#+OPTIONS: H:2
|
||||
#+OPTIONS: ^:nil H:2 author:nil creator:nil timestamp:nil toc:nil
|
||||
#+OPTIONS: html-postamble:nil
|
||||
|
||||
* Data flow
|
||||
#+begin_src dot :file data_flow.png :cmdline -Kdot -Tpng
|
||||
digraph G {
|
||||
@@ -36,13 +38,17 @@ digraph G {
|
||||
[[file:algo_flow.png]]
|
||||
|
||||
* NewOrder
|
||||
** Known at startup
|
||||
** Immutable
|
||||
BeginString = FIX.4.2 8=FIX.4.2
|
||||
MsgType = NewOrderSingle 35=D
|
||||
** When fields are known
|
||||
*** Known at startup
|
||||
BeginString = FIX.4.2 8=FIX.4.2
|
||||
MsgType = NewOrderSingle 35=D
|
||||
TargetCompID = CME 56=CME
|
||||
TargetSubID = 80 57=80
|
||||
SenderCompID = DE7534N 49=DE7534N
|
||||
** Derivable from hash of routing record
|
||||
*** Derivable from account and user
|
||||
SenderLocationID = US,IL 142=US,IL
|
||||
SenderSubID = DO3BTSJGR 50=DO3BTSJGR
|
||||
Account = CLX60635 1=CLX60635
|
||||
@@ -50,15 +56,15 @@ Account = CLX60635 1=CLX60635
|
||||
1028 = N 1028=N
|
||||
CustomerOrFirm = 0 204=0
|
||||
7928 = 6935102 7928=6935102
|
||||
** Known at stamp
|
||||
*** Known at stamp
|
||||
BodyLength = 000257 9=000257
|
||||
MsgSeqNum = 000000113 34=000000113
|
||||
LastMsgSeqNumProcessed = 000000110 369=000000110
|
||||
CheckSum = 018 10=018
|
||||
** Known when clock ticks
|
||||
*** Known when clock ticks
|
||||
TransactTime = 20190804-22:11:06.592 60=20190804-22:11:06.592
|
||||
SendingTime = 20190804-22:11:06.602 52=20190804-22:11:06.602
|
||||
** Known when order is known
|
||||
*** Known when order is known
|
||||
SecurityDesc = HOU9-HOX9 107=HOU9-HOX9
|
||||
Side = 2 54=2
|
||||
TimeInForce = 0 59=0
|
||||
@@ -66,7 +72,7 @@ ClOrdID = 00000101730000432660 11=00000101730000432
|
||||
OrderQty = 000001 38=000001
|
||||
OrdType = 2 40=2
|
||||
Price = -0000093.00000000 44=-0000093.00000000
|
||||
* Whole thing
|
||||
** Whole thing
|
||||
BeginString = FIX.4.2 8=FIX.4.2
|
||||
BodyLength = 000257 9=000257
|
||||
MsgType = NewOrderSingle 35=D
|
||||
@@ -93,62 +99,37 @@ OrdType = 2 40=2
|
||||
Price = -0000093.00000000 44=-0000093.00000000
|
||||
CheckSum = 018 10=018
|
||||
|
||||
* Structure
|
||||
** Header:
|
||||
- BeginString
|
||||
- *BodyLength*
|
||||
- MsgType
|
||||
- *MsgSeqNum*
|
||||
- *LastMsgSeqNumProcessed*
|
||||
- *SendingTime*
|
||||
- TargetCompID
|
||||
- TargetSubID
|
||||
- SenderCompID
|
||||
** Routing:
|
||||
- SenderLocationID
|
||||
- SenderSubID
|
||||
- Account
|
||||
- 0702
|
||||
- 1028
|
||||
- CustomerOrFirm
|
||||
- 7928
|
||||
** Body
|
||||
- Side
|
||||
- TimeInForce
|
||||
- ClOrdID
|
||||
- OrdQty
|
||||
- OrdType
|
||||
- Price
|
||||
- TransactTime
|
||||
** Footer
|
||||
- SecurityDesc
|
||||
- Checksum
|
||||
|
||||
* Field sources
|
||||
| BeginString | |
|
||||
| MsgType | |
|
||||
| SenderCompID | |
|
||||
| TargetCompID | |
|
||||
| 9702 | |
|
||||
| 7928 | |
|
||||
| TargetSubID | |
|
||||
| SendingTime | clock |
|
||||
| TransactTime | clock |
|
||||
| CustomerOrFirm | user/account/venue |
|
||||
| SenderSubID | user/account/venue |
|
||||
| SenderLocationID | user/account/venue |
|
||||
| Account | user/account/venue |
|
||||
| Side | Order |
|
||||
| TimeInForce | Order |
|
||||
| 1028 | Order |
|
||||
| SecurityDesc | Order |
|
||||
| ClOdID | Order |
|
||||
| OrderQty | Order |
|
||||
| Price | Order |
|
||||
| BodyLength | finished msg |
|
||||
| MsgSeqNum | finished msg |
|
||||
| LastMsg | finished msg |
|
||||
| CheckSum | finished msg |
|
||||
* Dimensioning
|
||||
- executor count
|
||||
* Bootstrap process
|
||||
** GWs
|
||||
Gateways will wait until they have:
|
||||
- The list of all boostrap orders, that is orders that are currently thought to be active
|
||||
- The admin object
|
||||
- Filled position
|
||||
* Quick Notes
|
||||
- when creating or binding orders the gw will reply to the create/bind with a execution report that contains the record key
|
||||
- this could mean that the OM will have to buffer any updates until it receives this execution report
|
||||
- the alternative is to fallback to keys to look up the order. This should be OK, since the branch should be totally predictable
|
||||
* To discuss with Taha
|
||||
- Full positions are now calculated outside the OM
|
||||
* On limiter enforcing
|
||||
- Because we now have potentially multiple threads generating updates to the working position it is no longer possible for the order manager, now the gateway, to assume it knows all the working positions. We have two options here, we can either use shared state and have all the threads coordinate access to it, or we can have the full position (filled + working) to be computed elsewhere. Since we are already late in observing the filled position we are really no worse off by also being late in observing the filled position. So we opt for having it all entirely computed elsewhere.
|
||||
* Work Log
|
||||
** <2019-11-25 Mon>
|
||||
*** Goals
|
||||
- Make substantial headway into Gateway
|
||||
*** Work
|
||||
**** Gateway
|
||||
:LOGBOOK:
|
||||
CLOCK: [2019-11-25 Mon 09:29]
|
||||
:END:
|
||||
** <2019-11-24 Sun>
|
||||
Improved the way we calculate fix tag strings and crc at runtime, droppnig the metaprogramming machinery in favour of a constexpr function
|
||||
** <2019-11-23 Sat>
|
||||
Worked a little on the gateway.
|
||||
1) We can distinguish full updates from quick updates. Full updates can update anything that is updatable, but quick updates can only update price and size. Full updates result in obtaining new IMessage pointers
|
||||
2) We should have an async call added to the api, maybe something like this:
|
||||
do_async(action_to_do, cb_when_complete);
|
||||
3) It might be necessary to bring back on_before_launch and in general keep the API stable. It will be a lot of work if there substantial changes.
|
||||
4) I need to keep a log of the work, with a single place for notes.
|
||||
|
||||
|
||||
@@ -1,14 +1,22 @@
|
||||
#pragma once
|
||||
#include "lib/orderman_v2/common.h"
|
||||
#include "lib/orderman_v2/execution/ExecReport.h"
|
||||
#include "lib/orderman_v2/interconnect/Action.h"
|
||||
#include "lib/orderman_v2/execution/UserAccountVenue.h"
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
class GW_OrderRecord;
|
||||
class OM_NativeOrderRecord;
|
||||
class IExecReport;
|
||||
struct GW_OrderRecord;
|
||||
struct OM_NativeOrderRecord;
|
||||
class ExecReport;
|
||||
|
||||
struct GatewayCfg {
|
||||
uint8_t om_count;
|
||||
GW_ID my_id;
|
||||
int pause_seconds;
|
||||
};
|
||||
|
||||
template <class EV> constexpr bool meets_event_constraints() {
|
||||
return std::is_trivial<EV>::value && sizeof(EV) <= MaxEventSize;
|
||||
@@ -50,54 +58,37 @@ struct SecurityStatusUpdate {
|
||||
static_assert(meets_event_constraints<SecurityStatusUpdate>());
|
||||
|
||||
struct PositionUpdate {
|
||||
SecurityKey key;
|
||||
api::Security *const security;
|
||||
AccountID account_id;
|
||||
Quantity long_quantity;
|
||||
Quantity short_quantity;
|
||||
};
|
||||
static_assert(meets_event_constraints<PositionUpdate>());
|
||||
|
||||
|
||||
struct CommonOrderState {
|
||||
OrderKey order_key;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
Quantity total_fills;
|
||||
Price avg_price;
|
||||
Quantity last_fills;
|
||||
Price last_price;
|
||||
OrderStatus status;
|
||||
struct GW_Op_Ack {
|
||||
GW_OP_Result result;
|
||||
GW_Request_ID req_id;
|
||||
char const* message;
|
||||
};
|
||||
|
||||
struct GW_ExeReport {
|
||||
CommonOrderState common;
|
||||
IExecReport const *last_report;
|
||||
OM_NativeOrderRecord const *om_record;
|
||||
GW_OrderRecord const *gw_record;
|
||||
OM_Id target;
|
||||
};
|
||||
static_assert(meets_event_constraints<GW_ExeReport>());
|
||||
|
||||
struct GW_UnknownOrderExeReport {
|
||||
CommonOrderState common;
|
||||
api::Security const*security;
|
||||
GW_Id source_gw;
|
||||
IExecReport const *last_report;
|
||||
api::Security const *security;
|
||||
GW_ID source_gw;
|
||||
ExecReport const *last_exe_report;
|
||||
};
|
||||
static_assert(meets_event_constraints<GW_UnknownOrderExeReport>());
|
||||
|
||||
struct OM_OrderUpdate {
|
||||
CommonOrderState common;
|
||||
OrderKey parent_key;
|
||||
IExecReport const *last_report;
|
||||
ExecReport const *last_exe_report;
|
||||
api::orderman::OrderDefinition const *def;
|
||||
const char *last_msg;
|
||||
};
|
||||
static_assert(meets_event_constraints<OM_OrderUpdate>());
|
||||
|
||||
struct CreateOrderRequest {
|
||||
OM_Id target;
|
||||
RequestID request_id;
|
||||
OM_ID target;
|
||||
OM_Request_ID request_id;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
api::orderman::OrderDefinition const *def;
|
||||
@@ -105,8 +96,8 @@ struct CreateOrderRequest {
|
||||
static_assert(meets_event_constraints<CreateOrderRequest>());
|
||||
|
||||
struct UpdateOrderRequest {
|
||||
OM_Id target;
|
||||
RequestID request_id;
|
||||
OM_ID target;
|
||||
OM_Request_ID request_id;
|
||||
OrderKey key;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
@@ -115,15 +106,15 @@ struct UpdateOrderRequest {
|
||||
static_assert(meets_event_constraints<UpdateOrderRequest>());
|
||||
|
||||
struct CancelOrderRequest {
|
||||
OM_Id target;
|
||||
RequestID request_id;
|
||||
OM_ID target;
|
||||
OM_Request_ID request_id;
|
||||
OrderKey key;
|
||||
};
|
||||
static_assert(meets_event_constraints<CancelOrderRequest>());
|
||||
|
||||
struct DetachOrderRequest {
|
||||
OM_Id target;
|
||||
RequestID request_id;
|
||||
OM_ID target;
|
||||
OM_Request_ID request_id;
|
||||
OrderKey key;
|
||||
};
|
||||
static_assert(meets_event_constraints<DetachOrderRequest>());
|
||||
@@ -137,43 +128,85 @@ enum GW_Op_Code : uint8_t {
|
||||
BIND
|
||||
};
|
||||
|
||||
struct GW_OrderCreate {
|
||||
static const auto code = GW_Op_Code::CREATE;
|
||||
api::Security const*security;
|
||||
struct GW_OrderReport;
|
||||
|
||||
struct GW_BoundOrder {
|
||||
api::Security const *security;
|
||||
OM_NativeOrderRecord const *om_record;
|
||||
ExecReport const *last_exe_report;
|
||||
OrderKey key;
|
||||
UserID user_id;
|
||||
AccountID account_id;
|
||||
UserAccountVenue uav;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
Side side;
|
||||
ManualOrderIndicator moi;
|
||||
TimeInForce tif;
|
||||
Side side;
|
||||
};
|
||||
|
||||
struct GW_OrderCreate {
|
||||
static const auto code = GW_Op_Code::CREATE;
|
||||
GW_BoundOrder bound_order;
|
||||
GW_Request_ID req_id;
|
||||
};
|
||||
|
||||
struct GW_OrderBind {
|
||||
static const auto code = GW_Op_Code::BIND;
|
||||
GW_BoundOrder bound_order;
|
||||
GW_Request_ID req_id;
|
||||
};
|
||||
|
||||
struct GW_OrderQuickUpdate {
|
||||
static const auto code = GW_Op_Code::QUICK_UPDATE;
|
||||
GW_OrderRecord *order_record;
|
||||
GW_OrderRecord *gw_order_record;
|
||||
Quantity quantity;
|
||||
Price price;
|
||||
GW_Request_ID req_id;
|
||||
};
|
||||
|
||||
struct GW_OrderFullUpdate {
|
||||
static const auto code = GW_Op_Code::FULL_UPDATE;
|
||||
GW_OrderRecord *gw_order_record;
|
||||
Quantity quantity;
|
||||
Price price;
|
||||
ManualOrderIndicator moi;
|
||||
TimeInForce tif;
|
||||
UserAccountVenue uav;
|
||||
GW_Request_ID req_id;
|
||||
};
|
||||
|
||||
struct GW_OrderCancel {
|
||||
static const auto code = GW_Op_Code::CANCEL;
|
||||
GW_OrderRecord *order_record;
|
||||
GW_OrderRecord *gw_order_record;
|
||||
GW_Request_ID req_id;
|
||||
};
|
||||
|
||||
struct GW_OrderReport {
|
||||
ExecReport const *last_exe_report;
|
||||
OM_NativeOrderRecord const *om_record;
|
||||
GW_OrderRecord const *gw_record;
|
||||
GW_Op_Ack last_ack;
|
||||
OM_ID target;
|
||||
|
||||
void set_ack(GW_OP_Result result, const char*message=nullptr) {
|
||||
last_ack.result = result;
|
||||
last_ack.message = message;
|
||||
}
|
||||
};
|
||||
static_assert(meets_event_constraints<GW_OrderReport>());
|
||||
|
||||
class IGW_Op_Visitor {
|
||||
public:
|
||||
virtual void on(GW_OrderCreate &) = 0;
|
||||
virtual void on(GW_OrderQuickUpdate &) = 0;
|
||||
virtual void on(GW_OrderCancel &) = 0;
|
||||
virtual void on_gw_op(OM_ID, const GW_OrderCreate &) = 0;
|
||||
virtual void on_gw_op(OM_ID, const GW_OrderQuickUpdate &) = 0;
|
||||
virtual void on_gw_op(OM_ID, const GW_OrderCancel &) = 0;
|
||||
virtual void on_gw_op(OM_ID, const GW_OrderFullUpdate &) = 0;
|
||||
virtual void on_gw_op(OM_ID, const GW_OrderBind &) = 0;
|
||||
};
|
||||
|
||||
struct GW_Op_Batch {
|
||||
struct Header {
|
||||
OM_Id originator;
|
||||
GW_Id target;
|
||||
OM_ID originator;
|
||||
GW_ID target;
|
||||
uint8_t n_msgs;
|
||||
} header;
|
||||
|
||||
@@ -195,27 +228,31 @@ struct GW_Op_Batch {
|
||||
}
|
||||
|
||||
template <class OP>
|
||||
void consume(IGW_Op_Visitor &v, uint8_t* &buffer) {
|
||||
v.on(*((OP*) (buffer+1)));
|
||||
buffer+= (1+sizeof(OP));
|
||||
void consume(IGW_Op_Visitor &v, uint8_t const *&buffer) const {
|
||||
v.on_gw_op(header.originator, *((OP *)(buffer + 1)));
|
||||
buffer += (1 + sizeof(OP));
|
||||
}
|
||||
|
||||
void visit(IGW_Op_Visitor &v) {
|
||||
void visit(IGW_Op_Visitor &v) const {
|
||||
auto n_msgs = header.n_msgs;
|
||||
auto cursor = buffer.data();
|
||||
while (n_msgs--) {
|
||||
auto op_code = (GW_Op_Code)* (cursor);
|
||||
auto op_code = (GW_Op_Code) * (cursor);
|
||||
switch (op_code) {
|
||||
case GW_Op_Code::CREATE:
|
||||
consume<GW_OrderCreate>(v,cursor);
|
||||
break;
|
||||
case GW_Op_Code::QUICK_UPDATE:
|
||||
consume<GW_OrderQuickUpdate>(v,cursor);
|
||||
consume<GW_OrderQuickUpdate>(v, cursor);
|
||||
break;
|
||||
case GW_Op_Code::CREATE:
|
||||
consume<GW_OrderCreate>(v, cursor);
|
||||
break;
|
||||
case GW_Op_Code::CANCEL:
|
||||
consume<GW_OrderCancel>(v,cursor);
|
||||
consume<GW_OrderCancel>(v, cursor);
|
||||
break;
|
||||
default:
|
||||
case GW_Op_Code::FULL_UPDATE:
|
||||
consume<GW_OrderFullUpdate>(v, cursor);
|
||||
break;
|
||||
case GW_Op_Code::BIND:
|
||||
consume<GW_OrderBind>(v, cursor);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -226,27 +263,32 @@ static_assert(meets_event_constraints<GW_Op_Batch>());
|
||||
// Order Ops
|
||||
|
||||
struct OM_BootstrapOrders {
|
||||
OM_Id originator;
|
||||
GW_Id target;
|
||||
std::vector<GW_OrderCreate> *orders;
|
||||
OM_ID originator;
|
||||
GW_ID target;
|
||||
std::vector<GW_OrderBind> *orders;
|
||||
};
|
||||
|
||||
struct GW_Status {
|
||||
GW_Id gw;
|
||||
GW_ID gw;
|
||||
bool connected;
|
||||
};
|
||||
static_assert(meets_event_constraints<GW_Status>());
|
||||
|
||||
struct GW_Error {
|
||||
GW_Id gw;
|
||||
enum uint8_t { CANCEL_REJECT, BUSSINESS_REJECT, SESSION_REJECT, DISCONNECT } error;
|
||||
GW_ID gw;
|
||||
enum uint8_t {
|
||||
CANCEL_REJECT,
|
||||
BUSSINESS_REJECT,
|
||||
SESSION_REJECT,
|
||||
DISCONNECT
|
||||
} error;
|
||||
const char *error_msg;
|
||||
OrderKey order_key;
|
||||
};
|
||||
static_assert(meets_event_constraints<GW_Error>());
|
||||
|
||||
struct OM_Reply {
|
||||
RequestID req_id;
|
||||
OM_Request_ID req_id;
|
||||
const char *error_msg;
|
||||
bool success;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include "lib/orderman_v2/common.h"
|
||||
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
class ExecReport {
|
||||
public:
|
||||
OrderKey order_key;
|
||||
Price price;
|
||||
Quantity quantity;
|
||||
Quantity total_fills;
|
||||
Price avg_price;
|
||||
Quantity last_fills;
|
||||
Price last_price;
|
||||
OrderStatus status;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "ICancelMsg.h"
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "lib/orderman_v2/execution/IVenueMsg.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
struct GW_BoundOrder;
|
||||
|
||||
class ICancelMsg : public IVenueMsg {
|
||||
public:
|
||||
virtual ICancelMsg& clone() const;
|
||||
virtual void update(GW_BoundOrder const&) const;
|
||||
virtual ~ICancelMsg() {}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "ICancelReplaceMsg.h"
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "lib/orderman_v2/execution/IVenueMsg.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
struct GW_BoundOrder;
|
||||
|
||||
class ICancelReplaceMsg : public IVenueMsg {
|
||||
public:
|
||||
virtual void update(GW_BoundOrder const&);
|
||||
virtual ICancelReplaceMsg& clone() const = 0;
|
||||
virtual ~ICancelReplaceMsg() {}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "ILimiter.h"
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "lib/orderman_v2/common.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {namespace admin { class AdminData; }}
|
||||
|
||||
namespace orderman_v2 {
|
||||
|
||||
struct AccountPnLUpdate;
|
||||
struct PositionUpdate;
|
||||
struct ExcessLiquidityUpdate;
|
||||
struct UserAccountVenue;
|
||||
|
||||
class ILimiter {
|
||||
public:
|
||||
|
||||
struct LimiterQueryResult {
|
||||
GW_OP_Result result;
|
||||
char const*message;
|
||||
bool ok() const { return result == GW_OP_Result::OK; }
|
||||
bool error() const { return !ok(); }
|
||||
};
|
||||
|
||||
virtual LimiterQueryResult can_send_new_order(AccountID account,
|
||||
api::Security const &sec,
|
||||
Side side, Quantity quantity);
|
||||
|
||||
virtual LimiterQueryResult can_update_order(AccountID account,
|
||||
api::Security const &sec,
|
||||
Side side, double delta);
|
||||
|
||||
virtual void update(api::admin::AdminData const &admin);
|
||||
virtual void update(AccountPnLUpdate const &) = 0;
|
||||
virtual void update(PositionUpdate const &) = 0;
|
||||
virtual void update(ExcessLiquidityUpdate const &) = 0;
|
||||
virtual std::vector<UserAccountVenue> get_all_user_account_venue() const = 0;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "INewOrderSingleMsg.h"
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
#include "lib/orderman_v2/execution/IVenueMsg.h"
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
struct GW_BoundOrder;
|
||||
|
||||
class INewOrderSingleMsg : public IVenueMsg {
|
||||
public:
|
||||
virtual INewOrderSingleMsg & clone() const;
|
||||
virtual void set_order_params(GW_BoundOrder const&);
|
||||
virtual ~INewOrderSingleMsg() {}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "IRouter.h"
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include "lib/api/services/OrderService.pb.h"
|
||||
|
||||
namespace bts {
|
||||
|
||||
namespace api {namespace admin {class AdminData;}}
|
||||
|
||||
namespace orderman_v2 {
|
||||
struct UserAccountVenue;
|
||||
|
||||
class IRouter {
|
||||
public:
|
||||
virtual void update(api::admin::AdminData const &admin);
|
||||
|
||||
struct RouteQueryResult {
|
||||
bool has_route;
|
||||
std::string error_msg;
|
||||
api::orderman::RoutingRecord routing_record;
|
||||
};
|
||||
virtual RouteQueryResult get_route(UserAccountVenue const &) = 0;
|
||||
};
|
||||
}}
|
||||
@@ -0,0 +1 @@
|
||||
#include "IVenue.h"
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
|
||||
namespace bts {
|
||||
namespace api {namespace orderman { class RoutingRecord;}}
|
||||
|
||||
namespace orderman_v2 {
|
||||
|
||||
class ExeReport;
|
||||
|
||||
class INewOrderSingleMsg;
|
||||
class ICancelReplaceMsg;
|
||||
class ICancelMsg;
|
||||
class IVenueMsg;
|
||||
|
||||
struct MsgTemplates {
|
||||
INewOrderSingleMsg* new_order;
|
||||
ICancelReplaceMsg* cancel_replace;
|
||||
ICancelMsg* cancel;
|
||||
};
|
||||
|
||||
class IVenue {
|
||||
public:
|
||||
virtual std::pair<TimeStamp,TimeStamp> get_current_session() = 0;
|
||||
virtual void logout() = 0;
|
||||
virtual void login() = 0;
|
||||
virtual MsgTemplates
|
||||
get_msg_templates(api::orderman::RoutingRecord const &) = 0;
|
||||
virtual bool under_messaging_limit() = 0;
|
||||
virtual void send(IVenueMsg**begin, IVenueMsg**end);
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,2 @@
|
||||
#include "IVenueMsg.h"
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
class IVenueMsg {
|
||||
public:
|
||||
virtual ~IVenueMsg() {}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,13 @@
|
||||
#prama once
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
class IVenueObserver {
|
||||
public:
|
||||
virtual void on_venue_logon() = 0;
|
||||
virtual void on_venue_logout() = 0;
|
||||
virtual void on_venue_logon_failure() = 0;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <fmt/format.h>
|
||||
#include <string>
|
||||
|
||||
namespace bts {
|
||||
namespace orderman_v2 {
|
||||
|
||||
struct UserAccountVenue {
|
||||
UserID user;
|
||||
AccountID account;
|
||||
api::Venue venue;
|
||||
bool operator==(UserAccountVenue const &rhs) const {
|
||||
return user == rhs.user && account == rhs.account && venue == rhs.venue;
|
||||
}
|
||||
|
||||
std::string to_str() {
|
||||
return fmt::format (" user_id: {} account_id: {} venue: {}",
|
||||
user.value,
|
||||
account.value,
|
||||
api::Venue_Name(venue));
|
||||
}
|
||||
};
|
||||
|
||||
struct UserAccountVenueHash {
|
||||
std::size_t operator()(UserAccountVenue const &k) const {
|
||||
size_t result = k.user.value;
|
||||
boost::hash_combine(result, k.account.value);
|
||||
boost::hash_combine(result, k.venue);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -137,6 +137,8 @@ template<class... Fs> class FIXFragment {
|
||||
sealed_crc + hole_crc};
|
||||
}
|
||||
|
||||
FIXFragment& operator=(const FIXFragment&src) = default;
|
||||
|
||||
private:
|
||||
uint64_t sealed_crc;
|
||||
uint64_t hole_crc;
|
||||
|
||||
@@ -54,6 +54,10 @@ Orchestrator::Orchestrator(md::MDConsumer &md,
|
||||
|
||||
void Orchestrator::create_actors(config::OrderManThreadingCfg const &cfg) {
|
||||
|
||||
ILimiter *limiter = nullptr;
|
||||
IRouter *router = nullptr;
|
||||
IClock *clock = nullptr;
|
||||
|
||||
for (auto const &t_cfg : cfg.thread()) {
|
||||
auto thread =
|
||||
get_thread(t_cfg.name(), t_cfg.poll(), t_cfg.slow_worker_period());
|
||||
@@ -66,7 +70,8 @@ void Orchestrator::create_actors(config::OrderManThreadingCfg const &cfg) {
|
||||
thread->add_actor<OrderManager>()});
|
||||
else if (actor_name == "gateway")
|
||||
me->gateways.push_back(thread->add_actor<Gateway>(
|
||||
get_venue_connection(actor_desc.arg(0))));
|
||||
get_venue_connection(actor_desc.arg(0)), *limiter, *router,*clock,
|
||||
GatewayCfg{}));
|
||||
else if (actor_name == "sorage") {
|
||||
bts_assert_msg(!me->storage,
|
||||
"Duplicate storage actor in OrderManThreadingCfg");
|
||||
@@ -195,7 +200,7 @@ void Orchestrator::wire_order_managers() {
|
||||
void Orchestrator::wire_gateways() {
|
||||
for (auto gw : me->gateways) {
|
||||
// GW_OrderUpdate
|
||||
gw->on_native_order_update.route_to(
|
||||
gw->on_order_report.route_to(
|
||||
[](auto const &o) { return o.target.value; },
|
||||
me->collect_om_fwds<&OrderManager::on_native_order_update>());
|
||||
|
||||
@@ -221,8 +226,8 @@ Thread *Orchestrator::get_thread(std::string const &name, bool poll,
|
||||
return thread.get();
|
||||
}
|
||||
|
||||
IVenueConnection &Orchestrator::get_venue_connection(std::string const &) {
|
||||
IVenueConnection *ptr = nullptr;
|
||||
IVenue &Orchestrator::get_venue_connection(std::string const &) {
|
||||
IVenue *ptr = nullptr;
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class OrderManThreadingCfg;
|
||||
namespace orderman_v2 {
|
||||
|
||||
class Thread;
|
||||
class IVenueConnection;
|
||||
class IVenue;
|
||||
|
||||
class Orchestrator {
|
||||
public:
|
||||
@@ -36,7 +36,7 @@ class Orchestrator {
|
||||
void wire_gateways();
|
||||
Thread *get_thread(std::string const &name, bool poll,
|
||||
uint32_t slow_worker_period);
|
||||
IVenueConnection &get_venue_connection(std::string const&jf_session);
|
||||
IVenue &get_venue_connection(std::string const&jf_session);
|
||||
};
|
||||
|
||||
} // namespace orderman_v2
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#include <benchmark/benchmark.h>
|
||||
|
||||
#include "lib/orderman_v2/fix/Fields.h"
|
||||
#include "lib/jetfix/codec/f_toa.h"
|
||||
#include "lib/jetfix/codec/i32_toa.h"
|
||||
#include "lib/orderman_v2/fix/Fields.h"
|
||||
|
||||
namespace bts {
|
||||
|
||||
namespace cmd {
|
||||
|
||||
|
||||
using namespace orderman_v2;
|
||||
|
||||
struct NumberEncoding {
|
||||
@@ -33,8 +32,8 @@ inline int my_u32_toa(uint32_t v, unsigned char *buffer, int pad) {
|
||||
memcpy(buffer, u32_encoding[v].number.data() + offset, pad);
|
||||
return u32_encoding[v].crc - (offset * '0');
|
||||
} else {
|
||||
u32_toa(v, (char*) buffer, pad);
|
||||
return sum_bytes((char*)buffer, pad);
|
||||
u32_toa(v, (char *)buffer, pad);
|
||||
return sum_bytes((char *)buffer, pad);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,14 +60,12 @@ static void new_order_single_hybrid(benchmark::State &state) {
|
||||
no.add_value<SenderCompID>("DE7534N");
|
||||
no.add_value<TargetCompID>("CME");
|
||||
no.add_value<TargetSubID>("80");
|
||||
no.add_value<SenderSubID>("DO3BTSJGR");
|
||||
no.add_value<SenderLocationID>("US,IL");
|
||||
|
||||
|
||||
no.add_value<Account>("CLX60635");
|
||||
no.add_value<CustomerOrFirm>("1");
|
||||
no.add_value<CtiCode>("1");
|
||||
no.add_value<SelfMatchPreventionID>("6935102");
|
||||
no.add_value<SenderSubID>("DO3BTSJGR");
|
||||
no.add_value<Account>("CLX60635");
|
||||
no.add_value<CtiCode>("1");
|
||||
no.add_value<CustomerOrFirm>("1");
|
||||
no.add_value<OrdType>("2");
|
||||
|
||||
auto transact_time = no.add_hole<TransactTime>();
|
||||
@@ -88,27 +85,69 @@ static void new_order_single_hybrid(benchmark::State &state) {
|
||||
|
||||
for (auto _ : state) {
|
||||
no.reopen_holes();
|
||||
no.fill_hole_inplace(body_length, 123,my_u32_toa);
|
||||
no.fill_hole_inplace(sn, 12,my_u32_toa);
|
||||
no.fill_hole_inplace(lsn,13,my_u32_toa);
|
||||
no.fill_hole(send_time, 0,"20190804-22:11:06.602");
|
||||
no.fill_hole(transact_time,0, "20190804-22:11:06.602");
|
||||
no.fill_hole_inplace(clorid, 100,my_u32_toa);
|
||||
no.fill_hole_inplace(body_length, 123, my_u32_toa);
|
||||
no.fill_hole_inplace(sn, 12, my_u32_toa);
|
||||
no.fill_hole_inplace(lsn, 13, my_u32_toa);
|
||||
no.fill_hole(send_time, 0, "20190804-22:11:06.602");
|
||||
no.fill_hole(transact_time, 0, "20190804-22:11:06.602");
|
||||
no.fill_hole_inplace(clorid, 100, my_u32_toa);
|
||||
no.fill_hole(side, "1");
|
||||
no.fill_hole(tif, "1");
|
||||
no.fill_hole(mno, "1");
|
||||
no.fill_hole_inplace(qty, 9,my_u32_toa);
|
||||
no.fill_hole_inplace(price,-93.0,[](auto v, auto buffer, auto sz) {
|
||||
d_toa(v,(char*)buffer,sz+1,9,sz);
|
||||
buffer[sz]=1;
|
||||
return sum_bytes((char*)buffer,sz);
|
||||
});
|
||||
no.fill_hole_inplace(qty, 9, my_u32_toa);
|
||||
no.fill_hole_inplace(price, -93.0, [](auto v, auto buffer, auto sz) {
|
||||
d_toa(v, (char *)buffer, sz + 1, 9, sz);
|
||||
buffer[sz] = 1;
|
||||
return sum_bytes((char *)buffer, sz);
|
||||
});
|
||||
no.fill_hole(sec_desc, "HOU9-HOX9");
|
||||
no.fill_hole_inplace(checksum,123,my_u32_toa);
|
||||
no.fill_hole_inplace(checksum, 123, my_u32_toa);
|
||||
}
|
||||
std::cout << no.encode().human_str() << "\n";
|
||||
}
|
||||
BENCHMARK(new_order_single_hybrid);
|
||||
|
||||
static void fragment_copy(benchmark::State &state) {
|
||||
NewOrderSingle no;
|
||||
using namespace fix;
|
||||
|
||||
no.add_value<BeginString>("FIX.4.2");
|
||||
no.add_hole<BodyLength>();
|
||||
no.add_value<MessageType>("D");
|
||||
no.add_hole<MsgSeqNum>();
|
||||
no.add_hole<LastMsgSeqNumProcessed>();
|
||||
no.add_hole<SendingTime>();
|
||||
|
||||
no.add_value<SenderCompID>("DE7534N");
|
||||
no.add_value<TargetCompID>("CME");
|
||||
no.add_value<TargetSubID>("80");
|
||||
no.add_value<SenderLocationID>("US,IL");
|
||||
no.add_value<SelfMatchPreventionID>("6935102");
|
||||
no.add_value<SenderSubID>("DO3BTSJGR");
|
||||
no.add_value<Account>("CLX60635");
|
||||
no.add_value<CtiCode>("1");
|
||||
no.add_value<CustomerOrFirm>("1");
|
||||
no.add_value<OrdType>("2");
|
||||
|
||||
no.add_hole<TransactTime>();
|
||||
no.add_hole<ClOrdID>(9);
|
||||
no.add_hole<fix::Side>();
|
||||
no.add_hole<fix::TimeInForce>();
|
||||
no.add_hole<fix::ManualOrderIndicator>();
|
||||
no.add_hole<OrderQty>();
|
||||
no.add_hole<fix::Price>(17);
|
||||
no.add_hole<SecurityDesc>(9);
|
||||
no.add_hole<Checksum>();
|
||||
|
||||
no.seal();
|
||||
|
||||
NewOrderSingle no2;
|
||||
for (auto _ : state) {
|
||||
benchmark::DoNotOptimize(no2 = no);
|
||||
}
|
||||
}
|
||||
BENCHMARK(fragment_copy);
|
||||
|
||||
// size_t create_order = 0;
|
||||
// size_t update_order = 0;
|
||||
// size_t cancel_order = 0;
|
||||
@@ -189,7 +228,8 @@ BENCHMARK(new_order_single_hybrid);
|
||||
// memcpy(buffer + p_index, "-0000093.00000000",
|
||||
// sizeof("-0000093.00000000") - 1);
|
||||
// benchmark::DoNotOptimize(
|
||||
// cb += sum_bytes(buffer + p_index, sizeof("-0000093.00000000") - 1));
|
||||
// cb += sum_bytes(buffer + p_index, sizeof("-0000093.00000000") -
|
||||
// 1));
|
||||
// }
|
||||
// }
|
||||
// BENCHMARK(new_order_single_raw_gen);
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
using namespace bts;
|
||||
|
||||
utils::init_spark_lib();
|
||||
BEGIN_CMD;
|
||||
REGISTER(Test);
|
||||
@@ -48,3 +47,5 @@ int main(int argc, char **argv) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -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/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/cssstyle/scripts/run_tests.sh;api/node_modules/exit/test/fixtures/create-files.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;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.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/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/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;ui/src/obj/Debug/netstandard2.0/ui.AssemblyInfo.fs)
|
||||
Reference in new issue
Block a user