diff --git a/src/lib/config/defaults/MarketData.conf b/src/lib/config/defaults/MarketData.conf index ab4c47638..b42302541 100644 --- a/src/lib/config/defaults/MarketData.conf +++ b/src/lib/config/defaults/MarketData.conf @@ -41,11 +41,13 @@ CMEOptions { ICEOptions { value { channel { + name: "oil" market_type: 5 #ICE Futures Brent, IPE Brent Futures market_type: 9 #ICE Futures WTI, ICE WTI Crude Futures #udp_buffer_size: 67108864 } channel { + name: "juice" market_type: 23 #ICE Futures US Agricultures, FCOJ A } ice_config_file: "ConnectivityConfiguration.APITest.xml" diff --git a/src/lib/config/protos/MarketData.proto b/src/lib/config/protos/MarketData.proto index 1119b8683..955e2934d 100755 --- a/src/lib/config/protos/MarketData.proto +++ b/src/lib/config/protos/MarketData.proto @@ -143,11 +143,12 @@ message ICEOptions //A channel is one onixs-ice thread message ICEChannel { - repeated uint32 market_type = 1; - optional uint32 udp_buffer_size = 2 [default = 33554432]; //32mb - optional uint32 heartbeat_interval = 3 [default = 36000]; - optional uint32 sequence_gap_margin = 4 [default = 10000]; - optional uint32 gap_timeout_in_ms = 5 [default = 10000]; + required string name = 1; + repeated uint32 market_type = 2; + optional uint32 udp_buffer_size = 3 [default = 33554432]; //32mb + optional uint32 heartbeat_interval = 4 [default = 36000]; + optional uint32 sequence_gap_margin = 5 [default = 10000]; + optional uint32 gap_timeout_in_ms = 6 [default = 10000]; optional int32 snapshot_recovery_timeout_in_ms = 10 [default = -1]; optional int32 maximum_number_of_snapshot_recovery_attempts = 11 [default = -1]; diff --git a/src/lib/md/ice/ICEUtils.cpp b/src/lib/md/ice/ICEUtils.cpp index 139f3c117..0a54775fa 100644 --- a/src/lib/md/ice/ICEUtils.cpp +++ b/src/lib/md/ice/ICEUtils.cpp @@ -21,6 +21,35 @@ using namespace bts::api; namespace bts { namespace md { namespace ice { + +std::string ICEChannel::to_string() const +{ + std::string mt = name; + for(const auto& x : market_types) + mt += " " + x; + return mt; +} + +//We are sort of punting on symbols here because there is no symbol -> channel mapping supplied by ice +//therefore we must 1) enumerate the channels we want in config, and smash them together with the list of +//symbols we care about. This has the unfortunate side effect of not knowing what channel should heartbeat what symbol +//but Eric says this is ok +const vector parse_ice_channels(const vector& symbols) +{ + vector result; + const auto& ice_options = config::get(); + for(const auto& x : ice_options.channel()) + { + md::ice::ICEChannel chan; + chan.name = x.name(); + chan.symbols.insert(symbols.begin(), symbols.end()); + for(const auto& xx : x.market_type()) + chan.market_types.push_back(xx); + result.push_back(chan); + } + return result; +} + string ice_data_path() { auto p = config::get().data_path() + "onixs_ice/"; @@ -106,26 +135,6 @@ const std::vector get_configured_ice_channels() { return parse_ice_channels(symbols); } -//We are sort of punting on symbols here because there is no symbol -> channel mapping supplied by ice -//therefore we must 1) enumerate the channels we want in config, and smash them together with the list of -//symbols we care about. This has the unfortunate side effect of not knowing what channel should heartbeat what symbol -//but Eric says this is ok -const vector parse_ice_channels(const vector& symbols) -{ - vector result; - const auto& ice_options = config::get(); - for(const auto& x : ice_options.channel()) - { - for(const auto& xx : x.market_type()) - { - md::ice::ICEChannel chan; - chan.market_type = xx; - chan.symbols.insert(symbols.begin(), symbols.end()); - result.push_back(chan); - } - } - return result; -} }}} //namespace #endif \ No newline at end of file diff --git a/src/lib/md/ice/ICEUtils.h b/src/lib/md/ice/ICEUtils.h index 32c043201..5e0df291e 100644 --- a/src/lib/md/ice/ICEUtils.h +++ b/src/lib/md/ice/ICEUtils.h @@ -11,8 +11,10 @@ namespace ice { struct ICEChannel { - uint32_t market_type; + std::string name; + std::vector market_types; std::set symbols; + std::string to_string() const; }; void await_ice_config(); diff --git a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp index 2f4b7d0c6..ce2384b05 100644 --- a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp +++ b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.cpp @@ -8,6 +8,7 @@ #include "lib/utils/helper_macros.h" #include "lib/utils/Dispatcher.h" #include "lib/utils/proto_helper.h" +#include "lib/utils/bts_chrono.h" #include "lib/md/protos/co2.pb.h" #include "lib/config/protos/MarketData.pb.h" @@ -54,28 +55,29 @@ ICEMain::ICEMain() : ICEMain::~ICEMain() {} -const ICEOptions::ICEChannel channel_settings_for(uint32_t id) +const ICEOptions::ICEChannel channel_settings_for(const ICEChannel& channel) { const auto& config = config::get(); for (const auto& ch : config.channel()) { - bool found = std::find_if(ch.market_type().begin(), ch.market_type().end(), [&](const uint32_t& chan_id) { return chan_id == id ; }) != ch.market_type().end(); - if(found) - return ch; + if(ch.name() == channel.name) + return ch; } return ICEOptions::ICEChannel(); } -onixs_ice::MarketSubscriptions market_subcription_for_channel(uint32_t market_type) +onixs_ice::MarketSubscriptions market_subcription_for_channel(const ICEChannel& chan) { - const auto& options = channel_settings_for(market_type); onixs_ice::MarketSubscriptions subs; - //onixs_ice::MarketSubType::NonImplied - onixs_ice::MarketSubscription futures(market_type, onixs_ice::MarketSubType::FullImplied, onixs_ice::SecurityType::Futures, onixs_ice::BookDepth::FOD); - onixs_ice::MarketSubscription spreads(market_type, onixs_ice::MarketSubType::FullImplied, onixs_ice::SecurityType::UdsFuturesMarkets, onixs_ice::BookDepth::FOD); - subs.push_back(futures); - subs.push_back(spreads); + for(const auto& x : chan.market_types) + { + //onixs_ice::MarketSubType::NonImplied + onixs_ice::MarketSubscription futures(x, onixs_ice::MarketSubType::FullImplied, onixs_ice::SecurityType::Futures, onixs_ice::BookDepth::FOD); + onixs_ice::MarketSubscription spreads(x, onixs_ice::MarketSubType::FullImplied, onixs_ice::SecurityType::UdsFuturesMarkets, onixs_ice::BookDepth::FOD); + subs.push_back(futures); + subs.push_back(spreads); + } return subs; } @@ -101,19 +103,22 @@ void ICEMain::run(std::vector& symbols) const auto& channels = parse_ice_channels(symbols); for (const auto& channel : channels) { - unique_ptr phandler = prepare_handler(channel.market_type); + unique_ptr phandler = prepare_handler(channel); _listeners.push_back(prepare_listener(*phandler, channel)); - _handlers.insert(std::make_pair(channel.market_type, move(phandler))); - std::stringstream symstr; + _handlers.push_back(std::make_pair(channel, move(phandler))); + + std::stringstream symstr; for (const auto& sym : channel.symbols) symstr << sym.symbol() << "-" << SecurityType_Name(sym.type()) << " "; - LOG(md,Info, "ICE: Initialized channel {} ({})",channel.market_type,symstr.str()); + LOG(md,Info, "ICE: Initialized channel {} ({})", channel.to_string(), symstr.str()); } for (auto& pair : _handlers) - { - onixs_ice::MarketSubscriptions subs = market_subcription_for_channel(pair.first); + { + LOG(md,Info, "ICE: Init Handler {}", pair.first.to_string()); + onixs_ice::MarketSubscriptions subs = market_subcription_for_channel(pair.first); pair.second->start(subs); + sleep_for(16s); } // @@ -131,7 +136,7 @@ void ICEMain::run(std::vector& symbols) // // // Initialize HandlerSettings and allocate the channel Handler -unique_ptr ICEMain::prepare_handler(uint32_t market_type) +unique_ptr ICEMain::prepare_handler(const ICEChannel& channel) { const auto& ice_options = config::get(); auto license = ice_options.onixs_license(); @@ -139,8 +144,8 @@ unique_ptr ICEMain::prepare_handler(uint32_t market_type) license = os::bts_data_path() + "/licenses/"; const auto& pub_options = config::get(); - const auto& options = channel_settings_for(market_type); - LOG(md,Info,"Loaded channel options for channel {}:\n{}",market_type,options.DebugString()); + const auto& options = channel_settings_for(channel); + LOG(md,Info,"Loaded channel options for channel {}:\n{}", channel.to_string(), options.DebugString()); onixs_ice::HandlerSettings settings; settings.licenseDirectory = license; @@ -201,7 +206,7 @@ unique_ptr ICEMain::prepare_handler(uint32_t market_type) return handler; } catch (std::exception& e) { - LOG(md,Error,"{}", std::string(e.what())); + LOG(md,Error,"ONIXSERROR{}", std::string(e.what())); throw; } } @@ -217,7 +222,7 @@ unique_ptr ICEMain::prepare_listener(onixs_ice::Handler& handler, c producer_channels.push_back(_producer.get_channel(symbol.symbol().c_str(), symbol.type(), symbol.exchange())); } - const auto& options = channel_settings_for(channel.market_type); + const auto& options = channel_settings_for(channel); unique_ptr listener(new ICEListener(_index, _producer, /*_settlement_recorder,*/ producer_channels)); for (auto& symbol : channel.symbols) listener->add_filter_symbol(symbol.symbol()); diff --git a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h index 3ec06504a..4b974a9d5 100644 --- a/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h +++ b/src/server/sparkd/md/platforms/ice_onixs/ICEMain.h @@ -32,7 +32,7 @@ public: void run(std::vector&); void initialize(); - std::unique_ptr prepare_handler(uint32_t channel); + std::unique_ptr prepare_handler(const ICEChannel& channel); std::unique_ptr prepare_listener(onixs_ice::Handler& handler, const ICEChannel& channel); private: @@ -41,8 +41,8 @@ private: ICESecurityIndex _index; SecurityIDRecorder _recorder; MDProducer _producer; - std::map> _handlers; - std::vector> _listeners; + std::vector< std::pair> > _handlers; + std::vector< std::unique_ptr > _listeners; }; }}} //namespace