Minor settings changes? hah!
This commit is contained in:
1 parent
57554acf48
commit
336f8b2eb0
5 files changed
+385
-393
No files matched your search
@@ -33,21 +33,6 @@ CMEOptions {
|
||||
}
|
||||
}
|
||||
|
||||
ActivSpreadMap {
|
||||
value {
|
||||
entry {
|
||||
symbol: "ES"
|
||||
exchange: GLBX
|
||||
pattern: "UD:1V:*"
|
||||
}
|
||||
entry {
|
||||
symbol: "EW"
|
||||
exchange: GLBX
|
||||
pattern: "UD:1V:*"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RecordOptions {
|
||||
rule: "System.platform == 'Windows'"
|
||||
value {
|
||||
|
||||
@@ -13,9 +13,9 @@ namespace bts {
|
||||
namespace md {
|
||||
|
||||
class MDP3Listener :
|
||||
onixs::HandlerListener,
|
||||
onixs::MarketDataListener,
|
||||
onixs::SecurityListener
|
||||
public onixs::HandlerListener,
|
||||
public onixs::MarketDataListener,
|
||||
public onixs::SecurityListener
|
||||
{
|
||||
public:
|
||||
MDP3Listener(CMESecurityIndex& index, md2::MDProducer&, md2::SecurityIDRecorder&, co2::SettlementRecorder&, std::vector<md2::MDProducerChannel>, utils::Dispatcher&);
|
||||
|
||||
@@ -1,25 +1,26 @@
|
||||
// #ifndef NO_CPP0X
|
||||
// #include "MDP3Main.h"
|
||||
#include "MDP3Main.h"
|
||||
|
||||
// #include "MDP3Utils.h"
|
||||
// #include "lib/config/config.h"
|
||||
// #include "lib/md/coconut2.h"
|
||||
// #include "lib/os/os.h"
|
||||
// #include "lib/utils/Dispatcher.h"
|
||||
// #include "lib/utils/proto_helper.h"
|
||||
#include "MDP3Utils.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/md/coconut2.h"
|
||||
#include "lib/os/os.h"
|
||||
#include "lib/utils/Dispatcher.h"
|
||||
#include "lib/utils/proto_helper.h"
|
||||
#include "lib/md/protos/co2.pb.h"
|
||||
|
||||
// #include "lib/config/protos/MarketData.pb.h"
|
||||
// #include "lib/config/protos/system.pb.h"
|
||||
#include "lib/config/protos/MarketData.pb.h"
|
||||
#include "lib/config/protos/system.pb.h"
|
||||
|
||||
// #include <memory>
|
||||
// #include <set>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
|
||||
// using namespace std;
|
||||
// using namespace bts::md2;
|
||||
// // using namespace OnixS::CME::MDP3;
|
||||
using namespace std;
|
||||
using namespace bts::md2;
|
||||
using namespace bts::co2;
|
||||
// using namespace onixs;
|
||||
|
||||
// namespace bts {
|
||||
// namespace md {
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
// void run_onixs_mdp3_server(UserSymbol* psyms, size_t symcount) {
|
||||
// MDP3Main main;
|
||||
@@ -30,289 +31,295 @@
|
||||
// main.run(symbols);
|
||||
// }
|
||||
|
||||
// MDP3Main::MDP3Main() :
|
||||
// _producer(Platform::MDP3ONIXS),
|
||||
// _security_recorder(),
|
||||
// _settlement_recorder(Platform::MDP3ONIXS),
|
||||
// _engines(),
|
||||
// _handlers(),
|
||||
// _listeners()
|
||||
// {
|
||||
// }
|
||||
MDP3Main::MDP3Main() :
|
||||
_producer(PLATFORM_MDP3ONIXS),
|
||||
_security_recorder(),
|
||||
_settlement_recorder(PLATFORM_MDP3ONIXS),
|
||||
_engines(),
|
||||
_handlers(),
|
||||
_listeners(),
|
||||
_recovery()
|
||||
{
|
||||
}
|
||||
|
||||
// MDP3Main::~MDP3Main() {}
|
||||
MDP3Main::~MDP3Main() {}
|
||||
|
||||
// const CMEOptions::CMEChannel channel_settings_for(const string& id) {
|
||||
// const auto& config = config::get<CMEOptions>();
|
||||
// for (const auto& ch : config.channel()) {
|
||||
// bool found = std::find_if(ch.id().begin(), ch.id().end(), [&](const string& chan_id) { return chan_id == id || chan_id == "*"; }) != ch.id().end();
|
||||
// if (found) {
|
||||
// return ch;
|
||||
// }
|
||||
// }
|
||||
// return CMEOptions::CMEChannel();
|
||||
// }
|
||||
// bool feed_engine_exists(const string& name) {
|
||||
// const auto& config = config::get<CMEOptions>();
|
||||
// for (const auto& feed : config.feed_engine()) {
|
||||
// if (feed.name() == name) return true;
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
const CMEOptions::CMEChannel channel_settings_for(const string& id) {
|
||||
const auto& config = config::get<CMEOptions>();
|
||||
for (const auto& ch : config.channel()) {
|
||||
bool found = std::find_if(ch.id().begin(), ch.id().end(), [&](const string& chan_id) { return chan_id == id || chan_id == "*"; }) != ch.id().end();
|
||||
if (found) {
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
return CMEOptions::CMEChannel();
|
||||
}
|
||||
bool feed_engine_exists(const string& name) {
|
||||
const auto& config = config::get<CMEOptions>();
|
||||
for (const auto& feed : config.feed_engine()) {
|
||||
if (feed.name() == name) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// const onixs::FeedEngineSettings feed_engine_settings_from_config(const CMEOptions::FeedEngineSettings& settings, int feed_count) {
|
||||
// onixs::FeedEngineSettings result;
|
||||
// if (settings.has_data_wait()) result.dataWaitTime(settings.data_wait());
|
||||
// if (settings.has_spin_time()) result.redundancySpinTime(settings.spin_time());
|
||||
// for (auto& core : settings.affinity()) {
|
||||
// result.threadsAffinity().insert(core);
|
||||
// }
|
||||
const onixs::FeedEngineSettings feed_engine_settings_from_config(const CMEOptions::FeedEngineSettings& settings, int feed_count) {
|
||||
onixs::FeedEngineSettings result;
|
||||
|
||||
// // num_threads() overrides anything else
|
||||
// if (settings.has_num_threads()) {
|
||||
// result.threadsCount(settings.num_threads());
|
||||
// }
|
||||
// else {
|
||||
// // If num_threads is absent determine thread count based on #channels
|
||||
// result.threadsCount((feed_count / settings.channels_per_thread()) + 1);
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
if (settings.has_data_wait()) result.dataWaitTime(settings.data_wait());
|
||||
if (settings.has_spin_time()) result.spinBeforeIdleTime(settings.spin_time());
|
||||
|
||||
// size_t count_engine_uses(const vector<CMEChannel>& channels, const string& feed_name) {
|
||||
// return count_if(channels.begin(), channels.end(), [&](const CMEChannel& ch) {
|
||||
// const auto& settings = channel_settings_for(ch.id);
|
||||
// return settings.has_feed_engine() && settings.feed_engine() == feed_name;
|
||||
// });
|
||||
// }
|
||||
for (auto& core : settings.affinity()) {
|
||||
result.threadAffinity().cpus().insert(core);
|
||||
}
|
||||
|
||||
// map<string,onixs::FeedEngineSettings> create_feed_engine_settings(const std::vector<CMEChannel>& channels) {
|
||||
// map<string, onixs::FeedEngineSettings> settings;
|
||||
// const auto& config = config::get<CMEOptions>();
|
||||
// num_threads() overrides anything else
|
||||
if (settings.has_num_threads()) {
|
||||
result.threadCount(settings.num_threads());
|
||||
}
|
||||
else {
|
||||
// If num_threads is absent determine thread count based on #channels
|
||||
result.threadCount((feed_count / settings.channels_per_thread()) + 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// // For each feed engine in feed_engine
|
||||
// for (const auto& feed : config.feed_engine()) {
|
||||
// // - see if it is in use
|
||||
// size_t use_count = count_engine_uses(channels, feed.name());
|
||||
// // - Only create if this feed engine is in use
|
||||
// if (use_count > 0) {
|
||||
// settings[feed.name()] = feed_engine_settings_from_config(feed, use_count);
|
||||
// }
|
||||
// }
|
||||
size_t count_engine_uses(const vector<CMEChannel>& channels, const string& feed_name) {
|
||||
return count_if(channels.begin(), channels.end(), [&](const CMEChannel& ch) {
|
||||
const auto& settings = channel_settings_for(ch.id);
|
||||
return settings.has_feed_engine() && settings.feed_engine() == feed_name;
|
||||
});
|
||||
}
|
||||
|
||||
// // If a channel asks for defaults ensure it exists.
|
||||
// if (settings.count("default") == 0) {
|
||||
// size_t channels_using_default = count_engine_uses(channels, "default");
|
||||
// if (channels_using_default > 0) {
|
||||
// settings["default"] = feed_engine_settings_from_config(CMEOptions::FeedEngineSettings(), channels_using_default);
|
||||
// }
|
||||
// }
|
||||
map<string,onixs::FeedEngineSettings> create_feed_engine_settings(const std::vector<CMEChannel>& channels) {
|
||||
map<string, onixs::FeedEngineSettings> settings;
|
||||
const auto& config = config::get<CMEOptions>();
|
||||
|
||||
// return settings;
|
||||
// }
|
||||
// For each feed engine in feed_engine
|
||||
for (const auto& feed : config.feed_engine()) {
|
||||
// - see if it is in use
|
||||
size_t use_count = count_engine_uses(channels, feed.name());
|
||||
// - Only create if this feed engine is in use
|
||||
if (use_count > 0) {
|
||||
settings[feed.name()] = feed_engine_settings_from_config(feed, use_count);
|
||||
}
|
||||
}
|
||||
|
||||
// map<string, unique_ptr<onixs::FeedEngine>> create_feed_engines(const vector<CMEChannel>& channels) {
|
||||
// map<string, unique_ptr<onixs::FeedEngine>> result;
|
||||
// auto settings = create_feed_engine_settings(channels);
|
||||
// // Loop through settings and instantiate feed engines
|
||||
// for (const auto& s : settings) {
|
||||
// unique_ptr<onixs::FeedEngine> temp(new onixs::FeedEngine(s.second));
|
||||
// result.insert(make_pair(s.first, move(temp)));
|
||||
// }
|
||||
// If a channel asks for defaults ensure it exists.
|
||||
if (settings.count("default") == 0) {
|
||||
size_t channels_using_default = count_engine_uses(channels, "default");
|
||||
if (channels_using_default > 0) {
|
||||
settings["default"] = feed_engine_settings_from_config(CMEOptions::FeedEngineSettings(), channels_using_default);
|
||||
}
|
||||
}
|
||||
|
||||
// return result;
|
||||
// }
|
||||
return settings;
|
||||
}
|
||||
|
||||
// void MDP3Main::run(std::vector<UserSymbol>& symbols) {
|
||||
// await_cme_config();
|
||||
// initialize();
|
||||
// const auto& channels = parse_channels(symbols);
|
||||
// _engines = create_feed_engines(channels);
|
||||
// for (const auto& channel : channels) {
|
||||
// _handlers.push_back(prepare_handler(channel.id));
|
||||
// _listeners.push_back(prepare_listener(*_handlers.back(), channel));
|
||||
// std::stringstream symstr;
|
||||
// for (const auto& sym : channel.symbols) { symstr << sym.symbol() << "-" << SecurityType_Name(sym.type()) << " "; }
|
||||
// LOG(MarketData,Info, "CME: Initialized channel {} ({})",channel.id,symstr.str());
|
||||
// }
|
||||
// for (auto& p_handler : _handlers) {
|
||||
// p_handler->start();
|
||||
// }
|
||||
map<string, unique_ptr<onixs::FeedEngine>> create_feed_engines(const vector<CMEChannel>& channels) {
|
||||
map<string, unique_ptr<onixs::FeedEngine>> result;
|
||||
auto settings = create_feed_engine_settings(channels);
|
||||
// Loop through settings and instantiate feed engines
|
||||
for (const auto& s : settings) {
|
||||
unique_ptr<onixs::FeedEngine> temp(new onixs::FeedEngine(s.second));
|
||||
result.insert(make_pair(s.first, move(temp)));
|
||||
}
|
||||
|
||||
// //
|
||||
// // Work timer
|
||||
// auto& disp = utils::Dispatcher::current();
|
||||
// utils::DispatcherTimer security_timer(disp, 500, [&]() {
|
||||
// _security_recorder.do_work();
|
||||
// });
|
||||
// security_timer.start();
|
||||
return result;
|
||||
}
|
||||
|
||||
// utils::DispatcherTimer spread_resolve_timer(disp, 1000, [&]() {
|
||||
// _index.resolve_spreads();
|
||||
// });
|
||||
// spread_resolve_timer.start();
|
||||
void MDP3Main::run(std::vector<UserSymbol>& symbols) {
|
||||
(void)symbols;
|
||||
await_cme_config();
|
||||
initialize();
|
||||
const auto& channels = parse_channels(symbols);
|
||||
_engines = create_feed_engines(channels);
|
||||
for (const auto& channel : channels) {
|
||||
_handlers.push_back(prepare_handler(channel.id));
|
||||
_listeners.push_back(prepare_listener(*_handlers.back(), channel));
|
||||
std::stringstream symstr;
|
||||
for (const auto& sym : channel.symbols) { symstr << sym.symbol() << "-" << SecurityType_Name(sym.type()) << " "; }
|
||||
LOG(MarketData,Info, "CME: Initialized channel {} ({})",channel.id,symstr.str());
|
||||
}
|
||||
|
||||
// utils::DispatcherTimer settlement_timer(disp, 100, [&]() {
|
||||
// _settlement_recorder.do_work();
|
||||
// });
|
||||
// settlement_timer.start();
|
||||
onixs::SessionSettings settings;
|
||||
for (auto& p_handler : _handlers) {
|
||||
p_handler->start(settings);
|
||||
}
|
||||
|
||||
// utils::DispatcherTimer heartbeat_timer(disp, 250, [&]() {
|
||||
// for (const auto& listener: _listeners) {
|
||||
// listener->heartbeat();
|
||||
// }
|
||||
// });
|
||||
// heartbeat_timer.start();
|
||||
//
|
||||
// Timers
|
||||
|
||||
// LOG(MarketData,Info, "** CME MDP3 Publisher started **");
|
||||
auto& disp = utils::Dispatcher::current();
|
||||
utils::DispatcherTimer security_timer(disp, 500, [&]() {
|
||||
_security_recorder.do_work();
|
||||
});
|
||||
security_timer.start();
|
||||
|
||||
// disp.run();
|
||||
// }
|
||||
utils::DispatcherTimer spread_resolve_timer(disp, 1000, [&]() {
|
||||
_index.resolve_spreads();
|
||||
});
|
||||
spread_resolve_timer.start();
|
||||
|
||||
utils::DispatcherTimer settlement_timer(disp, 100, [&]() {
|
||||
_settlement_recorder.do_work();
|
||||
});
|
||||
settlement_timer.start();
|
||||
|
||||
utils::DispatcherTimer heartbeat_timer(disp, 250, [&]() {
|
||||
for (const auto& listener: _listeners) {
|
||||
listener->heartbeat();
|
||||
}
|
||||
});
|
||||
heartbeat_timer.start();
|
||||
|
||||
LOG(MarketData,Info, "** CME MDP3 Publisher started **");
|
||||
|
||||
disp.run();
|
||||
}
|
||||
|
||||
|
||||
// void MDP3Main::initialize() {
|
||||
// const auto& options = config::get<CMEOptions>();
|
||||
void MDP3Main::initialize() {
|
||||
const auto& options = config::get<CMEOptions>();
|
||||
|
||||
// //
|
||||
// // License path
|
||||
// onixs::InitializationSettings init_settings;
|
||||
// auto license = options.onixs_license();
|
||||
// init_settings.licenseStore(license);
|
||||
// if (license == "{default}") {
|
||||
// init_settings.licenseStore(os::get_cwd() + "/licenses/");
|
||||
// }
|
||||
// LOG(MarketData,Info,"Loading onixs license from {}", init_settings.licenseStore());
|
||||
// onixs::initialize(init_settings);
|
||||
// }
|
||||
//
|
||||
// License path
|
||||
onixs::InitializationSettings init_settings;
|
||||
auto license = options.onixs_license();
|
||||
init_settings.licenseStore(license);
|
||||
if (license == "{default}") {
|
||||
init_settings.licenseStore(os::bts_data_path() + "/licenses/");
|
||||
}
|
||||
LOG(MarketData,Info,"Loading onixs license from {}", init_settings.licenseStore());
|
||||
onixs::initialize(init_settings);
|
||||
}
|
||||
|
||||
// //
|
||||
// // Initialize HandlerSettings and allocate the channel Handler
|
||||
// unique_ptr<onixs::Handler> MDP3Main::prepare_handler(const string& channel_id) {
|
||||
// const auto& pub_options = config::get<PublisherOptions>();
|
||||
// const auto& options = channel_settings_for(channel_id);
|
||||
// LOG(MarketData,Info,"Loaded channel options for channel {}:\n{}",channel_id ,options.DebugString());
|
||||
// onixs::HandlerSettings settings;
|
||||
// settings.channelId(channel_id);
|
||||
// settings.channelsConfigurationFile(config_path());
|
||||
// settings.codingTemplatesFile(template_path());
|
||||
// Initialize HandlerSettings and allocate the channel Handler
|
||||
unique_ptr<onixs::Handler> MDP3Main::prepare_handler(const string& channel_id) {
|
||||
const auto& pub_options = config::get<PublisherOptions>();
|
||||
const auto& options = channel_settings_for(channel_id);
|
||||
LOG(MarketData,Info,"Loaded channel options for channel {}:\n{}",channel_id ,options.DebugString());
|
||||
|
||||
// //
|
||||
// // Tcp Replay options
|
||||
onixs::HandlerSettings settings;
|
||||
settings.channel(std::stoul(channel_id));
|
||||
settings.feeds().connectivityConfigurationFile(config_path());
|
||||
|
||||
// if (options.use_tcp_replay()) LOG(MarketData,Info,"CME: Enabled TCP replay");
|
||||
// if (options.use_tcp_replay()) {
|
||||
// settings.tcpRecoveryUsername(options.tcp_replay_username());
|
||||
// settings.tcpRecoveryPassword(options.tcp_replay_password());
|
||||
// settings.tcpRecoveryReconnectAttempts(options.tcp_replay_connect_attempts());
|
||||
// settings.tcpRecoveryReconnectInterval(options.tcp_replay_reconnect_interval_ms());
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Network settings
|
||||
|
||||
// settings.udpSocketBufferSize(options.udp_socket_buffer_size());
|
||||
// if (options.has_lost_packet_wait_timeout_ms()) {
|
||||
// settings.lostPacketWaitTime((size_t)options.lost_packet_wait_timeout_ms() * 1000);
|
||||
// }
|
||||
// if (pub_options.has_network_interface()) {
|
||||
// settings.networkInterface(pub_options.network_interface());
|
||||
// }
|
||||
// else {
|
||||
// if (pub_options.has_network_interface_a()) {
|
||||
// settings.networkInterfaceA(pub_options.network_interface_a());
|
||||
// }
|
||||
// if (pub_options.has_network_interface_b()) {
|
||||
// settings.networkInterfaceB(pub_options.network_interface_b());
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (pub_options.has_network_interface() ||
|
||||
// (pub_options.has_network_interface_a() &&
|
||||
// pub_options.has_network_interface_b()) ) {
|
||||
// if (options.prefer_backup_feeds()) {
|
||||
// settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedBWithFailoverToFeedA);
|
||||
// settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedBWithFailoverToFeedA);
|
||||
// }
|
||||
// else {
|
||||
// settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedAWithFailoverToFeedB);
|
||||
// settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedAWithFailoverToFeedB);
|
||||
// }
|
||||
// }
|
||||
// else if (pub_options.has_network_interface_a()) {
|
||||
// settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedAOnly);
|
||||
// settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedAOnly);
|
||||
// }
|
||||
// else if (pub_options.has_network_interface_b()) {
|
||||
// settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedBOnly);
|
||||
// settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedBOnly);
|
||||
// }
|
||||
|
||||
// //
|
||||
// // Misc settings
|
||||
|
||||
// settings.recoverSecurityDefinitionsOnGap(false);
|
||||
// settings.bookUpdateNotificationStrategy(onixs::BookUpdateNotificationStrategies::OnEndOfEvent);
|
||||
|
||||
// //
|
||||
// // Logging
|
||||
|
||||
// settings.logDirectory(config::get<CMEOptions>().onixs_log_path());
|
||||
// settings.logMode((onixs::LogModes::Enum)options.onixs_log_mode());
|
||||
// settings.advancedLogOptions((onixs::AdvancedLogOptions::Enum)options.onixs_log_advanced());
|
||||
// settings.logFileNamePrefix(channel_id + "_");
|
||||
// Market data options
|
||||
settings.bookManagement().consolidatedBooks().maintain(true);
|
||||
|
||||
|
||||
// //
|
||||
// // Associate with feed handler
|
||||
//
|
||||
// Network settings
|
||||
|
||||
// try {
|
||||
// auto temp = unique_ptr<onixs::Handler>(new onixs::Handler(settings));
|
||||
// if (options.has_feed_engine()) {
|
||||
// temp->bindToFeedEngine(_engines[options.feed_engine()].get());
|
||||
// }
|
||||
// return temp;
|
||||
// }
|
||||
// catch (std::exception& e) {
|
||||
// LOG(MarketData,Error,"{}", e.what());
|
||||
// throw;
|
||||
// }
|
||||
// }
|
||||
// settings.udpSocketBufferSize(options.udp_socket_buffer_size());
|
||||
|
||||
if (options.has_lost_packet_wait_timeout_ms()) {
|
||||
settings.lostPacketWaitTime((size_t)options.lost_packet_wait_timeout_ms() * 1000);
|
||||
}
|
||||
if (pub_options.has_network_interface()) {
|
||||
settings.networkInterface(pub_options.network_interface());
|
||||
}
|
||||
else {
|
||||
if (pub_options.has_network_interface_a()) {
|
||||
settings.networkInterfaceA(pub_options.network_interface_a());
|
||||
}
|
||||
if (pub_options.has_network_interface_b()) {
|
||||
settings.networkInterfaceB(pub_options.network_interface_b());
|
||||
}
|
||||
}
|
||||
|
||||
if (pub_options.has_network_interface() ||
|
||||
(pub_options.has_network_interface_a() &&
|
||||
pub_options.has_network_interface_b()) ) {
|
||||
if (options.prefer_backup_feeds()) {
|
||||
settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedBWithFailoverToFeedA);
|
||||
settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedBWithFailoverToFeedA);
|
||||
}
|
||||
else {
|
||||
settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedAWithFailoverToFeedB);
|
||||
settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedAWithFailoverToFeedB);
|
||||
}
|
||||
}
|
||||
else if (pub_options.has_network_interface_a()) {
|
||||
settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedAOnly);
|
||||
settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedAOnly);
|
||||
}
|
||||
else if (pub_options.has_network_interface_b()) {
|
||||
settings.instrumentFeedLayout(onixs::RecoveryFeedLayout::FeedBOnly);
|
||||
settings.snapshotFeedLayout(onixs::RecoveryFeedLayout::FeedBOnly);
|
||||
}
|
||||
|
||||
//
|
||||
// Misc settings
|
||||
|
||||
settings.recoverSecurityDefinitionsOnGap(false);
|
||||
settings.bookUpdateNotificationStrategy(onixs::BookUpdateNotificationStrategies::OnEndOfEvent);
|
||||
|
||||
//
|
||||
// Logging
|
||||
|
||||
settings.logDirectory(config::get<CMEOptions>().onixs_log_path());
|
||||
settings.logMode((onixs::LogModes::Enum)options.onixs_log_mode());
|
||||
settings.advancedLogOptions((onixs::AdvancedLogOptions::Enum)options.onixs_log_advanced());
|
||||
settings.logFileNamePrefix(channel_id + "_");
|
||||
|
||||
//
|
||||
// Tcp Replay options
|
||||
|
||||
std::unique_ptr<onixs::TcpRecoveryService> recovery;
|
||||
if (options.use_tcp_replay()) {
|
||||
LOG(MarketData,Info,"CME: Enabled TCP replay");
|
||||
onixs::TcpRecoverySettings tcpSettings;
|
||||
tcpSettings.username(options.tcp_replay_username());
|
||||
tcpSettings.password(options.tcp_replay_password());
|
||||
tcpSettings.reconnectAttempts(options.tcp_replay_connect_attempts());
|
||||
tcpSettings.reconnectInterval(options.tcp_replay_reconnect_interval_ms());
|
||||
recovery = new onixs::TcpRecoveryService(tcpSettings);
|
||||
}
|
||||
|
||||
//
|
||||
// Associate with feed handler
|
||||
|
||||
try {
|
||||
auto handler = unique_ptr<onixs::Handler>(new onixs::Handler(settings));
|
||||
if (options.has_feed_engine()) {
|
||||
handler->bindToFeedEngine(_engines[options.feed_engine()].get());
|
||||
}
|
||||
if (recovery) {
|
||||
handler->bindTcpRecovery(*recovery);
|
||||
_recovery.push_back(std::move(recovery));
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
LOG(MarketData,Error,"{}", e.what());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
// //
|
||||
// // Create a listener for this channel and register callbacks
|
||||
// unique_ptr<MDP3Listener> MDP3Main::prepare_listener(onixs::Handler& handler, const CMEChannel& channel) {
|
||||
// // We need to get a handler to the producer channels so we can produce heartbeats
|
||||
// vector<MDProducerChannel> producer_channels;
|
||||
// for (auto& symbol : channel.symbols) {
|
||||
// producer_channels.push_back(_producer.get_channel(symbol.symbol().c_str(), symbol.type(), symbol.exchange()));
|
||||
// //handler.addSecurityAssetFilter(symbol.symbol());
|
||||
// }
|
||||
unique_ptr<MDP3Listener> MDP3Main::prepare_listener(onixs::Handler& handler, const CMEChannel& channel) {
|
||||
// We need to get a handler to the producer channels so we can produce heartbeats
|
||||
vector<MDProducerChannel> producer_channels;
|
||||
for (auto& symbol : channel.symbols) {
|
||||
producer_channels.push_back(_producer.get_channel(symbol.symbol().c_str(), symbol.type(), symbol.exchange()));
|
||||
//handler.addSecurityAssetFilter(symbol.symbol());
|
||||
}
|
||||
|
||||
// unique_ptr<MDP3Listener> listener(new MDP3Listener(_index, _producer, _security_recorder, _settlement_recorder, producer_channels, utils::Dispatcher::current()));
|
||||
// for (auto& symbol : channel.symbols) {
|
||||
// listener->add_filter_symbol(symbol.symbol());
|
||||
// }
|
||||
unique_ptr<MDP3Listener> listener(new MDP3Listener(_index, _producer, _security_recorder, _settlement_recorder, producer_channels, utils::Dispatcher::current()));
|
||||
for (auto& symbol : channel.symbols) {
|
||||
listener->add_filter_symbol(symbol.symbol());
|
||||
}
|
||||
|
||||
// handler.registerMessageProcessingListener(listener.get());
|
||||
// handler.registerSecurityDefinitionListener(listener.get());
|
||||
// handler.registerSecurityStatusListener(listener.get());
|
||||
// handler.registerConsolidatedBookUpdateListener(listener.get());
|
||||
// handler.registerStateChangeListener(listener.get());
|
||||
|
||||
// if (!config::get<CMEOptions>().quoter_mode()) {
|
||||
// handler.registerTradeListener(listener.get());
|
||||
// handler.registerElectronicVolumeListener(listener.get());
|
||||
// handler.registerRequestForQuoteListener(listener.get());
|
||||
// handler.registerStatisticsListener(listener.get());
|
||||
// }
|
||||
|
||||
// handler.registerWarningListener(listener.get());
|
||||
// handler.registerErrorListener(listener.get());
|
||||
|
||||
// return listener;
|
||||
// }
|
||||
handler.registerListener(*listener);
|
||||
handler.registerMarketDataListener(*listener);
|
||||
handler.registerSecurityListener(*listener);
|
||||
|
||||
|
||||
// }}//namespace
|
||||
// #endif
|
||||
return listener;
|
||||
}
|
||||
|
||||
|
||||
}}//namespace
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
void run_onixs_mdp3_server(md2::UserSymbol* sym, size_t symcount);
|
||||
// void run_onixs_mdp3_server(md2::UserSymbol* sym, size_t symcount);
|
||||
|
||||
struct CMEChannel;
|
||||
|
||||
@@ -44,6 +44,7 @@ private:
|
||||
std::map<std::string, std::unique_ptr<onixs::FeedEngine>> _engines;
|
||||
std::vector<std::unique_ptr<onixs::Handler>> _handlers;
|
||||
std::vector<std::unique_ptr<MDP3Listener>> _listeners;
|
||||
std::vector<std::unique_ptr<onixs::TcpRecoveryService>> _recovery;
|
||||
};
|
||||
|
||||
}}//namespace
|
||||
|
||||
@@ -1,128 +1,127 @@
|
||||
// #ifndef NO_CPP0X
|
||||
// #include "MDP3Utils.h"
|
||||
// #include "onixs.h"
|
||||
#include "MDP3Utils.h"
|
||||
#include "onixs.h"
|
||||
|
||||
// #include "lib/config/config.h"
|
||||
// #include "lib/utils/datetime.h"
|
||||
// #include "lib/utils/bts_chrono.h"
|
||||
#include "lib/config/config.h"
|
||||
#include "lib/utils/datetime.h"
|
||||
#include "lib/utils/bts_chrono.h"
|
||||
|
||||
// #include "lib/config/protos/MarketData.pb.h"
|
||||
// #include "lib/config/protos/system.pb.h"
|
||||
#include "lib/config/protos/MarketData.pb.h"
|
||||
#include "lib/config/protos/system.pb.h"
|
||||
|
||||
// #include <boost/filesystem.hpp>
|
||||
// #include <pugixml/pugixml.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <pugixml/pugixml.hpp>
|
||||
|
||||
// using namespace std;
|
||||
// using namespace bts::md2;
|
||||
using namespace std;
|
||||
using namespace bts::md2;
|
||||
using namespace bts::api;
|
||||
|
||||
// namespace bts {
|
||||
// namespace md {
|
||||
namespace bts {
|
||||
namespace md {
|
||||
|
||||
// string data_path() {
|
||||
// auto p = config::get<config::System>().data_path() + "cme_mdp3/";
|
||||
// #ifdef _WIN32
|
||||
// // OnixS requires win32 paths to look like Win32 paths - everyone else in the world is ok with '/'
|
||||
// os::normalize_path(p, '\\');
|
||||
// #else
|
||||
// os::normalize_path(p);
|
||||
// #endif
|
||||
// return p;
|
||||
// }
|
||||
// const string config_path() { return data_path() + "config.xml"; }
|
||||
// const string template_path() { return data_path() + "templates.xml"; }
|
||||
string data_path() {
|
||||
auto p = config::get<config::System>().data_path() + "cme_mdp3/";
|
||||
#ifdef _WIN32
|
||||
// OnixS requires win32 paths to look like Win32 paths - everyone else in the world is ok with '/'
|
||||
os::normalize_path(p, '\\');
|
||||
#else
|
||||
os::normalize_path(p);
|
||||
#endif
|
||||
return p;
|
||||
}
|
||||
const string config_path() { return data_path() + "config.xml"; }
|
||||
const string template_path() { return data_path() + "templates.xml"; }
|
||||
|
||||
// bool check_file_exists_with_instructions(const string& filename, const string& url, bool log) {
|
||||
// if (!boost::filesystem::exists(filename)) {
|
||||
// if (log) {
|
||||
// LOG(MarketData,Error,
|
||||
// "File {} is not present on this system. "
|
||||
// "Please download it from the CME ftp site. "
|
||||
// "I will wait until the file is present.\n$ curl {} > {} ",
|
||||
// filename, url, filename);
|
||||
// }
|
||||
// return false;
|
||||
// }
|
||||
// return true;
|
||||
// }
|
||||
bool check_file_exists_with_instructions(const string& filename, const string& url, bool log) {
|
||||
if (!boost::filesystem::exists(filename)) {
|
||||
if (log) {
|
||||
LOG(MarketData,Error,
|
||||
"File {} is not present on this system. "
|
||||
"Please download it from the CME ftp site. "
|
||||
"I will wait until the file is present.\n$ curl {} > {} ",
|
||||
filename, url, filename);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// // For exponential backoff on logging this return true if x is a power of 2 or 0
|
||||
// bool is_pow_two_or_0(uint32_t x) { return (x & (~x + 1)) == x; }
|
||||
// For exponential backoff on logging this return true if x is a power of 2 or 0
|
||||
bool is_pow_two_or_0(uint32_t x) { return (x & (~x + 1)) == x; }
|
||||
|
||||
// void await_cme_config() {
|
||||
// const auto config_url = "ftp://ftp.cmegroup.com/SBEFix/Production/Configuration/config.xml";
|
||||
// const auto templates_url = "ftp://ftp.cmegroup.com/SBEFix/Production/Templates/templates_FixBinary.xml";
|
||||
void await_cme_config() {
|
||||
const auto config_url = "ftp://ftp.cmegroup.com/SBEFix/Production/Configuration/config.xml";
|
||||
const auto templates_url = "ftp://ftp.cmegroup.com/SBEFix/Production/Templates/templates_FixBinary.xml";
|
||||
|
||||
// boost::filesystem::create_directories(data_path());
|
||||
boost::filesystem::create_directories(data_path());
|
||||
|
||||
// // Check config is present and give instructions for downloading it if not
|
||||
// // If the file is not present log an error and wait a second. Continue to log the error ever power of 2 seconds until the file appears or the process is killed.
|
||||
// uint32_t count = 0;
|
||||
// while(!check_file_exists_with_instructions(config_path(), config_url, is_pow_two_or_0(count))) {
|
||||
// ++count;
|
||||
// std::this_thread::sleep_for(1s);
|
||||
// }
|
||||
// count = 0;
|
||||
// while(!check_file_exists_with_instructions(template_path(), templates_url, is_pow_two_or_0(count))) {
|
||||
// ++count;
|
||||
// std::this_thread::sleep_for(1s);
|
||||
// }
|
||||
// Check config is present and give instructions for downloading it if not
|
||||
// If the file is not present log an error and wait a second. Continue to log the error ever power of 2 seconds until the file appears or the process is killed.
|
||||
uint32_t count = 0;
|
||||
while(!check_file_exists_with_instructions(config_path(), config_url, is_pow_two_or_0(count))) {
|
||||
++count;
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
count = 0;
|
||||
while(!check_file_exists_with_instructions(template_path(), templates_url, is_pow_two_or_0(count))) {
|
||||
++count;
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
|
||||
// // If we waited for someone to download the file give it a second to be finished downloading
|
||||
// if (count > 0) {
|
||||
// std::this_thread::sleep_for(1s);
|
||||
// }
|
||||
// }
|
||||
// If we waited for someone to download the file give it a second to be finished downloading
|
||||
if (count > 0) {
|
||||
std::this_thread::sleep_for(1s);
|
||||
}
|
||||
}
|
||||
|
||||
// SecurityType infer_security_type(const string& label) {
|
||||
// if (label.find("Option") != std::string::npos) {
|
||||
// return SECURITYTYPE_OPTION;
|
||||
// }
|
||||
SecurityType infer_security_type(const string& label) {
|
||||
if (label.find("Option") != std::string::npos) {
|
||||
return SECURITYTYPE_OPTION;
|
||||
}
|
||||
|
||||
// if (label.find("Future") != std::string::npos) {
|
||||
// return SECURITYTYPE_FUTURE;
|
||||
// }
|
||||
if (label.find("Future") != std::string::npos) {
|
||||
return SECURITYTYPE_FUTURE;
|
||||
}
|
||||
|
||||
// // TODO: Allow configuration to override this?
|
||||
// LOG(MarketData,Warn,"Unable to guess security type from label: '{}"
|
||||
// "' Treating as OPTION.",label);
|
||||
// return SECURITYTYPE_OPTION;
|
||||
// }
|
||||
// TODO: Allow configuration to override this?
|
||||
LOG(MarketData,Warn,"Unable to guess security type from label: '{}"
|
||||
"' Treating as OPTION.",label);
|
||||
return SECURITYTYPE_OPTION;
|
||||
}
|
||||
|
||||
// const vector<CMEChannel> parse_channels(const vector<UserSymbol>& symbols) {
|
||||
// vector<CMEChannel> result;
|
||||
const vector<CMEChannel> parse_channels(const vector<UserSymbol>& symbols) {
|
||||
vector<CMEChannel> result;
|
||||
|
||||
// pugi::xml_document doc;
|
||||
// bts_assert_msg(doc.load_file(config_path().c_str()), "Error parsing config.xml as xml");
|
||||
pugi::xml_document doc;
|
||||
bts_assert_msg(doc.load_file(config_path().c_str()), "Error parsing config.xml as xml");
|
||||
|
||||
// auto configuration = doc.root().child("configuration");
|
||||
// bts_assert(configuration);
|
||||
auto configuration = doc.root().child("configuration");
|
||||
bts_assert(configuration);
|
||||
|
||||
// LOG(MarketData,Info,"CME: Loaded '{}' config. Last updated: {}" ,
|
||||
// configuration.attribute("environment").as_string(),
|
||||
// configuration.attribute("updated").as_string());
|
||||
// auto channels = configuration.children("channel");
|
||||
// for (const auto& chan : channels) {
|
||||
// CMEChannel channel;
|
||||
// channel.id = chan.attribute("id").as_string();
|
||||
// auto type = infer_security_type(chan.attribute("label").as_string());
|
||||
// if (!(channel.id.empty())) {
|
||||
// auto product_list = chan.child("products").children("product");
|
||||
// for (const auto& product : product_list) {
|
||||
// auto symbol = product.attribute("code").as_string();
|
||||
// for (auto s : symbols) {
|
||||
// if ((s.type() == type || s.type() == SECURITYTYPE_SPREAD) && s.symbol() == symbol) {
|
||||
// channel.symbols.insert(s);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (!channel.symbols.empty()) {
|
||||
// result.push_back(channel);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
LOG(MarketData,Info,"CME: Loaded '{}' config. Last updated: {}" ,
|
||||
configuration.attribute("environment").as_string(),
|
||||
configuration.attribute("updated").as_string());
|
||||
auto channels = configuration.children("channel");
|
||||
for (const auto& chan : channels) {
|
||||
CMEChannel channel;
|
||||
channel.id = chan.attribute("id").as_string();
|
||||
auto type = infer_security_type(chan.attribute("label").as_string());
|
||||
if (!(channel.id.empty())) {
|
||||
auto product_list = chan.child("products").children("product");
|
||||
for (const auto& product : product_list) {
|
||||
auto symbol = product.attribute("code").as_string();
|
||||
for (auto s : symbols) {
|
||||
if ((s.type() == type || s.type() == SECURITYTYPE_SPREAD) && s.symbol() == symbol) {
|
||||
channel.symbols.insert(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!channel.symbols.empty()) {
|
||||
result.push_back(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// return result;
|
||||
// }
|
||||
return result;
|
||||
}
|
||||
|
||||
// }}//namespace
|
||||
// #endif
|
||||
}}//namespace
|
||||
Reference in new issue
Block a user