Added storage for sessions. Still missing parsing of exec reports.

This commit is contained in:
Pedro Pinto committed 2020-06-02 17:13:53 -04:00
1 parent 03404eb3f1
commit 968be6a99a
14 files changed
+243 -163

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
-48
View File
@@ -133,54 +133,6 @@ std::string session_name (config::JetFIX::Connection const &session_cfg)
parse_time (session_cfg.start_time ()),
parse_time (session_cfg.end_time ()));
}
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 ()));
}
}}
-13
View File
@@ -46,18 +46,5 @@ std::string session_name(datetime::PTime const &ref_date,
boost::posix_time::time_duration time_of_day_end);
std::string session_name(config::JetFIX::Connection const &session_cfg);
// 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);
} // namespace jetfix
} // namespace bts
-43
View File
@@ -128,49 +128,6 @@ TEST_CASE("JetFIX SessionNameTests", "[jetfix]") {
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]") {
@@ -6,9 +6,10 @@
#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/actors/ilink3/SessionStore.h"
#include "lib/orderman/events/NewSecuritiesEvent.h"
#include "lib/orderman/orderman_utils/fix_order_codec.h"
#include "lib/jetfix/store/session_name.h"
namespace bts {
namespace orderman {
@@ -28,7 +29,7 @@ struct GLBXiLink3ExecutionGateway::PImpl {
: 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(),
gw_name(cfg.name()), session_store(), gw(),
connection(nullptr), connection_failures(0) {
TCPEndpoint endpoint{cfg.socket_connect_host_ip(),
(ushort)cfg.socket_connect_port()};
@@ -49,7 +50,7 @@ struct GLBXiLink3ExecutionGateway::PImpl {
std::unordered_map<std::string, api::Security const *>
securities_by_descriptor;
GatewayName gw_name;
SessionManager session_manager;
std::optional<SessionStore> session_store;
std::optional<ILinkGW> gw;
IL3Connection *connection;
size_t connection_failures;
@@ -106,8 +107,8 @@ void GLBXiLink3ExecutionGateway::on_time() {
// 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) {
auto current_session = jetfix::session_name(me->cfg);
if (current_session.empty()) {
LOG(OrderMan, Info, "Outside of session in ", me->gw_name.value());
return;
}
@@ -115,20 +116,34 @@ void GLBXiLink3ExecutionGateway::on_time() {
connect(current_session);
}
void GLBXiLink3ExecutionGateway::connect(Session const &s) {
void GLBXiLink3ExecutionGateway::connect(std::string const&session_name) {
bts_assert(me->state == State::PAUSED);
transition(State::CONNECTING);
Config c;
me->gw.emplace(*me->connection, s, c);
c.cme_session = me->cfg.sender_compid().substr(0,3);
c.firm = me->cfg.sender_compid().substr(3);
c.failover_on_disconnect = false;
me->session_store.emplace(session_name, me->cfg);
me->gw.emplace(*me->connection, me->session_store->starting_session_descriptor(), c);
me->gw->subscribe_cancel_reject(
[this](auto k, auto const &msg) { me->on_cancel_reject(k, msg); });
[this](auto k, auto const &msg) {
bts_assert(me->state == State::READY);
me->on_cancel_reject(k, msg);
});
me->gw->subscribe_execution_reports(
[this](auto er) { me->on_exe_report(*er, {}); });
[this](auto er) {
bts_assert(me->state == State::READY);
me->on_exe_report(*er, {});
});
me->gw->subscribe_session(
[this](auto const &s) { me->session_manager.store_current(s); });
[this](auto const &s) {
bts_assert(me->state == State::READY);
me->session_store->async_update_session(s);
});
me->gw->subscribe_state([this](auto gw_state) {
LOG(OrderMan, Info,
@@ -39,7 +39,7 @@ private:
void transition(State);
void pause();
void connect(const Session&);
void connect(std::string const& session_nam);
};
} // namespace orderman
+2
View File
@@ -13,6 +13,7 @@
#include "generated/MessageHeader.h"
#include "IL3GeneratedFwd.h"
#include "IL3ExecutionReportParser.h"
#include "lib/orderman/actors/ilink3/RawMsg.h"
namespace bts {
namespace orderman {
@@ -42,6 +43,7 @@ struct Config {
std::string cme_session; // NGG
std::string firm; // 004
bool failover_on_disconnect;
std::function<void(RawMessageDirection, RawMsg const&)> raw_message_logger;
};
enum class State {
+11
View File
@@ -0,0 +1,11 @@
#pragma once
#include <functional>
#include <string>
namespace bts {
namespace orderman {
namespace ilink3 {
enum class RawMessageDirection {INCOMING, OUTGOING};
using RawMsg = std::function<std::string(void)>;
}}}
@@ -1,17 +0,0 @@
#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&) {}
}}}
@@ -1,22 +0,0 @@
#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;
};
}}}
@@ -0,0 +1,162 @@
#include "SessionStore.h"
#include "lib/orderman/actors/ilink3/ILinkGW.h"
#include "lib/orderman/orderman_utils/ExecutionReport.h"
#include "lib/utils/bts_chrono.h"
#include "lib/utils/file_utils.h"
#include "lib/utils/thread_manager.h"
#include <boost/filesystem.hpp>
#include <tbb/concurrent_queue.h>
#include <thread>
namespace bts {
namespace orderman {
namespace ilink3 {
using Action = std::function<void()>;
static std::string base_store_path(std::string base_path,
std::string const &connection_name,
std::string const &session_name) {
if (base_path.empty())
base_path = os::bts_data_path();
boost::filesystem::path result = utils::normalize_data_path(base_path);
result /= "link3";
result /= connection_name;
result /= session_name;
if (!boost::filesystem::exists(result))
bts_assert(boost::filesystem::create_directories(result));
return result.string();
}
static std::string raw_msg_log_path(std::string const &store_path) {
boost::filesystem::path result = store_path;
result /= "raw_msgs";
return result.string();
}
static std::string session_path(std::string const &store_path) {
boost::filesystem::path result = store_path;
result /= "session";
return result.string();
}
static std::vector<ExecutionReport> load_replay(
config::JetFIX::Connection const &cfg, std::string const &path) {
std::vector<ExecutionReport> result;
if (boost::filesystem::exists(path)) {
std::ifstream f(path);
std::string line_buffer;
line_buffer.reserve(10 * 1024);
std::string date_buffer("20150427-19:05:17.032");
for (;;) {
std::getline(f, line_buffer);
if (!f.eof()) {
if (line_buffer[22] == '<') {
auto ts =
datetime::parse_FIX_timestamp(line_buffer.substr(0, 21));
if (!datetime::is_at_least_secs_old(ts,
cfg.seconds_to_replay())) {
// figure out if its an execution report and if so
// load it
}
}
} else
break;
}
}
return result;
}
static void save_raw_msg(std::ofstream &out, RawMessageDirection d, std::string const&msg) {
out << datetime::FIX_timestamp(datetime::now()) << " "
<< (d == RawMessageDirection::OUTGOING? ">" : "<") << " ";
out.write(msg.data(), msg.size());
out << std::endl;
}
void save_session(std::string const &path, Session const &session) {
std::ofstream f(path);
f << session.uuid << session.to_cme << session.from_cme;
}
Session load_session(std::string const &path) {
auto result = Session::none();
if (boost::filesystem::exists(path)) {
Session result;
std::ifstream f(path);
f >> result.uuid >> result.to_cme >> result.from_cme;
}
return result;
}
struct SessionStore::PImpl {
PImpl(std::string const &session_name, config::JetFIX::Connection const &cfg,
std::string const &base_path)
: cfg(cfg),
store_path(base_store_path(base_path, cfg.name(), session_name)),
replay_messages(load_replay(cfg, raw_msg_log_path(store_path))),
starting_session_descriptor(load_session(session_path(store_path))),
raw_msg_store()
{
raw_msg_store.open(raw_msg_log_path(store_path), std::ofstream::app);
}
const config::JetFIX::Connection cfg;
const std::string store_path;
const std::vector<ExecutionReport> replay_messages;
const Session starting_session_descriptor;
std::atomic<bool> done = false;
tbb::concurrent_queue<Action> event_queue;
std::thread storage_thread;
std::ofstream raw_msg_store;
};
SessionStore::SessionStore(std::string const &session_name,
config::JetFIX::Connection const &cfg,
std::string base_path)
: me(new PImpl(session_name,cfg, base_path)) {
me->storage_thread = threading::make_thread_from_function(
"il3_store", [this]() { do_work(); });
}
std::vector<ExecutionReport> const &SessionStore::replay() const {
return me->replay_messages;
}
Session SessionStore::starting_session_descriptor() const {
return me->starting_session_descriptor;
}
void SessionStore::async_update_session(Session const&s) {
me->event_queue.push(Action {[this,s]() {
save_session(me->store_path,s);
}});
}
void SessionStore::async_store_raw_msg(RawMessageDirection d, RawMsg const&ms) {
me->event_queue.push(Action {[this,d,ms]() {
save_raw_msg(me->raw_msg_store,d,ms());
}});
}
void SessionStore::do_work() {
while (!me->done) {
Action a;
if (me->event_queue.try_pop(a))
a();
else
std::this_thread::sleep_for(100ms);
}
}
SessionStore::~SessionStore() {
me->done = true;
me->storage_thread.join();
}
} // namespace ilink3
} // namespace orderman
} // namespace bts
@@ -0,0 +1,33 @@
#pragma once
#include <memory>
#include <vector>
#include <functional>
#include "lib/config/protos/jetfix.pb.h"
#include "RawMsg.h"
namespace bts {
namespace orderman {
class ExecutionReport;
namespace ilink3 {
struct Session;
class SessionStore {
public:
SessionStore(std::string const&session_name,
config::JetFIX::Connection const&,
std::string base_path="");
~SessionStore() ;
Session starting_session_descriptor() const;
std::vector<ExecutionReport> const &replay() const;
void async_update_session(Session const&) ;
void async_store_raw_msg(RawMessageDirection, RawMsg const&);
private:
void do_work();
struct PImpl;
std::unique_ptr<PImpl> me;
};
}}}
@@ -221,7 +221,7 @@ TEST_CASE("EstablishExistingSession", "[ilink3]") {
Session session = Session::create();
// Set the exchange to know about our session
exchange.session = session.uuid;
Config config { Session::none(), "NGG", "004", false };
Config config { Session::none(), "NGG", "004", false , {}};
ILinkGW gw { connection, session, config };
gw.connect();
exchange.do_work();
@@ -257,7 +257,7 @@ TEST_CASE("BeginningOfWeekLogon", "[ilink3][cert]") {
auto& connection = exchange.connect();
// New session starts at 1
Session session = Session::none();
Config config { Session::none(), "NGG", "004", false };
Config config { Session::none(), "NGG", "004", false,{} };
ILinkGW gw { connection, session, config };
gw.subscribe_session([&](auto&s) { session = s; });
@@ -275,7 +275,7 @@ TEST_CASE("PrimaryGatewayConnectionEnforcement", "[ilink3][il3cert]") {
Session session = Session::create();
exchange.session = session.uuid;
exchange.config.reject_establish_on_primary = true;
Config config { Session::none(), "NGG", "004", true };
Config config { Session::none(), "NGG", "004", true, {} };
ILinkGW gw { connection, session, config };
gw.connect();
exchange.do_work();
@@ -300,7 +300,7 @@ TEST_CASE("Re-SettingUUID", "[ilink3][il3cert]") {
// Existing session starts >1. Will attempt to establish
{
Session session { 1234, /*out*/ 5, /*in*/ 17 };
Config config { Session::none(), "NGG", "004", false };
Config config { Session::none(), "NGG", "004", false, {} };
ILinkGW gw { connection, session, config };
gw.connect();
exchange.do_work();
@@ -309,7 +309,7 @@ TEST_CASE("Re-SettingUUID", "[ilink3][il3cert]") {
}
Session session = Session::none();
Config config { Session::none(), "NGG", "004", false };
Config config { Session::none(), "NGG", "004", false, {} };
ILinkGW gw { connection, session, config };
// send establish
gw.connect();
@@ -356,7 +356,7 @@ TEST_CASE("OutrightVanillaOrder", "[ilink3][execution]") {
auto& connection = exchange.connect();
// New session starts at 1
Session session = Session::none();
Config config { Session::none(), "NGG", "004", false };
Config config { Session::none(), "NGG", "004", false, {} };
ILinkGW gw { connection, session, config };
gw.subscribe_session([&](auto&s) { session = s; });
+2 -2
View File
@@ -196,7 +196,7 @@ int CMECert::execute(const std::vector<std::string>&) {
// Typically a timestamp
SessionSaver ss;
ss.load();
Config config { Session::none(), "NGG", "004", false };
Config config { Session::none(), "NGG", "004", false, {} };
Reactor reactor;
auto& connection = reactor.register_connection({
// local dev
@@ -300,4 +300,4 @@ std::string CMECert::help() {
//////////////////////////////////////////
// This code worked once
//////////////////////////////////////////
}}//namespace
}}//namespace