Made some progress in GLBXiLink3ExecutionGateway

This commit is contained in:
Pedro Pinto committed 2020-06-02 09:16:02 -04:00
1 parent ff1a970982
commit 03404eb3f1
16 files changed
+696 -445

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/MarketDataService.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/subprocess.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/Product.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/service/MarketDataServiceServer.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;metricsLine 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/MarketDataService.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/subprocess.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/Product.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/service/MarketDataServiceServer.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;metricsLine truncated
+3 -3
View File
@@ -9,9 +9,9 @@ message JetFIX {
enum JetFIXPlatform {
GLBX = 1;
CBOE = 6;
SIM = 2;
ICE = 3;
SIMICE = 4;
SIM = 2;
ICE = 3;
SIMICE = 4;
}
optional JetFIXPlatform platform = 15 [default = GLBX];
+67 -68
View File
@@ -40,13 +40,13 @@ OutFIXPtr make_seq_reset(config::JetFIX::Connection const &session_cfg,
enum class Session::State {
WLOGON,
RECOVER,
WTR_REPLY,
READY,
TERMINATED,
WLOGOUT,
CERT_MODE
};
RECOVER,
WTR_REPLY,
READY,
TERMINATED,
WLOGOUT,
CERT_MODE
};
struct Session::RecoveryState {
RecoveryState() : buffered_msgs(), resend_request(0, 0) {}
@@ -59,14 +59,14 @@ struct Session::PImpl {
PImpl(config::JetFIX::Connection const &cfg, IConnection &connection,
IFIXStore &store, ICoreGatewayEventSink &sink, Clock const &clock,
trace::PerfLog &perf_log)
: cfg(cfg), state(State::TERMINATED), connection(connection),
store(store), event_sink(sink), now(clock), perf_log(perf_log),
begin_of_this_session(), last_seq_num(), last_seq_num_processed(),
last_sent_msg_timestamp(), last_sent_sync_timestamp(),
last_rcvd_msg_timestamp(), start_of_logon(), start_of_logout(),
current_time(std::make_shared<std::string>(
datetime::FIX_timestamp(datetime::now()))),
recovery_state() {}
: cfg(cfg), state(State::TERMINATED), connection(connection),
store(store), event_sink(sink), now(clock), perf_log(perf_log),
begin_of_this_session(), last_seq_num(), last_seq_num_processed(),
last_sent_msg_timestamp(), last_sent_sync_timestamp(),
last_rcvd_msg_timestamp(), start_of_logon(), start_of_logout(),
current_time(std::make_shared<std::string>(
datetime::FIX_timestamp(datetime::now()))),
recovery_state() {}
config::JetFIX::Connection cfg;
State state;
@@ -90,7 +90,7 @@ struct Session::PImpl {
Session::Session(config::JetFIX::Connection const &cfg, IConnection &connection,
IFIXStore &store, ICoreGatewayEventSink &sink,
Clock const &clock, trace::PerfLog &perf_log)
: me(new PImpl(cfg, connection, store, sink, clock, perf_log)) {}
: me(new PImpl(cfg, connection, store, sink, clock, perf_log)) {}
Session::~Session() {
if (me->state != State::TERMINATED)
@@ -248,16 +248,16 @@ void Session::on_logon(InMsgBuffer const &msg) {
} else {
if (their_last <= our_last_processed)
terminate_session(
JetFIXError::INCOMING_SN_TOO_SMALL,
(boost::format(
"Incoming sequence number was %d "
"but the last one we processed was %d. "
"Most likely the FIX sequencer numbers file "
"($SPARKDATA/data/jetfix/connection_name/current/seqnum) "
"was deleted. Update this file with the correct "
"incoming sequence number (second column)") %
their_last % our_last_processed)
.str());
JetFIXError::INCOMING_SN_TOO_SMALL,
(boost::format(
"Incoming sequence number was %d "
"but the last one we processed was %d. "
"Most likely the FIX sequencer numbers file "
"($SPARKDATA/data/jetfix/connection_name/current/seqnum) "
"was deleted. Update this file with the correct "
"incoming sequence number (second column)") %
their_last % our_last_processed)
.str());
else if (their_last == (our_last_processed + 1)) {
transition(State::WTR_REPLY);
@@ -329,9 +329,9 @@ void Session::on_test_request(InMsgBuffer const &msg) {
switch (me->state) {
case State::WLOGON:
terminate_session(
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (char)msg.type())
.str());
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (char)msg.type())
.str());
break;
case State::RECOVER:
internal_send(make_hb(me->cfg, msg.get_test_req_id()));
@@ -363,8 +363,8 @@ void Session::on_resend_request(InMsgBuffer const &msg) {
switch (me->state) {
case State::WLOGON:
terminate_session(
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
break;
case State::RECOVER:
case State::WTR_REPLY:
@@ -386,12 +386,12 @@ void Session::on_resend_request(InMsgBuffer const &msg) {
send_seq_reset(msg.get_begin_seq_no(), msg.get_end_seq_no());
else
logout(
JetFIXError::UNEXPECTED_RESEND_REQUEST,
(boost::format("Received resend request for messages "
"%d to %d but my initial sequence number is %d ") %
msg.get_begin_seq_no() % msg.get_end_seq_no() %
me->begin_of_this_session)
.str());
JetFIXError::UNEXPECTED_RESEND_REQUEST,
(boost::format("Received resend request for messages "
"%d to %d but my initial sequence number is %d ") %
msg.get_begin_seq_no() % msg.get_end_seq_no() %
me->begin_of_this_session)
.str());
break;
}
case State::WLOGOUT:
@@ -408,8 +408,8 @@ void Session::on_seq_reset(InMsgBuffer const &msg) {
switch (me->state) {
case State::WLOGON:
terminate_session(
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
break;
case State::RECOVER:
buffer_or_deliver(msg);
@@ -439,8 +439,8 @@ void Session::on_hb(InMsgBuffer const &msg) {
switch (me->state) {
case State::WLOGON:
terminate_session(
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
break;
case State::RECOVER:
buffer(msg);
@@ -471,8 +471,8 @@ void Session::on_app(InMsgBuffer const &msg) {
switch (me->state) {
case State::WLOGON:
terminate_session(
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
JetFIXError::EXPECTED_LOGON,
(boost::format("Received message type %c ") % (int)msg.type()).str());
break;
case State::RECOVER:
buffer_or_deliver(msg);
@@ -595,8 +595,8 @@ void Session::terminate_session(JetFIXError::Code reason) {
bool match_with_outgoing_sn_too_small(std::string const &msg, uint32_t *sn) {
std::string rx_str =
".*Sequence number received lower than expected. Expected "
"\\[(\\d+)\\] Received \\d+.*";
".*Sequence number received lower than expected. Expected "
"\\[(\\d+)\\] Received \\d+.*";
std::regex rx(rx_str);
std::smatch matches;
@@ -609,7 +609,7 @@ bool match_with_outgoing_sn_too_small(std::string const &msg, uint32_t *sn) {
bool match_with_incoming_sn_too_small(std::string const &msg, uint32_t *sn) {
std::string rx_str = ".*Incoming sequence number was (\\d+) "
"but the last one we processed was .*";
"but the last one we processed was .*";
std::regex rx(rx_str);
@@ -728,7 +728,7 @@ std::pair<uint32_t, uint32_t> Session::find_first_incoming_msg_gap() {
else
return std::make_pair(me->last_seq_num_processed + 1,
me->recovery_state->buffered_msgs.begin()->first -
1);
1);
}
bool Session::resend_request_active() {
@@ -783,22 +783,21 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
const char *application = "O2";
#endif
if(session_cfg.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_ICE ||
session_cfg.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE)
{
if (session_cfg.platform() ==
bts::config::JetFIX_Connection_JetFIXPlatform_ICE ||
session_cfg.platform() ==
bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE) {
buffer.add<ICEApplicationSystemName>(std::string_view{application});
buffer.add<ICEApplicationSystemVersion>(std::string_view{"1.0"});
buffer.add<ICEApplicationSystemVendor>(std::string_view{"BTS"});
buffer.add<UserName>(session_cfg.user_name());
buffer.add<ICEApplicationSystemVendor>(std::string_view{"BTS"});
buffer.add<UserName>(session_cfg.user_name());
buffer.add<RawDataLength>(session_cfg.raw_data().size());
buffer.add<RawData>(session_cfg.raw_data());
buffer.add<RawData>(session_cfg.raw_data());
buffer.add<EncryptMethod>(0);
buffer.add<ICEStrategyPreference>(1);
buffer.add<ICETimeStampPreference>(1);
}
else
{
} else {
buffer.add<ApplicationSystemName>(std::string_view{application});
buffer.add<ApplicationSystemVersion>(std::string_view{"1.0"});
buffer.add<ApplicationSystemVendor>(std::string_view{"BTS"});
@@ -808,7 +807,8 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
buffer.add<fix::TradingSessionID>(session_cfg.trading_session_id());
}
if (session_cfg.has_udf_support_indicator())
buffer.add<fix::UDFSupportIndicator>(session_cfg.udf_support_indicator());
buffer.add<fix::UDFSupportIndicator>(
session_cfg.udf_support_indicator());
if (session_cfg.use_cme_secure_logon()) {
bts_assert(session_cfg.sender_compid().size() >= 3);
@@ -819,25 +819,24 @@ OutFIXPtr make_logon(uint32_t seq_num, uint32_t last_seq_num_processed,
std::string last_seq_num_str(9, ' ');
i32_toa(last_seq_num_processed, &last_seq_num_str[0], 9);
auto ld = glbx::calculate_hmac(
session_id, seq_num_str, session_cfg.sender_compid(),
session_cfg.sender_subid(), time_str, session_cfg.target_subid(),
std::to_string(session_cfg.seconds_between_hbs()),
session_cfg.sender_locationid(), last_seq_num_str, application, "1.0",
"BTS");
session_id, seq_num_str, session_cfg.sender_compid(),
session_cfg.sender_subid(), time_str, session_cfg.target_subid(),
std::to_string(session_cfg.seconds_between_hbs()),
session_cfg.sender_locationid(), last_seq_num_str, application,
"1.0", "BTS");
#ifndef BTS_EDGE
LOG(Jetfix, Info, "Canonical string for secure logon: {}", ld.canonical);
LOG(Jetfix, Info, "Canonical string for secure logon: {}",
ld.canonical);
#endif
buffer.add<EncodedTextLen>(ld.access_key.size());
buffer.add<EncodedText>(ld.access_key);
buffer.add<EncryptedPasswordMethod>(std::string_view{"CME-1-SHA-256"});
buffer.add<EncryptedPasswordLen>(ld.signature.size());
buffer.add<EncryptedPassword>(ld.signature);
}
else
{
} else {
buffer.add<RawDataLength>(session_cfg.raw_data().size());
buffer.add<RawData>(session_cfg.raw_data());
if(session_cfg.user_name() != "")
if (session_cfg.user_name() != "")
buffer.add<UserName>(session_cfg.user_name());
}
}
+46
View File
@@ -135,6 +135,52 @@ std::string session_name (config::JetFIX::Connection const &session_cfg)
}
datetime::PTime session_ptime (datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end)
{
if (in_session (ref_date,time_of_day_start,time_of_day_end)) {
auto start_of_session = ref_date;
if (time_of_day_start > time_of_day_end &&
start_of_session.time_of_day () <= time_of_day_end)
start_of_session -= boost::gregorian::date_duration (1);
start_of_session.time_of_day() = {};
return start_of_session;
}
else
return {};
}
datetime::PTime session_ptime (datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end)
{
if (in_session (ref_date,weekday_start,time_of_day_start,weekday_end,time_of_day_end))
return session_ptime (closest_before (ref_date,weekday_start,time_of_day_start),
boost::posix_time::time_duration(0, 0, 0),
boost::posix_time::time_duration(0, 0, 1));
else
return {};
}
datetime::PTime session_ptime (config::JetFIX::Connection const &session_cfg) {
auto now = datetime::local_now ();
if (session_cfg.has_start_day ()) {
bts_assert (session_cfg.has_end_day ());
return session_ptime (now,
parse_weekday (session_cfg.start_day ()),
parse_time (session_cfg.start_time ()),
parse_weekday (session_cfg.end_day ()),
parse_time (session_cfg.end_time ()));
} else
return session_ptime (now,
parse_time (session_cfg.start_time ()),
parse_time (session_cfg.end_time ()));
}
}}
+42 -28
View File
@@ -1,9 +1,9 @@
#pragma once
#include "lib/config/protos/jetfix.pb.h"
#include "lib/utils/datetime.h"
#include <memory>
#include <string>
#include "lib/utils/datetime.h"
#include "lib/config/protos/jetfix.pb.h"
namespace boost {
namespace gregorian {
@@ -11,39 +11,53 @@ class greg_weekday;
}
namespace posix_time {
class time_duration;
}}
}
} // namespace boost
namespace bts {
namespace jetfix {
boost::gregorian::greg_weekday parse_weekday (std::string weekday_str);
bool parse_time (std::string const &time_str,boost::posix_time::time_duration *out);
boost::gregorian::greg_weekday parse_weekday(std::string weekday_str);
bool parse_time(std::string const &time_str,
boost::posix_time::time_duration *out);
datetime::PTime closest_before (datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday,
boost::posix_time::time_duration time_of_day);
datetime::PTime closest_before(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday,
boost::posix_time::time_duration time_of_day);
bool in_session (datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end);
bool in_session(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end);
bool in_session (datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end);
bool in_session(datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end);
std::string session_name (datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end);
// Human readable name for a session
std::string session_name(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end);
std::string session_name(datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end);
std::string session_name(config::JetFIX::Connection const &session_cfg);
std::string session_name (datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end);
// PTime of the start of a session. This will always be midnight of the day
// the session started regardless of the exact start time.
datetime::PTime
session_ptime(datetime::PTime const &ref_date,
boost::gregorian::greg_weekday weekday_start,
boost::posix_time::time_duration time_of_day_start,
boost::gregorian::greg_weekday weekday_end,
boost::posix_time::time_duration time_of_day_end);
datetime::PTime session_ptime(datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_start,
boost::posix_time::time_duration time_of_day_end);
datetime::PTime session_ptime(config::JetFIX::Connection const &session_cfg);
std::string session_name (config::JetFIX::Connection const &session_cfg);
}}
} // namespace jetfix
} // namespace bts
+245 -211
View File
@@ -6,279 +6,313 @@
#include "lib/jetfix/common/OutFIXPtr.h"
#include "lib/jetfix/store/FIXFileStore.h"
#include "lib/jetfix/store/session_name.h"
#include "lib/logging/logging.h"
#include "lib/utils/TempDir.h"
#include "lib/utils/TimeStamp.h"
#include "lib/utils/datetime.h"
#include "lib/logging/logging.h"
#include <boost/date_time.hpp>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/filesystem.hpp>
#include <boost/date_time.hpp>
namespace bts {
namespace jetfix {
TEST_CASE ("JetFIX SessionNameTests", "[jetfix]")
{
SECTION("greg_weekday_works")
{
const char*days [] = {"sun","Monday","tuesday","Wedn","Thursday","Friday","sat"};
TEST_CASE("JetFIX SessionNameTests", "[jetfix]") {
SECTION("greg_weekday_works") {
const char *days[] = {"sun", "Monday", "tuesday", "Wedn",
"Thursday", "Friday", "sat"};
int i =0;
int i = 0;
for (auto d : days)
REQUIRE (parse_weekday (d)==boost::gregorian::greg_weekday (i++));
}
SECTION("closest_before_works")
{
auto same_day_before = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Friday,
boost::posix_time::time_duration(16, 59, 59));
REQUIRE (datetime::FIX_date_time_string (same_day_before)=="20150717-16:59:59");
auto same_day_after = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Friday,
boost::posix_time::time_duration(17,0,1));
REQUIRE (datetime::FIX_date_time_string (same_day_after)=="20150710-17:00:01");
auto another_day_same_week = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Thursday,
boost::posix_time::time_duration(16, 59, 59));
REQUIRE (datetime::FIX_date_time_string (another_day_same_week)=="20150716-16:59:59");
auto another_day_previous_week = closest_before (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Saturday,
boost::posix_time::time_duration(16, 59, 59));
REQUIRE (datetime::FIX_date_time_string (another_day_previous_week)=="20150711-16:59:59");
REQUIRE(parse_weekday(d) == boost::gregorian::greg_weekday(i++));
}
SECTION("in_session_works")
{
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(17, 0, 1)));
SECTION("closest_before_works") {
auto same_day_before =
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Friday,
boost::posix_time::time_duration(16, 59, 59));
REQUIRE(datetime::FIX_date_time_string(same_day_before) ==
"20150717-16:59:59");
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(16, 59, 59)));
auto same_day_after = closest_before(
datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Friday, boost::posix_time::time_duration(17, 0, 1));
REQUIRE(datetime::FIX_date_time_string(same_day_after) ==
"20150710-17:00:01");
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)));
auto another_day_same_week =
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Thursday,
boost::posix_time::time_duration(16, 59, 59));
REQUIRE(datetime::FIX_date_time_string(another_day_same_week) ==
"20150716-16:59:59");
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::posix_time::time_duration(0,0,0),
boost::posix_time::time_duration(16, 0,0)));
REQUIRE (in_session (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)));
REQUIRE (!in_session (datetime::make_ptime (2015,7,17,17,47,0,0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)));
auto another_day_previous_week =
closest_before(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Saturday,
boost::posix_time::time_duration(16, 59, 59));
REQUIRE(datetime::FIX_date_time_string(another_day_previous_week) ==
"20150711-16:59:59");
}
SECTION("session_name_works")
{
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(17, 0, 1)) ==
"2015-07-12");
SECTION("in_session_works") {
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(17, 0, 1)));
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(16, 59, 59)) == "");
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)) ==
"2015-07-17");
boost::gregorian::Friday,
boost::posix_time::time_duration(16, 59, 59)));
REQUIRE (session_name (datetime::make_ptime (2015,7,17,18,0,0,0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)) ==
"");
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)));
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,0,0,0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
"2015-07-16");
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::posix_time::time_duration(0, 0, 0),
boost::posix_time::time_duration(16, 0, 0)));
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,51,0,0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
"2015-07-17");
REQUIRE (session_name (datetime::make_ptime (2015,7,17,17,47,0,0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
"");
REQUIRE(in_session(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)));
REQUIRE(!in_session(datetime::make_ptime(2015, 7, 17, 17, 47, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)));
}
SECTION("session_name_works") {
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(17, 0, 1)) ==
"2015-07-12");
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(16, 59, 59)) == "");
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)) ==
"2015-07-17");
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 18, 0, 0, 0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)) == "");
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
"2015-07-16");
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 51, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
"2015-07-17");
REQUIRE(session_name(datetime::make_ptime(2015, 7, 17, 17, 47, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) == "");
}
SECTION("session_ptime_works") {
REQUIRE(session_ptime(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(17, 0, 1)) ==
datetime::make_ptime(2015, 07, 12));
REQUIRE(session_ptime(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::gregorian::Sunday,
boost::posix_time::time_duration(16, 59, 59),
boost::gregorian::Friday,
boost::posix_time::time_duration(16, 59, 59)) ==
datetime::PTime{});
REQUIRE(session_ptime(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)) ==
datetime::make_ptime(2015, 07, 17));
REQUIRE(session_ptime(datetime::make_ptime(2015, 7, 17, 18, 0, 0, 0),
boost::posix_time::time_duration(16, 59, 59),
boost::posix_time::time_duration(17, 59, 59)) ==
datetime::PTime{});
REQUIRE(session_ptime(datetime::make_ptime(2015, 7, 17, 17, 0, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
datetime::make_ptime(2015, 07, 16));
REQUIRE(session_ptime(datetime::make_ptime(2015, 7, 17, 17, 51, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
datetime::make_ptime(2015, 07, 17));
REQUIRE(session_ptime(datetime::make_ptime(2015, 7, 17, 17, 47, 0, 0),
boost::posix_time::time_duration(17, 50, 59),
boost::posix_time::time_duration(17, 45, 59)) ==
datetime::PTime{});
}
}
TEST_CASE ("JetFIX FileStoreTests", "[jetfix]")
{
SECTION("empty_store_works")
{
TEST_CASE("JetFIX FileStoreTests", "[jetfix]") {
SECTION("empty_store_works") {
config::JetFIX::Connection c;
c.set_name ("test");
c.set_sender_compid ("CME");
c.set_sender_subid ("G");
c.set_target_compid ("1U7001N");
c.set_target_subid ("BLUESTREAM");
c.set_name("test");
c.set_sender_compid("CME");
c.set_sender_subid("G");
c.set_target_compid("1U7001N");
c.set_target_subid("BLUESTREAM");
c.set_start_time ("00:00:00");
c.set_end_time ("23:59:59");
c.set_start_time("00:00:00");
c.set_end_time("23:59:59");
utils::TempDir td;
FIXFileStore fs (c,td.name ());
REQUIRE (fs.session_active ());
REQUIRE (fs.replay ().size ()==0);
REQUIRE (fs.last_seq_num ()==0);
REQUIRE (fs.last_seq_num_processed ()==0);
FIXFileStore fs(c, td.name());
REQUIRE(fs.session_active());
REQUIRE(fs.replay().size() == 0);
REQUIRE(fs.last_seq_num() == 0);
REQUIRE(fs.last_seq_num_processed() == 0);
}
SECTION("in_msg_is_stored")
{
auto td = std::make_shared<utils::TempDir> ();
SECTION("in_msg_is_stored") {
auto td = std::make_shared<utils::TempDir>();
config::JetFIX::Connection c;
c.set_name ("test");
c.set_sender_compid ("CME");
c.set_sender_subid ("G");
c.set_target_compid ("1U7001N");
c.set_target_subid ("BLUESTREAM");
c.set_name("test");
c.set_sender_compid("CME");
c.set_sender_subid("G");
c.set_target_compid("1U7001N");
c.set_target_subid("BLUESTREAM");
c.set_start_time ("00:00:00");
c.set_end_time ("23:59:59");
c.set_start_time("00:00:00");
c.set_end_time("23:59:59");
FIXEncodingStream stream (c);
auto &buf = stream.new_msg (MessageTypes::Logon);
buf.add<fix::TargetLocationID> (std::string_view {"US,NC"});
buf.add<fix::EncryptMethod> (0);
FIXEncodingStream stream(c);
auto &buf = stream.new_msg(MessageTypes::Logon);
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
buf.add<fix::EncryptMethod>(0);
buf.add<fix::HeartBtInt>(30);
buf.add<fix::ApplicationSystemName> (std::string_view{"O2"});
buf.add<fix::ApplicationSystemVersion> (std::string_view {"1.0"});
buf.add<fix::ApplicationSystemVendor> (std::string_view {"BTS"});
stream.close ();
stream.stamp (2,3,datetime::FIX_timestamp (datetime::now ()));
auto fix = stream.to_str ();
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
stream.close();
stream.stamp(2, 3, datetime::FIX_timestamp(datetime::now()));
auto fix = stream.to_str();
{
FIXFileStore fs (c,td->name ());
fs.store (InMsgBuffer (fix));
fs.set_last_msg_processed (3);
FIXFileStore fs(c, td->name());
fs.store(InMsgBuffer(fix));
fs.set_last_msg_processed(3);
}
FIXFileStore fs (c,td->name ());
auto replay = fs.replay ();
REQUIRE (replay.size ()==1);
REQUIRE (replay[0].type ()==MessageTypes::Logon);
REQUIRE (replay[0].to_str ()==fix);
REQUIRE (fs.last_seq_num ()==0);
REQUIRE (fs.last_seq_num_processed ()==3);
FIXFileStore fs(c, td->name());
auto replay = fs.replay();
REQUIRE(replay.size() == 1);
REQUIRE(replay[0].type() == MessageTypes::Logon);
REQUIRE(replay[0].to_str() == fix);
REQUIRE(fs.last_seq_num() == 0);
REQUIRE(fs.last_seq_num_processed() == 3);
}
SECTION("out_msg_is_stored")
{
auto td = std::make_shared<utils::TempDir> ();
SECTION("out_msg_is_stored") {
auto td = std::make_shared<utils::TempDir>();
config::JetFIX::Connection c;
c.set_name ("test");
c.set_sender_compid ("CME");
c.set_sender_subid ("G");
c.set_target_compid ("1U7001N");
c.set_target_subid ("BLUESTREAM");
c.set_name("test");
c.set_sender_compid("CME");
c.set_sender_subid("G");
c.set_target_compid("1U7001N");
c.set_target_subid("BLUESTREAM");
c.set_start_time ("00:00:00");
c.set_end_time ("23:59:59");
c.set_start_time("00:00:00");
c.set_end_time("23:59:59");
auto msg_vec = std::make_shared<OutFIX>(c);
auto &stream = msg_vec->fix.back ();
auto &buf = stream.new_msg (MessageTypes::Logon);
buf.add<fix::TargetLocationID> (std::string_view{"US,NC"});
buf.add<fix::EncryptMethod> (0);
auto &stream = msg_vec->fix.back();
auto &buf = stream.new_msg(MessageTypes::Logon);
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
buf.add<fix::EncryptMethod>(0);
buf.add<fix::HeartBtInt>(30);
buf.add<fix::ApplicationSystemName> (std::string_view{"O2"});
buf.add<fix::ApplicationSystemVersion> (std::string_view{"1.0"});
buf.add<fix::ApplicationSystemVendor> (std::string_view{"BTS"});
stream.close ();
stream.stamp (2,3,datetime::FIX_timestamp (datetime::now ()));
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
stream.close();
stream.stamp(2, 3, datetime::FIX_timestamp(datetime::now()));
{
FIXFileStore fs (c,td->name ());
fs.store (msg_vec);
FIXFileStore fs(c, td->name());
fs.store(msg_vec);
}
FIXFileStore fs (c,td->name ());
auto replay = fs.replay ();
REQUIRE (replay.size ()==0);
REQUIRE (fs.last_seq_num ()==3);
REQUIRE (fs.last_seq_num_processed ()==0);
FIXFileStore fs(c, td->name());
auto replay = fs.replay();
REQUIRE(replay.size() == 0);
REQUIRE(fs.last_seq_num() == 3);
REQUIRE(fs.last_seq_num_processed() == 0);
}
SECTION("test_performance")
{
auto td = std::make_shared<utils::TempDir> ();
SECTION("test_performance") {
auto td = std::make_shared<utils::TempDir>();
config::JetFIX::Connection c;
c.set_name ("test");
c.set_sender_compid ("CME");
c.set_sender_subid ("G");
c.set_target_compid ("1U7001N");
c.set_target_subid ("BLUESTREAM");
c.set_name("test");
c.set_sender_compid("CME");
c.set_sender_subid("G");
c.set_target_compid("1U7001N");
c.set_target_subid("BLUESTREAM");
c.set_start_time ("00:00:00");
c.set_end_time ("23:59:59");
c.set_start_time("00:00:00");
c.set_end_time("23:59:59");
auto start = utils::TimeStamp::now ();
auto start = utils::TimeStamp::now();
{
FIXFileStore fs (c,td->name ());
for (int i = 0; i < 10000;i++) {
FIXFileStore fs(c, td->name());
for (int i = 0; i < 10000; i++) {
auto msg_vec = std::make_shared<std::vector<FIXEncodingStream>>();
msg_vec->emplace_back (c);
auto &stream = msg_vec->back ();
auto &buf = stream.new_msg (MessageTypes::Logon);
buf.add<fix::TargetLocationID> (std::string_view{"US,NC"});
buf.add<fix::EncryptMethod> (0);
msg_vec->emplace_back(c);
auto &stream = msg_vec->back();
auto &buf = stream.new_msg(MessageTypes::Logon);
buf.add<fix::TargetLocationID>(std::string_view{"US,NC"});
buf.add<fix::EncryptMethod>(0);
buf.add<fix::HeartBtInt>(30);
buf.add<fix::ApplicationSystemName> (std::string_view{"O2"});
buf.add<fix::ApplicationSystemVersion> (std::string_view{"1.0"});
buf.add<fix::ApplicationSystemVendor> (std::string_view{"BTS"});
stream.close ();
stream.stamp (i,3,datetime::FIX_timestamp (datetime::now () - boost::gregorian::days (1)));
fs.store (InMsgBuffer (stream.to_str ()));
buf.add<fix::ApplicationSystemName>(std::string_view{"O2"});
buf.add<fix::ApplicationSystemVersion>(std::string_view{"1.0"});
buf.add<fix::ApplicationSystemVendor>(std::string_view{"BTS"});
stream.close();
stream.stamp(i, 3,
datetime::FIX_timestamp(datetime::now() -
boost::gregorian::days(1)));
fs.store(InMsgBuffer(stream.to_str()));
}
}
auto stop = utils::TimeStamp::now ();
LOG(Testing,Info,"jetfix store gen: {} ms", (stop-start).milliseconds () );
start = utils::TimeStamp::now ();
FIXFileStore fs (c,td->name ());
stop = utils::TimeStamp::now ();
LOG(Testing,Info,"jetfix store load: {} ms", (stop-start).milliseconds () );
auto stop = utils::TimeStamp::now();
LOG(Testing, Info, "jetfix store gen: {} ms",
(stop - start).milliseconds());
start = utils::TimeStamp::now();
FIXFileStore fs(c, td->name());
stop = utils::TimeStamp::now();
LOG(Testing, Info, "jetfix store load: {} ms",
(stop - start).milliseconds());
}
}
}}
} // namespace jetfix
} // namespace bts
@@ -1,175 +1,266 @@
#include "lib/orderman/actors/GLBXiLink3ExecutionGateway.h"
#include "lib/config/config.h"
#include "lib/config/protos/orderman_cfg.pb.h"
#include "lib/domain_model/Security.h"
#include "lib/jetfix/common/OutFIX.h"
#include "lib/orderman/actors/GLBXExecutionGateway.h"
#include "lib/orderman/actors/ilink3/IL3Reactor.h"
#include "lib/orderman/actors/ilink3/ILinkGW.h"
#include "lib/orderman/actors/ilink3/SessionManager.h"
#include "lib/orderman/events/NewSecuritiesEvent.h"
#include "lib/orderman/orderman_utils/fix_order_codec.h"
namespace bts {
namespace orderman {
namespace ilink3 {
enum class GLBXiLink3ExecutionGateway::State {
WAITING_FOR_SECURITIES,
PAUSED,
CONNECTING,
READY
};
struct GLBXiLink3ExecutionGateway::PImpl {
PImpl(config::JetFIX::Connection const &cfg, trace::PerfLog &l,
PImpl(config::JetFIX::Connection const &cfg, trace::PerfLog &log,
md::SecurityOracle o)
: cfg(cfg), gw(cfg, l, o) {}
: state(), cfg(cfg), reactor(), start_of_pause(), on_exe_report(),
on_gw_status_change(), on_cancel_reject(), perf_log(log),
sec_oracle(o), securities(), securities_by_descriptor(),
gw_name(cfg.name()), session_manager(cfg.name()), gw(),
connection(nullptr), connection_failures(0) {
TCPEndpoint endpoint{cfg.socket_connect_host_ip(),
(ushort)cfg.socket_connect_port()};
connection = &reactor.register_connection({endpoint});
}
State state;
config::JetFIX::Connection const cfg;
GLBXExecutionGateway gw;
Reactor reactor;
TimeStamp start_of_pause;
OnExeReport on_exe_report;
OnGwStatusChange on_gw_status_change;
orderman::OnCancelReject on_cancel_reject;
trace::PerfLog &perf_log;
md::SecurityOracle sec_oracle;
std::unordered_map<SecurityKey::Value, api::Security const *> securities;
std::unordered_map<std::string, api::Security const *>
securities_by_descriptor;
GatewayName gw_name;
SessionManager session_manager;
std::optional<ILinkGW> gw;
IL3Connection *connection;
size_t connection_failures;
};
GLBXiLink3ExecutionGateway::GLBXiLink3ExecutionGateway(
config::JetFIX::Connection const &cfg, trace::PerfLog &log,
md::SecurityOracle o)
: me(new PImpl(cfg, log, o)) {}
: me(new PImpl(cfg, log, o)) {
me->state = State::WAITING_FOR_SECURITIES;
}
GLBXiLink3ExecutionGateway::~GLBXiLink3ExecutionGateway() {}
void GLBXiLink3ExecutionGateway::start() { me->gw.start(); }
void GLBXiLink3ExecutionGateway::start() {}
void GLBXiLink3ExecutionGateway::dispatch_incoming_fix_messages() {
me->gw.dispatch_incoming_fix_messages();
switch (me->state) {
case State::WAITING_FOR_SECURITIES:
break;
case State::PAUSED:
on_time();
break;
case State::READY:
case State::CONNECTING:
me->reactor.do_work();
me->gw->on_time();
break;
}
}
void GLBXiLink3ExecutionGateway::on_time() {
bts_assert(me->state == State::PAUSED);
// If we are still paused bail early, this avoids logging too much
// or spending too much CPU
if (pause_in_effect())
return;
me->start_of_pause = Timer::now();
// If we alread exceed the maximum number of failures per run
// bail. This is a safety measure to avoid overwhelming the
// exchange in the event of a bug or operational problem that
// results in repeated connection failures.
if (max_failures_reached()) {
LOG(OrderMan, Warn,
"Maximum number of connection failures reached for {}. Reboot to try "
"again",
me->gw_name.value());
return;
}
// At this point we are no longer in the pause window and we have
// not exceed our connection failure limit. Are we within the
// exchange's active session?
auto current_session = me->session_manager.get_current();
if (!current_session) {
LOG(OrderMan, Info, "Outside of session in ", me->gw_name.value());
return;
}
// Yep, the stars are all aligned, lets try to connect
connect(current_session);
}
void GLBXiLink3ExecutionGateway::connect(Session const &s) {
bts_assert(me->state == State::PAUSED);
transition(State::CONNECTING);
Config c;
me->gw.emplace(*me->connection, s, c);
me->gw->subscribe_cancel_reject(
[this](auto k, auto const &msg) { me->on_cancel_reject(k, msg); });
me->gw->subscribe_execution_reports(
[this](auto er) { me->on_exe_report(*er, {}); });
me->gw->subscribe_session(
[this](auto const &s) { me->session_manager.store_current(s); });
me->gw->subscribe_state([this](auto gw_state) {
LOG(OrderMan, Info,
"Internal gateway state change in {}. State is now {}",
me->gw_name.value(),
log::CharPtrWrapper{ilink3::state_string(gw_state)});
switch (me->state) {
case State::CONNECTING:
if (gw_state == ilink3::State::READY) {
transition(State::READY);
me->on_gw_status_change(true);
} else if (gw_state == ilink3::State::ERROR) {
me->connection_failures++;
pause();
}
break;
case State::READY:
if (gw_state == ilink3::State::ERROR) {
me->connection_failures++;
pause();
me->on_gw_status_change(false);
}
break;
default:
bts_assert(false);
break;
}
});
me->gw->connect();
}
void GLBXiLink3ExecutionGateway::pause() {
me->start_of_pause = Timer::now();
me->gw.reset();
transition(State::PAUSED);
}
bool GLBXiLink3ExecutionGateway::pause_in_effect() const {
return sec_diff(Timer::now(), me->start_of_pause) >=
me->cfg.seconds_to_pause();
}
bool GLBXiLink3ExecutionGateway::max_failures_reached() const {
return me->connection_failures > me->cfg.max_connection_attempts();
}
void GLBXiLink3ExecutionGateway::on_securities(
const mercury::Update<NewSecuritiesEvent> &ev) {
me->gw.on_securities(ev);
const mercury::Update<NewSecuritiesEvent> &update) {
if (update.events) {
for (auto const &ev : *(update.events)) {
auto sec_ptr = ev.security;
me->securities[sec_ptr->id()] = sec_ptr;
me->securities_by_descriptor[securities::descriptor(*sec_ptr)] =
sec_ptr;
}
if (me->state == State::WAITING_FOR_SECURITIES) {
LOG(OrderMan, Warn,
"Received first set of {} securities. Proceeding "
"with initialization of execution gateway {}",
update.events->size(), me->gw_name.value());
// got our security synopsis, ready to start the GW
transition(State::READY);
}
}
}
void GLBXiLink3ExecutionGateway::on_admin_data(
const mercury::Update<NewAdminDataEvent> &ev) {
me->gw.on_admin_data(ev);
}
static std::string
get_cust_order_handling_inst(api::orderman::RoutingRecord const &rr) {
if (rr.cust_order_handling_inst().size())
return rr.cust_order_handling_inst();
else
return config::get<config::OrdermanCfg>()
.fallback_cust_order_handling_inst();
}
template <class F, class MSG>
static void add_clorid(jetfix::FIXFragment &fix,MSG const&msg) {
std::string clordid(clordid_sz(), ' ');
encode_clorid(msg.key, SecurityKey(msg.security->id()), &clordid);
fix.add<F>(clordid);
}
template <class MSG>
static void encode_common_fields(jetfix::FIXFragment &fix, MSG const &msg) {
using namespace jetfix;
using namespace api::orderman;
auto &rr = *msg.routing_record;
fix.add<fix::SenderSubID>(msg.routing_record->operator_id());
fix.add<fix::SenderLocationID>(msg.routing_record->location());
fix.add<fix::Account>(rr.account());
fix.add<fix::Side>(msg.side);
fix.add<fix::ManualOrderIndicator>(msg.manual_order_indicator);
fix.add<fix::SecurityDesc>(msg.security->glbx().security_desc());
add_clorid<fix::ClOrdID>(fix,msg);
fix.add<fix::TransactTimeStr>(datetime::FIX_timestamp(datetime::now()));
}
static void encode_create_fields(jetfix::FIXFragment &fix,
CreateOrderMsg const &create_fields) {
using namespace jetfix;
using namespace api::orderman;
encode_common_fields(fix, create_fields);
auto &rr = *create_fields.routing_record;
fix.add<fix::CustomerOrFirm>(rr.customer_or_firm());
fix.add<fix::CtiCode>(rr.cti_code());
fix.add<fix::CustOrderHandlingInst>(get_cust_order_handling_inst(rr));
if (rr.smp_id().size()) {
fix.add<fix::SelfMatchPreventionID>(rr.smp_id());
if (rr.smp_instruction() !=
api::orderman::SELF_MATCH_PREVENTION_INSTRUCTION_UNDEFINED)
fix.add<fix::SelfMatchPreventionInstruction>(rr.smp_instruction());
}
fix.add<fix::OrderQty>(create_fields.quantity.value());
fix.add<fix::OrdType>(create_fields.order_type);
fix.add<fix::TimeInForce>(create_fields.time_in_force);
switch (create_fields.order_type) {
case NATIVE_ORDER_TYPE_MARKET:
break;
case NATIVE_ORDER_TYPE_LIMIT:
fix.add<fix::Price>(create_fields.price.value(), 8, -1);
break;
case NATIVE_ORDER_TYPE_STOP:
fix.add<fix::StopPx>(create_fields.stop_px.value(), 8, -1);
break;
case NATIVE_ORDER_TYPE_STOP_LIMIT:
fix.add<fix::Price>(create_fields.price.value(), 8, -1);
fix.add<fix::StopPx>(create_fields.stop_px.value(), 8, -1);
break;
default:
bts_assert(false);
break;
}
if (create_fields.display_quantity.value())
fix.add<fix::MaxShow>(create_fields.display_quantity.value());
}
const mercury::Update<NewAdminDataEvent> &) {}
void GLBXiLink3ExecutionGateway::send_msgs(std::vector<OrderMsg> const &msgs,
trace::CorID corid) {
using namespace jetfix;
auto fix = std::make_shared<jetfix::OutFIX>(me->cfg);
auto &stream = fix->first_stream();
trace::CorID) {
for (auto &m : msgs) {
// NewOrderSingle
auto create_ptr = std::get_if<CreateOrderMsg>(&m);
if (create_ptr) {
auto &create_fix = stream.new_msg(jetfix::MessageTypes::NewOrderSingle);
encode_create_fields(create_fix, *create_ptr);
break;
}
// CancelReplace
auto cancel_replace_ptr = std::get_if<CancelReplaceOrderMsg>(&m);
if (cancel_replace_ptr) {
auto &update_fix = stream.new_msg(jetfix::MessageTypes::CancelReplace);
auto create_ptr = &cancel_replace_ptr->create_fields;
encode_create_fields(update_fix, *create_ptr);
update_fix.add<fix::OrderIDu64>(
cancel_replace_ptr->exchange_order_id.value());
add_clorid<fix::OrigClOrdID>(update_fix,*create_ptr);
add_clorid<fix::CorrelationClOrdID>(update_fix,*create_ptr);
update_fix.add<fix::InFlightMitigation>(true);
break;
}
// Cancel
auto cancel_ptr = std::get_if<CancelOrderMsg>(&m);
if (cancel_ptr) {
auto &cancel_fix = stream.new_msg(jetfix::MessageTypes::Cancel);
encode_common_fields(cancel_fix, *cancel_ptr);
cancel_fix.add<fix::OrderIDu64>(cancel_ptr->exchange_order_id.value());
add_clorid<fix::OrigClOrdID>(cancel_fix,*cancel_ptr);
add_clorid<fix::CorrelationClOrdID>(cancel_fix,*cancel_ptr);
break;
if (me->state == State::READY) {
for (auto &m : msgs) {
// NewOrderSingle
auto create_ptr = std::get_if<CreateOrderMsg>(&m);
if (create_ptr) {
me->gw->send_order(*create_ptr);
break;
}
// CancelReplace
auto cancel_replace_ptr = std::get_if<CancelReplaceOrderMsg>(&m);
if (cancel_replace_ptr) {
me->gw->send_cancel_replace(*cancel_replace_ptr);
break;
}
// Cancel
auto cancel_ptr = std::get_if<CancelOrderMsg>(&m);
if (cancel_ptr) {
me->gw->send_cancel(*cancel_ptr);
break;
}
}
me->gw->flush();
}
stream.close();
me->gw.send_fix(fix, corid);
}
OnExeReport &GLBXiLink3ExecutionGateway::on_exe_report() {
return me->gw.on_exe_report();
return me->on_exe_report;
}
OnGwStatusChange &GLBXiLink3ExecutionGateway::on_gw_status_change() {
return me->gw.on_gw_status_change();
return me->on_gw_status_change;
}
OnCancelReject &GLBXiLink3ExecutionGateway::on_cancel_reject() {
return me->gw.on_cancel_reject();
orderman::OnCancelReject &GLBXiLink3ExecutionGateway::on_cancel_reject() {
return me->on_cancel_reject;
}
log::CharPtrWrapper GLBXiLink3ExecutionGateway::state_name(State st) {
switch (st) {
case State::WAITING_FOR_SECURITIES:
return {"WAITING_FOR_SECURITIES"};
case State::PAUSED:
return {"PAUSED"};
case State::CONNECTING:
return {"CONNECTING"};
case State::READY:
return {"READY"};
}
bts_assert(false);
return {""};
}
void GLBXiLink3ExecutionGateway::transition(State new_state) {
LOG(OrderMan, Info, "Transitioning from {} to {}", me->gw_name.value(),
state_name(me->state), state_name(new_state));
me->state = new_state;
}
} // namespace ilink3
} // namespace orderman
} // namespace bts
@@ -1,10 +1,13 @@
#pragma once
#include "IExecutionGateway.h"
#include "lib/logging/logging.h"
namespace bts {
namespace orderman {
namespace ilink3 {
struct Session;
class GLBXiLink3ExecutionGateway : public IExecutionGateway {
public:
@@ -22,10 +25,23 @@ class GLBXiLink3ExecutionGateway : public IExecutionGateway {
OnExeReport& on_exe_report() override;
OnGwStatusChange& on_gw_status_change() override;
OnCancelReject &on_cancel_reject() override;
private:
enum class State;
struct PImpl;
std::unique_ptr<PImpl> me;
// Time passing
void on_time();
bool pause_in_effect() const;
bool max_failures_reached()const;
static log::CharPtrWrapper state_name(State);
void transition(State);
void pause();
void connect(const Session&);
};
} // namespace orderman
} // namespace bts
}
@@ -18,7 +18,7 @@ ExecutionGatewayFactory::create_gateway(const config::JetFIX::Connection &conn,
conn.platform() == bts::config::JetFIX_Connection_JetFIXPlatform_SIMICE)
return std::make_unique<ICEExecutionGateway>(conn, pl, o);
else if (conn.use_ilink3())
return std::make_unique<GLBXiLink3ExecutionGateway>(conn, pl, o);
return std::make_unique<ilink3::GLBXiLink3ExecutionGateway>(conn, pl, o);
else
return std::make_unique<GLBXExecutionGateway>(conn, pl, o);
@@ -0,0 +1,10 @@
#include "IL3ConnectionHandler.h"
namespace bts {
namespace orderman {
namespace ilink3 {
IL3ConnectionHandler::~IL3ConnectionHandler() = default;
}}}
@@ -7,10 +7,11 @@ namespace orderman {
namespace ilink3 {
struct IL3ConnectionHandler {
virtual ~IL3ConnectionHandler() ;
virtual void on_connect_success() = 0;
virtual void on_disconnect() = 0;
// Send available data and length. Handler will return what it consumed
virtual size_t on_data(const std::string_view&) = 0;
};
}}}//namespace
}}}//namespace
+1 -1
View File
@@ -18,7 +18,7 @@ struct TCPEndpoint {
class Reactor {
struct PImpl;
struct Connection;
std::unique_ptr<PImpl> me;
public:
+2 -1
View File
@@ -54,10 +54,11 @@ enum class State {
READY,
ERROR
};
const char* state_string(State s);
typedef std::function<void(State)> OnStateChange;
typedef std::function<void(const ExecutionReport*)> OnExecutionReport;
typedef std::function<void(const Session& s)> OnSessionChange;
typedef std::function<void(OrderKey,std::string)> OnCancelReject;
typedef std::function<void(OrderKey,std::string const&)> OnCancelReject;
// Does not allow re-entrance
class ILinkGW : IL3ConnectionHandler {
@@ -0,0 +1,17 @@
#include "SessionManager.h"
#include "lib/orderman/actors/ilink3/ILinkGW.h"
namespace bts {
namespace orderman {
namespace ilink3 {
struct SessionManager::PImpl {} ;
SessionManager::SessionManager(std::string const&) : me (new PImpl()) {}
SessionManager::~SessionManager() = default;
Session SessionManager::get_current() const { return {};}
void SessionManager::store_current(Session const&) {}
}}}
@@ -0,0 +1,22 @@
#pragma once
#include <memory>
namespace bts {
namespace orderman {
namespace ilink3 {
struct Session;
class SessionManager {
public:
SessionManager(std::string const&) ;
~SessionManager() ;
Session get_current() const ;
void store_current(Session const&) ;
private:
struct PImpl;
std::unique_ptr<PImpl> me;
};
}}}