FIX Venue.

This commit is contained in:
Pedro Pinto committed 2019-12-20 08:33:57 -05:00
1 parent d82855aec2
commit 0a98fd7fed
16 files changed
+331 -217

No files matched your search

+1 -1
View File
@@ -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
+62 -26
View File
@@ -33,7 +33,8 @@ struct Gateway::OrderRec {
ICancelReplaceMsg *cancel_replace;
ICancelMsg *cancel;
OM_ID originator;
GW_Op_Ack last_ack;
void clear_msgs() {
cancel_replace = nullptr;
cancel = nullptr;
@@ -90,7 +91,7 @@ struct Gateway::Hot {
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() {}
current_exponential_backoff(0), bootstrap_orders(), interned_strings () {}
IRouter &router;
IClock &clock;
@@ -100,6 +101,7 @@ struct Gateway::Cold {
size_t current_exponential_backoff;
SessionSpan session_span;
std::map<OM_ID, std::vector<GW_OrderBind> *> bootstrap_orders;
std::set<std::string> interned_strings;
};
struct Gateway::PImpl {
@@ -139,7 +141,7 @@ void Gateway::do_slow_work() {
(me->cold.cfg.pause_seconds
<< me->cold.current_exponential_backoff)) {
transition(State::W_LOGON);
me->hot.venue.logon();
me->hot.venue.login();
}
break;
}
@@ -191,7 +193,7 @@ void Gateway::on_admin_data(AdminDataUpdate const &admin) {
}
}
void Gateway::on_venue_logon_success(std::vector<ExecReport> const &recovered) {
void Gateway::on_venue_login_success(std::vector<ExecReport> const &recovered) {
bts_assert(me->hot.state == State::W_LOGON);
me->cold.current_exponential_backoff = 0;
transition(State::READY);
@@ -199,7 +201,7 @@ void Gateway::on_venue_logon_success(std::vector<ExecReport> const &recovered) {
on_venue_exe_report(er);
}
void Gateway::on_venue_logon_failure() {
void Gateway::on_venue_login_failure() {
bts_assert(me->hot.state == State::W_LOGON);
if (in_active_schedule()) {
@@ -219,7 +221,7 @@ void Gateway::on_venue_disconnect() {
for (auto orec : all_working) {
GW_Error error;
error.gw = me->cold.cfg.my_id;
error.error = GW_Error::DISCONNECT;
error.error_code = GW_Error::DISCONNECT;
error.error_msg = "Venue disconnected";
error.order_key = orec->order.key;
on_gw_error(error);
@@ -231,17 +233,41 @@ void Gateway::on_venue_exe_report(const ExecReport &report) {
auto r = me->hot.working_orders.lookup(report.order_key);
if (r) {
GW_OrderReport report;
report.last_exe_report = report;
report.last_ack =
// This is an order we have seen before. This is the normal
// path.
r->order.last_exe_report = report;
// If the order is no longer working then we remove it from the
// working index.
if (report.status != OrderStatus::WORKING)
me->hot.working_orders.remove(report.order_key);
on_order_report(make_order_report(r));
} else if (report.status == OrderStatus::WORKING) {
auto sec = me->hot.venue.resolve_security(report);
if (sec)
on_unknown_native_order_update ( {sec,me->cold.cfg.my_id,report});
}
}
void Gateway::on_venue_error(VenueError const &) {}
void Gateway::on_venue_error(VenueError const &v_error) {
GW_Error gw_error;
switch (v_error.error_code) {
case VenueError::CANCEL_REJECT:
gw_error.error_code = GW_Error::CANCEL_REJECT;
break;
case VenueError::BUSINESS_REJECT:
gw_error.error_code = GW_Error::BUSINESS_REJECT;
break;
case VenueError::SESSION_REJECT:
gw_error.error_code = GW_Error::SESSION_REJECT;
break;
default:
gw_error.error_code = GW_Error::OTHER;
break;
}
gw_error.error_msg = intern_string(v_error.error_msg);
gw_error.order_key = v_error.order_key;
on_gw_error(gw_error);
}
void Gateway::on_gw_op(OM_ID om_id, const GW_OrderCreate &create) {
bts_assert_d(me->hot.working_orders.lookup(create.bound_order.key) ==
@@ -251,7 +277,8 @@ void Gateway::on_gw_op(OM_ID om_id, const GW_OrderCreate &create) {
auto gw_rec =
me->hot.working_orders.make_and_store(om_id, create.bound_order);
auto &order = gw_rec->order;
auto ack = make_ack(create);
auto &ack = gw_rec->last_ack;
ack = make_ack(create);
switch (me->hot.state) {
case State::READY: {
@@ -307,7 +334,7 @@ void Gateway::on_gw_op(OM_ID om_id, const GW_OrderCreate &create) {
// hear from the exchange on this order we have to send our ack
// now. This is an exceptional path, it should almost never happen.
bts_assert_d(ack.result != GW_OP_Result::OK);
auto report = make_ack_order_report(gw_rec, ack);
auto report = make_order_report(gw_rec);
me->hot.working_orders.remove(order.key);
on_order_report(report);
}
@@ -324,7 +351,8 @@ void Gateway::on_gw_op(OM_ID om_id, const GW_OrderBind &bind) {
// Construct new order record
auto gw_rec = me->hot.working_orders.make_and_store(om_id, bind.bound_order);
auto &order = gw_rec->order;
auto ack = make_ack(bind);
auto &ack = gw_rec->last_ack;
ack = make_ack(bind);
// Find the message templates for this UAV and clone them for this
// order
@@ -337,7 +365,7 @@ void Gateway::on_gw_op(OM_ID om_id, const GW_OrderBind &bind) {
// because there is no guarantee that we will be able to piggy back
// the reply on the next exchange acknowledgement (which may never
// come).
on_order_report(make_ack_order_report(gw_rec, ack));
on_order_report(make_order_report(gw_rec));
}
// A quick update is an update of just price and quantity. This is the
@@ -346,7 +374,8 @@ void Gateway::on_gw_op(OM_ID om_id, const GW_OrderBind &bind) {
// everything but quantity and price)
void Gateway::on_gw_op(OM_ID, const GW_OrderQuickUpdate &quick_update) {
auto gw_rec = me->hot.working_orders.lookup(quick_update.order_key);
auto ack = make_ack(quick_update);
auto &ack = gw_rec->last_ack;
ack = make_ack(quick_update);
switch (me->hot.state) {
case State::READY: {
@@ -399,7 +428,7 @@ void Gateway::on_gw_op(OM_ID, const GW_OrderQuickUpdate &quick_update) {
// this case we send out a new order report detailing the reasons
// for the failure.
bts_assert(ack.result != GW_OP_Result::OK);
on_order_report(make_ack_order_report(gw_rec, ack));
on_order_report(make_order_report(gw_rec));
}
// The difference between a full update and a quick update is that in
@@ -408,7 +437,8 @@ void Gateway::on_gw_op(OM_ID, const GW_OrderQuickUpdate &quick_update) {
// 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 = me->hot.working_orders.lookup(full_update.order_key);
auto ack = make_ack(full_update);
auto &ack = gw_rec->last_ack;
ack = make_ack(full_update);
switch (me->hot.state) {
case State::READY: {
@@ -464,12 +494,13 @@ void Gateway::on_gw_op(OM_ID om_id, const GW_OrderFullUpdate &full_update) {
// the order failed. This should be very rare. In this case we send
// a reply right away.
bts_assert(ack.result != GW_OP_Result::OK);
on_order_report(make_ack_order_report(gw_rec, ack));
on_order_report(make_order_report(gw_rec));
}
void Gateway::on_gw_op(OM_ID, const GW_OrderCancel &cancel) {
auto gw_rec = me->hot.working_orders.lookup(cancel.order_key);
auto ack = make_ack(cancel);
auto &ack = gw_rec->last_ack;
ack = make_ack(cancel);
switch (me->hot.state) {
case State::READY: {
@@ -505,14 +536,19 @@ void Gateway::on_gw_op(OM_ID, const GW_OrderCancel &cancel) {
// this case we send out a new order report detailing the reasons
// for the failure.
bts_assert(ack.result != GW_OP_Result::OK);
on_order_report(make_ack_order_report(gw_rec, ack));
on_order_report(make_order_report(gw_rec));
}
const char* Gateway::intern_string(std::string const&str) {
auto [it,_] = me->cold.interned_strings.insert(str);
return it->data();
}
void Gateway::send_pending_msgs() {
auto &pending = me->hot.pending_msgs;
// TODO: Need to make sure that there is no danger of reentrancy
// here, in the case that venue calls us back from the send call
me->hot.venue.send(*pending.data(), *(pending.data() + pending.size()));
me->hot.venue.send(pending.data(), (pending.data() + pending.size()));
pending.clear();
}
@@ -568,10 +604,10 @@ void Gateway::setup_bootstrap_orders() {
me->cold.bootstrap_orders.clear();
}
GW_OrderReport Gateway::make_ack_order_report(OrderRec *gw_rec, GW_Op_Ack ack) {
GW_OrderReport Gateway::make_order_report(OrderRec *gw_rec) {
GW_OrderReport report;
report.last_exe_report = gw_rec->order.last_exe_report;
report.last_ack = ack;
report.last_ack = gw_rec->last_ack;
report.target = gw_rec->originator;
return report;
}
+4 -4
View File
@@ -49,8 +49,8 @@ class Gateway : public Actor, ISlowWorker, IGW_Op_Visitor, IVenueObserver {
std::unique_ptr<PImpl> me;
// IVenueObserver
void on_venue_logon_success(std::vector<ExecReport> const&) override;
void on_venue_logon_failure() override;
void on_venue_login_success(std::vector<ExecReport> const&) override;
void on_venue_login_failure() override;
void on_venue_disconnect() override;
void on_venue_exe_report(const ExecReport &) override;
void on_venue_error(VenueError const&) override;
@@ -62,14 +62,14 @@ class Gateway : public Actor, ISlowWorker, IGW_Op_Visitor, IVenueObserver {
void on_gw_op(OM_ID, const GW_OrderCancel &) override;
void on_gw_op(OM_ID, const GW_OrderFullUpdate &) override;
const char* intern_string (std::string const&);
void send_pending_msgs();
bool has_bootstrap_data() const;
bool in_active_schedule() const;
void transition(State);
void rebuild_msg_templates();
void setup_bootstrap_orders();
GW_OrderReport make_ack_order_report(OrderRec *, GW_Op_Ack);
GW_OrderReport make_order_report(OrderRec *);
static log::CharPtrWrapper state_name(State);
};
+12 -3
View File
@@ -3,7 +3,10 @@
#include <boost/date_time/posix_time/posix_time.hpp>
namespace bts {
namespace api {namespace orderman { class RoutingRecord;}}
namespace api {
class Security;
namespace orderman { class RoutingRecord;}
}
namespace orderman_v2 {
@@ -12,6 +15,7 @@ class ICancelReplaceMsg;
class ICancelMsg;
class IVenueMsg;
class IVenueObserver;
class ExecReport;
struct MsgTemplates {
INewOrderSingleMsg* new_order;
@@ -36,7 +40,7 @@ class IVenue {
// Logon to the venue. This can only be called if the caller knows that the
// venue is in the idle state.
virtual void logon() = 0;
virtual void login() = 0;
// Build new order, cancel replace and cancel messages appropriate
// for this venue and using the information in the passed routing
@@ -50,7 +54,12 @@ class IVenue {
// Send the passed messages to the venue. It is only legal to call
// this if the venue is idle or ready.
virtual void send(IVenueMsg*begin, IVenueMsg*end) = 0;
virtual void send(IVenueMsg**begin, IVenueMsg**end) = 0;
// Resolved the security in the execution report. This is only
// needed for disaster recovery. Null should be returned in case of
// failure.
virtual api::Security const * resolve_security (ExecReport const&) = 0;
};
}}
@@ -5,23 +5,24 @@ namespace orderman_v2 {
class ExecReport;
struct VenueError {
enum Code { CANCEL_REJECT, BUSINESS_REJECT, SESSION_REJECT, OTHER };
Code error_code;
std::string error_msg;
// null_order_key() if not applicable
OrderKey order_key;
};
class IVenueObserver {
public:
struct VenueError {
enum Code { CANCEL_REJECT, BUSINESS_REJECT, SESSION_REJECT, OTHER };
Code error_code;
std::string error_msg;
std::optional<OrderKey> order_key;
};
// We logged on successfully and recovered the execution reports
// passed (this should be empty unless fills occurred while we were
// logged out)
virtual void on_venue_logon_success(std::vector<ExecReport> const &) = 0;
virtual void on_venue_login_success(std::vector<ExecReport> const &) = 0;
// We failed to login, either because we could not connect to the
// venue or because our credentials were invalid
virtual void on_venue_logon_failure() = 0;
virtual void on_venue_login_failure() = 0;
// We were disconnected from the venue
virtual void on_venue_disconnect() = 0;
@@ -0,0 +1 @@
#include "lib/orderman_v2/actors/gateway/fix/FIXVenueCtx.h"
@@ -0,0 +1,36 @@
#pragma once
#include "lib/config/protos/jetfix.pb.h"
#include "lib/jetfix/codec/FIXEncodingStream.h"
#include "lib/orderman/governor/Governor.h"
#include "VenueCheckPoint.h"
namespace bts {
namespace orderman_v2 {
class IFIXStore {};
class IClock;
class IConnectionController;
class IVenueObserver;
class FIXVenueCtx {
public:
FIXVenueCtx(config::JetFIX::Connection const &cfg,
VenueCheckPoint const &last_processed_msg, IClock &clock,
IFIXStore &store)
: controller(), venue_observer(), store(store), clock(clock),
out_buffer(cfg, 1), cfg(cfg), last_processed_msg(last_processed_msg) {}
IConnectionController *controller;
IVenueObserver *venue_observer;
IFIXStore &store;
IClock &clock;
jetfix::FIXEncodingStream out_buffer;
orderman::Governor governor;
config::JetFIX::Connection cfg;
VenueCheckPoint last_processed_msg;
}; // namespace orderman_v2
} // namespace orderman_v2
} // namespace bts
@@ -0,0 +1,12 @@
#pragma once
namespace bts {
namespace orderman_v2 {
class VenueCheckPoint {
public:
std::string session;
uint32_t last_processed_seq_number;
};
}}
@@ -0,0 +1,16 @@
#include "FIXVenueIdle.h"
#include "FIXVenueCtx.h"
namespace bts {
namespace orderman_v2 {
FIXVenueIdle::PImpl (FIXVenueCtx &,FIXVenueWConnect &) {
FIXVenueCtx &ctx;
FIX
};
FIXVenueIdle::FIXVenueIdle() : me (new PImpl()) {}
}}
@@ -0,0 +1,15 @@
#include "FIXVenueIdle.h"
#include "FIXVenueCtx.h"
namespace bts {
namespace orderman_v2 {
FIXVenueIdle::PImpl (FIXVenueCtx &,FIXVenueWConnect &) {
FIXVenueCtx &ctx;
l
};
FIXVenueIdle::FIXVenueIdle() : me (new PImpl()) {}
}}
@@ -0,0 +1,24 @@
#pragma once
#include "IFIXVenueState.h"
namespace bts {
namespace orderman_v2 {
class WConnect;
class FIXVenueCtx;
class FIXVenueIdle : public IFIXVenueState {
public:
void init(FIXVenueCtx &,WConnect&);
void send(IVenueMsg **, IVenueMsg**) override {};
const char*name() override {return "FIXVenueIdle";}
void enter() override;
void login() override;
private:
struct PImpl;
std::unique_ptr<PImpl> me;
};
}}
@@ -0,0 +1,23 @@
#pragma once
#include <string_view>
#include "lib/utils/bts_assert.h"
namespace bts {
namespace jetfix {class InMsgBuffer;}
namespace orderman_v2 {
class IVenueMsg;
class IFIXVenueState {
public:
virtual void enter() = 0;
virtual void login() {bts_assert(false);}
virtual void send(IVenueMsg **, IVenueMsg**) {bts_assert(false);}
virtual void on_connect_success() {bts_assert(false);}
virtual void on_connect_fail() {bts_assert(false);}
virtual void on_disconnect() {bts_assert(false);}
virtual void on_msg(jetfix::InMsgBuffer const&) {bts_assert(false);}
virtual const char* name() = 0;
};
}}
+5 -4
View File
@@ -56,7 +56,7 @@ struct SecurityStatusUpdate {
static_assert(meets_event_constraints<SecurityStatusUpdate>());
struct PositionUpdate {
api::Security *const security;
api::Security const * security;
AccountID account_id;
Quantity long_quantity;
Quantity short_quantity;
@@ -273,10 +273,11 @@ struct GW_Error {
GW_ID gw;
enum uint8_t {
CANCEL_REJECT,
BUSSINESS_REJECT,
BUSINESS_REJECT,
SESSION_REJECT,
DISCONNECT
} error;
DISCONNECT,
OTHER
} error_code;
const char *error_msg;
OrderKey order_key;
};
+96 -154
View File
@@ -1,175 +1,117 @@
#include "lib/orderman_v2/fix/FIXVenue.h"
#include "lib/jetfix/common/OutFIX.h"
#include "lib/jetfix/store/session_name.h"
#include "lib/orderman/governor/Governor.h"
#include "lib/orderman_v2/actors/gateway/IVenueMsg.h"
#include "lib/orderman_v2/actors/network/IConnectionController.h"
#include "lib/orderman_v2/common.h"
#include "lib/utils/bts_assert.h"
// #include "lib/orderman_v2/fix/FIXVenue.h"
// #include "lib/jetfix/common/OutFIX.h"
// #include "lib/jetfix/store/session_name.h"
// #include "lib/orderman/governor/Governor.h"
// #include "lib/orderman_v2/actors/gateway/IVenueMsg.h"
// #include "lib/orderman_v2/actors/network/IConnectionController.h"
// #include "lib/orderman_v2/common.h"
// #include "lib/utils/bts_assert.h"
#include <map>
// #include <map>
namespace bts {
namespace orderman_v2 {
// namespace bts {
// namespace orderman_v2 {
class FIXVenueConfig {};
// class FIXVenueConfig {};
enum class FIXVenue::State {
IDLE,
W_CONNECT,
W_LOGON,
WTR_REPLY,
READY,
W_DISCONNECT,
RECOVER
};
// struct InMsg {
// std::string_view data;
// };
enum class FIXVenue::ConnectionState {
IDLE,
W_CONNECT,
READY,
};
// struct VenueCheckPoint {
// std::string session;
// uint32_t sequence_number;
// };
struct InMsg {
std::string_view data;
};
// class IFIXStore {
// public:
// };
struct VenueCheckPoint {
std::string session;
uint32_t sequence_number;
};
// struct FIXVenue::PImpl {
class IFIXStore {
public:
};
// PImpl(config::JetFIX::Connection const &cfg,
// VenueCheckPoint const &last_processed_msg, IClock &clock,
// IFIXStore &store)
// : controller(), venue_observer(), store(store), clock(clock),
// out_buffer(cfg, 1), cfg(cfg),
// last_processed_msg(last_processed_msg) {}
// IConnectionController *controller;
// IVenueObserver *venue_observer;
// IFIXStore &store;
// IClock &clock;
// TimeStamp now;
// jetfix::FIXEncodingStream out_buffer;
// orderman::Governor governor;
// config::JetFIX::Connection cfg;
// VenueCheckPoint last_processed_msg;
// };
struct FIXVenue::RecoveryState {
std::map<uint32_t, InMsg> buffered_msgs;
std::pair<uint32_t, uint32_t> resend_request;
};
// FIXVenue::FIXVenue(config::JetFIX::Connection const &cfg,
// VenueCheckPoint const &check_point, IClock &clock,
// IFIXStore &store)
// : me(new PImpl(cfg, check_point, clock, store)) {}
struct FIXVenue::PImpl {
// void FIXVenue::set_observer(IVenueObserver &obs) {
// bts_assert(!me->venue_observer);
// me->venue_observer = &obs;
// }
PImpl(config::JetFIX::Connection const &cfg,
VenueCheckPoint const &last_processed_msg, IClock &clock,
IFIXStore &store)
: controller(), venue_observer(), store(store), state(State::IDLE),
connection_state(ConnectionState::IDLE), clock(clock),
out_buffer(cfg, 1), recovery(), cfg(cfg),
last_processed_msg(last_processed_msg) {}
IConnectionController *controller;
IVenueObserver *venue_observer;
IFIXStore &store;
State state;
ConnectionState connection_state;
IClock &clock;
TimeStamp now;
jetfix::FIXEncodingStream out_buffer;
orderman::Governor governor;
RecoveryState recovery;
config::JetFIX::Connection cfg;
VenueCheckPoint last_processed_msg;
};
// SessionSpan FIXVenue::get_current_session_span() {
// jetfix::SessionSpan ss = jetfix::session_span(me->cfg);
// return {ss.start, ss.stop};
// }
FIXVenue::FIXVenue(config::JetFIX::Connection const &cfg,
VenueCheckPoint const &check_point, IClock &clock,
IFIXStore &store)
: me(new PImpl(cfg, check_point, clock, store)) {}
// void FIXVenue::login() {
// bts_assert(is_initialized());
void FIXVenue::set_observer(IVenueObserver &obs) {
bts_assert(!me->venue_observer);
me->venue_observer = &obs;
}
// }
SessionSpan FIXVenue::get_current_session_span() {
jetfix::SessionSpan ss = jetfix::session_span(me->cfg);
return {ss.start, ss.stop};
}
// void FIXVenue::send(IVenueMsg **begin, IVenueMsg **end) {
// me->now = me->clock.now();
// for (auto msg = begin; msg != end; msg++)
// (*msg)->dispatch();
// internal_send();
// }
void FIXVenue::login() {
bts_assert(is_initialized());
switch (me->state) {
case State::IDLE:
transition(State::W_CONNECT);
me->controller->connect();
break;
case State::W_CONNECT:
case State::W_LOGON:
case State::WTR_REPLY:
case State::READY:
case State::RECOVER:
bts_assert(false);
break;
}
}
// void FIXVenue::init_handler(IConnectionController &ctrl) {
// bts_assert(!me->controller);
// me->controller = &ctrl;
// }
void FIXVenue::logout() {
bts_assert(is_initialized());
switch (me->state) {
case State::IDLE:
bts_assert(false);
break;
case State::W_LOGON:
case State::WTR_REPLY:
case State::READY:
case State::RECOVER:
prepare_logout(&me->out_buffer);
internal_send();
transition(State::IDLE);
me->controller->disconnect();
case State::W_CONNECT:
transition(State::IDLE);
me->controller->disconnect();
break;
}
}
// void FIXVenue::on_connect_success() {
// switch (me->state) {
// case State::IDLE:
// prepare_logon(&me->out_buffer);
// transition(State::W_LOGON);
// internal_send();
// break;
// case State::W_LOGON:
// case State::WTR_REPLY:
// case State::READY:
// case State::RECOVER:
// case State::W_CONNECT:
// bts_assert(false);
// break;
// }
// }
void FIXVenue::send(IVenueMsg **begin, IVenueMsg **end) {
me->now = me->clock.now();
for (auto msg = begin; msg != end; msg++)
(*msg)->dispatch();
internal_send();
}
// void FIXVenue::dispatch_new_order(jetfix::FIXFragment const &fix) {
// me->governor.record_sent(me->now);
// me->out_buffer.new_msg(jetfix::MessageTypes::NewOrderSingle).append(fix);
// }
void FIXVenue::init_handler(IConnectionController &ctrl) {
bts_assert(!me->controller);
me->controller = &ctrl;
}
// void FIXVenue::dispatch_cancel_replace(jetfix::FIXFragment const &fix) {
// me->governor.record_sent(me->now);
// me->out_buffer.new_msg(jetfix::MessageTypes::CancelReplace).append(fix);
// }
void FIXVenue::on_connect_success() {
switch (me->state) {
case State::IDLE:
prepare_logon(&me->out_buffer);
transition(State::W_LOGON);
internal_send();
break;
case State::W_LOGON:
case State::WTR_REPLY:
case State::READY:
case State::RECOVER:
case State::W_CONNECT:
bts_assert(false);
break;
}
}
// void FIXVenue::dispatch_cancel(jetfix::FIXFragment const &fix) {
// me->out_buffer.new_msg(jetfix::MessageTypes::Cancel).append(fix);
// }
void FIXVenue::dispatch_new_order(jetfix::FIXFragment const &fix) {
me->governor.record_sent(me->now);
me->out_buffer.new_msg(jetfix::MessageTypes::NewOrderSingle).append(fix);
}
// bool FIXVenue::is_initialized() const {
// return me->controller && me->venue_observer;
// }
void FIXVenue::dispatch_cancel_replace(jetfix::FIXFragment const &fix) {
me->governor.record_sent(me->now);
me->out_buffer.new_msg(jetfix::MessageTypes::CancelReplace).append(fix);
}
void FIXVenue::dispatch_cancel(jetfix::FIXFragment const &fix) {
me->out_buffer.new_msg(jetfix::MessageTypes::Cancel).append(fix);
}
bool FIXVenue::is_initialized() const {
return me->controller && me->venue_observer;
}
} // namespace orderman_v2
} // namespace bts
// } // namespace orderman_v2
// } // namespace bts
+13 -15
View File
@@ -1,11 +1,14 @@
#pragma once
#include "lib/config/protos/jetfix.pb.h"
#include "lib/orderman_v2/actors/gateway/IVenue.h"
#include "lib/orderman_v2/actors/network/IConnectionHandler.h"
#include "lib/config/protos/jetfix.pb.h"
namespace bts {
namespace jetfix {class FIXEncodingStream; class FIXFragment;}
namespace jetfix {
class FIXEncodingStream;
class FIXFragment;
} // namespace jetfix
namespace orderman_v2 {
@@ -16,30 +19,29 @@ struct VenueCheckPoint;
class FIXVenue : public IVenue, public IConnectionHandler {
public:
FIXVenue(config::JetFIX::Connection const &cfg,
VenueCheckPoint const &,
IClock &,
IFIXStore &);
FIXVenue(config::JetFIX::Connection const &cfg, VenueCheckPoint const &,
IClock &, IFIXStore &);
// IVenue
void set_observer(IVenueObserver &) override;
SessionSpan get_current_session_span() override;
void login() override;
void logout() override;
MsgTemplates
get_msg_templates(api::orderman::RoutingRecord const &) override;
void login() override;
void send(IVenueMsg **begin, IVenueMsg **end) override;
// IConnectionHandler
// IConnectionHandler
void init_handler(IConnectionController &) override;
void on_connect_success() override;
void on_connect_fail() override;
void on_disconnect() override;
void on_data(std::string_view const &data) override;
protected:
protected:
virtual void prepare_logon(jetfix::FIXEncodingStream *out) = 0;
private:
friend class FIXNewOrderSingle;
friend class FIXCancelReplace;
@@ -48,16 +50,12 @@ protected:
void dispatch_cancel_replace(jetfix::FIXFragment const &fix);
void dispatch_cancel(jetfix::FIXFragment const &fix);
enum class State;
enum class ConnectionState;
struct RecoveryState;
struct PImpl;
std::unique_ptr<PImpl> me;
bool is_initialized() const;
void prepare_logout(jetfix::FIXEncodingStream *out);
void internal_send();
void transition(State);
};
} // namespace orderman_v2
+1 -1
View File
@@ -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/psl/scripts/ci-build.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)