From e652435890ce3f5ae99cacbb11b68eb4df1d6281 Mon Sep 17 00:00:00 2001 From: Eric Harding Date: Fri, 9 Mar 2018 17:15:31 -0500 Subject: [PATCH] Spark-608 - get the simulator to send markets down to the shell. --- src/lib/config/defaults/MarketData.conf | 5 ++++ src/lib/config/protos/MarketData.proto | 7 +++++ src/lib/md/MDProducer.cpp | 6 ++++ src/lib/md/MDProducer.h | 3 ++ src/lib/md/PlatformLoader.cpp | 28 ++++--------------- src/lib/md/test/md2_tests.cpp | 21 ++++++++------ .../exchange_sim/ExchangeSimApplication.cpp | 7 +++-- .../exchange_sim/ExchangeSimApplication.h | 2 ++ 8 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/lib/config/defaults/MarketData.conf b/src/lib/config/defaults/MarketData.conf index 20e763a46..18e5ede53 100644 --- a/src/lib/config/defaults/MarketData.conf +++ b/src/lib/config/defaults/MarketData.conf @@ -7,6 +7,11 @@ MarketDataConfig { use_replay: true } } +PlatformMap { + value { + glbx_platform: "PLATFORM_MDP3ONIXS" + } +} PublisherNamespace { value { diff --git a/src/lib/config/protos/MarketData.proto b/src/lib/config/protos/MarketData.proto index 57045b5cb..ae5f2ae5b 100755 --- a/src/lib/config/protos/MarketData.proto +++ b/src/lib/config/protos/MarketData.proto @@ -5,6 +5,13 @@ message MarketDataConfig { optional bool use_replay = 1 [default=true]; } +message PlatformMap +{ + // PLATFORM_MDP3ONIXS + optional string glbx_platform = 1 [default = "PLATFORM_SIM"]; +} + + // // Options that apply to market data server // diff --git a/src/lib/md/MDProducer.cpp b/src/lib/md/MDProducer.cpp index 4d4122d5b..b3a92770b 100644 --- a/src/lib/md/MDProducer.cpp +++ b/src/lib/md/MDProducer.cpp @@ -154,6 +154,12 @@ MDProducerChannel MDProducer::get_channel(const char* symbol, SecurityType type, return MDProducerChannel(get_producer(symbol, type, exchange)); } +void MDProducer::heartbeat() { + for (auto& impl : _producers) { + impl->heartbeat(); + } +} + // // MDProducerChannel // diff --git a/src/lib/md/MDProducer.h b/src/lib/md/MDProducer.h index 8720d8df1..4123b59e6 100644 --- a/src/lib/md/MDProducer.h +++ b/src/lib/md/MDProducer.h @@ -31,6 +31,9 @@ public: // A Producer Channel holds data shared between the MDProducerChannel get_channel(const char* symbol, SecurityType type, Venue exchange); + // Heartbeat all channels + void heartbeat(); + private: BTS_NO_COPY(MDProducer); diff --git a/src/lib/md/PlatformLoader.cpp b/src/lib/md/PlatformLoader.cpp index 01b0df527..8c0dd5cc1 100644 --- a/src/lib/md/PlatformLoader.cpp +++ b/src/lib/md/PlatformLoader.cpp @@ -129,28 +129,12 @@ size_t get_system_md_symbols(const md::PlatformConfig& config, std::set(); - - // const PlatformMap::PlatformProps platforms[] = { - // pmap.sim(), pmap.srlabs(), pmap.spryware(), pmap.csm(), pmap.cme(), pmap.ice(), pmap.replay(), pmap.activ(), pmap.mdp3(), pmap.csm_onixs(), pmap.blue() - // }; - // const Platform types[] = { - // PLATFORM_SIM, PLATFORM_SRLABS, PLATFORM_SPRYWARE, PLATFORM_CSM, PLATFORM_CME, PLATFORM_ICE, PLATFORM_REPLAY, PLATFORM_ACTIV, PLATFORM_MDP3ONIXS, PLATFORM_CSM_ONIXS, PLATFORM_BLUE - // }; - // static_assert(BTS_ARRAYSIZE(platforms) == BTS_ARRAYSIZE(types),"Platforms should be the same size as types"); - - // for (size_t x = 0; x < BTS_ARRAYSIZE(platforms); x++) - // { - // for (int y = 0; y < platforms[x].exchange_size(); ++y) { - // if (platforms[x].exchange(y) == exchange) { - // return types[x]; - // } - // } - // } - - // return PLATFORM_UNSET; + const auto& pmap = config::get(); + co2::Platform platform; + if (co2::Platform_Parse(pmap.glbx_platform(), &platform)) { + return platform; + } + return PLATFORM_UNSET; } diff --git a/src/lib/md/test/md2_tests.cpp b/src/lib/md/test/md2_tests.cpp index 61743d8eb..8accd6560 100644 --- a/src/lib/md/test/md2_tests.cpp +++ b/src/lib/md/test/md2_tests.cpp @@ -39,7 +39,7 @@ namespace test { using namespace api; using namespace co2; -Platform TEST_PLATFORM = PLATFORM_MDP3ONIXS; +Platform TEST_PLATFORM = PLATFORM_SIM; // // Helper functions for Producer/Consumer tests @@ -148,6 +148,11 @@ class Co2Tests public: void setup() { config::internal::initialize_for_test( + "PlatformMap {" + " value {" + " glbx_platform: 'PLATFORM_SIM'" + " }" + "}" "PublisherOptions {" " value {" " heartbeat_ms: 100" @@ -1202,14 +1207,12 @@ struct Co2IndexTests { struct Co2RelayTests { void setup() { - // config::internal::initialize_for_test( - // "PlatformMap {" - // " value {" - // " sim {" - // " exchange: TESTEXCHANGE" - // " }" - // " }" - // "}"); + config::internal::initialize_for_test( + "PlatformMap {" + " value {" + " glbx_platform: 'PLATFORM_SIM'" + " }" + "}"); } void teardown() {} diff --git a/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp b/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp index 6f1d76350..3022fb251 100644 --- a/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp +++ b/src/server/sparkd/exchange_sim/ExchangeSimApplication.cpp @@ -315,7 +315,8 @@ ExchangeSimApplication::convert(const FIX::ManualOrderIndicator &moi) { ExchangeSimApplication::ExchangeSimApplication() : producer(co2::PLATFORM_SIM), - handles() + handles(), + timer(utils::Dispatcher::background(), 200, [=](){ producer.heartbeat(); }) { std::set symbols; md::get_system_md_symbols(symbols); @@ -324,10 +325,10 @@ ExchangeSimApplication::ExchangeSimApplication() : md::with_security_like(s,[this,s] (auto &fs) { auto new_s = s; *new_s.mutable_glbx()->mutable_security_desc() = std::string("sim:") + s.glbx().security_desc(); - *new_s.mutable_symbol() = std::string("sim:") + s.symbol(); + *new_s.mutable_symbol() = s.symbol(); md::convert_security(new_s, fs, true); md::MDProducerHandle handle = producer.add_security(fs); - auto sec_desc = securities::descriptor(s); + auto sec_desc = securities::descriptor(new_s); handles.insert(make_pair(sec_desc, handle)); }); }}); diff --git a/src/server/sparkd/exchange_sim/ExchangeSimApplication.h b/src/server/sparkd/exchange_sim/ExchangeSimApplication.h index e5ce2a61f..77cc7e1ac 100644 --- a/src/server/sparkd/exchange_sim/ExchangeSimApplication.h +++ b/src/server/sparkd/exchange_sim/ExchangeSimApplication.h @@ -32,6 +32,7 @@ GCC_DIAG_OFF("-Wignored-qualifiers") #include "OrderMatcher.h" #include "Order.h" #include "lib/md/MDProducer.h" +#include "lib/utils/Dispatcher.h" #include #include @@ -108,6 +109,7 @@ private: IDGenerator m_generator; md::MDProducer producer; std::map handles; + utils::DispatcherTimer timer; public: void update_md(std::string const&sec_desc); const OrderMatcher& orderMatcher() { return m_orderMatcher; }