fix: Resolve onixs log & data dirs relative to app data root

When our logging code moved to lib_system, it lost access to the config
system. As a result, the "log_path" function, which was used by ICEMain
and MDP3Main, broke. I added a new class, SparkDataDirectory, to be the
central/common authority on paths to local storage.
This commit is contained in:
John Colvin committed 2024-10-14 15:51:44 +00:00
1 parent c7f3819b3c
commit c3f88bd505
15 files changed
+378 -215

No files matched your search

@@ -1,7 +1,7 @@
#pragma once
#include "spark/md/coconut2.h"
#include "spark/md/ice/ICEUtils.h"
#include "spark/md/ice/ice_channel.h"
#include "spark/utils/bts_assert.h"
#include "spark/utils/helper_macros.h"
@@ -49,4 +49,4 @@ inline datetime::Date date_of_timestamp(const onixs_ice::DateTime &dt) {
} // namespace ice
} // namespace md
} // namespace bts
} // namespace bts
@@ -1,68 +1,61 @@
#include "ICEMain.h"
#include "spark/config/config.h"
#include "spark/md/SecurityDB.h"
#include "spark/md/coconut2.h"
#include "spark/md/ice/ICEUtils.h"
#include "spark/md/protos/co2.pb.h"
#include "spark/md/vendor/OnixsUtils.h"
#include "spark/utils/Dispatcher.h"
#include "spark/utils/bts_chrono.h"
#include "spark/utils/helper_macros.h"
#include "spark/config/protos/deployment_type.pb.h"
#include "spark/config/protos/market_data.pb.h"
#include "spark/utils/thread_manager.h"
#include "system/os.h"
#include "system/protobufs/proto_helper.h"
#include "spark/md/ice/ICEUtils.h"
#include "spark/md/ice/ice_channel.h"
#include "spark/md/vendor/OnixsUtils.h"
#include "spark/spark_data_directory.h"
#include "system/protobufs/config/system_config.pb.h"
#include <OnixS/ICE/iMpact/MarketData.h>
#include <boost/filesystem.hpp>
#include <memory>
#include <set>
void recursive_copy(
const boost::filesystem::path &src, const boost::filesystem::path &dst) {
if (boost::filesystem::exists(dst))
throw std::runtime_error(dst.generic_string() + " exists");
if (boost::filesystem::is_directory(src)) {
boost::filesystem::create_directories(dst);
for (boost::filesystem::directory_entry &item :
boost::filesystem::directory_iterator(src))
recursive_copy(item.path(), dst / item.path().filename());
} else if (boost::filesystem::is_regular_file(src))
boost::filesystem::copy(src, dst);
else
throw std::runtime_error(dst.generic_string() + " not dir or file");
}
using namespace std;
using namespace bts::co2;
using std::size_t;
namespace bts {
namespace md {
namespace ice {
namespace bts::md::ice {
using bts::system::protobufs::SystemConfig;
using Path = boost::filesystem::path;
ICEMain::ICEMain()
: _index(), _recorder(
{utils::Dispatcher::current(),
[=, this](ExchangeKey k) {
return SecurityKey(_index.get_key(k.value()));
}}),
_producer(_recorder), _handlers(), _listeners() {}
struct ICEMain::PImpl {
ICEOptions options;
std::string config_file;
ICESecurityIndex index;
SecurityIDRecorder recorder;
MDProducer producer;
std::vector<std::pair<ICEChannel, std::unique_ptr<onixs_ice::Handler>>>
handlers;
std::vector<std::unique_ptr<ICEListener>> listeners;
ICEMain::~ICEMain() {}
PImpl(ICEOptions options)
: options(options),
config_file((Path{config::get<SystemConfig>().data_path()} /
"onixs_ice" / this->options.ice_config_file())
.string()),
index(), recorder(
{utils::Dispatcher::current(),
[=, this](ExchangeKey k) {
return SecurityKey(index.get_key(k.value()));
}}),
producer(recorder), handlers(), listeners() {}
const IceChannelConfig channel_settings_for(const ICEChannel &channel) {
const auto &config = config::get<ICEOptions>();
for (const auto &ch : config.channel()) {
if (ch.name() == channel.name)
return ch;
IceChannelConfig channel_settings_for(const ICEChannel &channel) {
for (const auto &ch : options.channel()) {
if (ch.name() == channel.name)
return ch;
}
return {};
}
return {};
};
ICEMain::ICEMain(ICEOptions options)
: me_(std::make_unique<PImpl>(std::move(options))) {
me_->options = std::move(options);
}
onixs_ice::MarketSubscriptions market_subcription_for_channel(
@@ -90,23 +83,30 @@ onixs_ice::MarketSubscriptions market_subcription_for_channel(
return subs;
}
void ICEMain::start(const std::vector<UserSymbol> &symbols) {
auto ice_conf_location =
Path{config::get<SystemConfig>().data_path()} / "onixs_ice/";
if (!boost::filesystem::is_directory(ice_conf_location)) {
auto conf_path = Path{os::sparkd_wd()} / "data_files" / "onixs_ice/";
recursive_copy(Path{conf_path}, ice_conf_location);
static void validate_config_file(const std::string &config_file) {
if (!boost::filesystem::exists(config_file)) {
const std::string config_url =
config::get<config::DeploymentType>().type() == "dev"
? "https://community.theice.com/docs/DOC-19989"
: "https://drive.google.com/"
"open?id=13_eyF2pKtn3F7chgsa_75ftUdf7emMbp";
bts_assert_msgf(
false, "Ice config file not found '{}'. Please download from {}",
config_file, config_url);
}
}
void ICEMain::start(const std::vector<UserSymbol> &symbols) {
await_ice_config();
validate_config_file(me_->config_file);
auto license = onixs_create_temporary_license();
const auto &channels = parse_ice_channels(symbols);
const auto &channels = ICEChannel::parse_all(symbols);
for (const auto &channel : channels) {
unique_ptr<onixs_ice::Handler> phandler =
prepare_handler(channel, license.path.string());
_listeners.push_back(prepare_listener(*phandler, channel));
_handlers.push_back(std::make_pair(channel, std::move(phandler)));
me_->listeners.push_back(prepare_listener(*phandler, channel));
me_->handlers.push_back(std::make_pair(channel, std::move(phandler)));
std::stringstream symstr;
for (const auto &sym : channel.symbols)
@@ -115,7 +115,7 @@ void ICEMain::start(const std::vector<UserSymbol> &symbols) {
symstr.str());
}
for (auto &pair : _handlers) {
for (auto &pair : me_->handlers) {
LOG(md, Info, "ICE: Init Handler {}", pair.first.to_string());
sleep_for(16s);
onixs_ice::MarketSubscriptions subs =
@@ -132,7 +132,7 @@ void ICEMain::start(const std::vector<UserSymbol> &symbols) {
}
void ICEMain::send_heartbeats() {
for (const auto &listener : _listeners)
for (const auto &listener : me_->listeners)
listener->heartbeat();
}
@@ -140,20 +140,16 @@ void ICEMain::send_heartbeats() {
// Initialize HandlerSettings and allocate the channel Handler
unique_ptr<onixs_ice::Handler> ICEMain::prepare_handler(
const ICEChannel &channel, const std::string &license) {
const auto &options = channel_settings_for(channel);
const auto &options = me_->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;
//
// Logging
settings.logLevel = (onixs_ice::LogLevels::Enum)options.onixs_log_mode();
settings.logDirectory = ice_log_path();
//
// Config file
settings.connectivityConfiguration = ice_config_path();
settings.logDirectory =
(spark::SparkDataDirectory{}.log_dir() / "onixs_ice/").string();
settings.connectivityConfiguration = me_->config_file;
//
// Network settings
@@ -231,12 +227,12 @@ unique_ptr<ICEListener> ICEMain::prepare_listener(
// heartbeats
vector<MDProducerChannel> producer_channels;
for (auto &symbol : channel.symbols) {
producer_channels.push_back(_producer.get_channel(
producer_channels.push_back(me_->producer.get_channel(
symbol.symbol().c_str(), symbol.type(), symbol.exchange()));
}
unique_ptr<ICEListener> listener(new ICEListener(
_index, _producer, /*_settlement_recorder,*/ producer_channels));
me_->index, me_->producer, /*_settlement_recorder,*/ producer_channels));
for (auto &symbol : channel.symbols)
listener->add_filter_symbol(symbol.symbol());
@@ -254,6 +250,4 @@ unique_ptr<ICEListener> ICEMain::prepare_listener(
return listener;
}
} // namespace ice
} // namespace md
} // namespace bts
} // namespace bts::md::ice
@@ -1,21 +1,13 @@
#pragma once
#include "ICEListener.h"
#include "ICESecurityIndex.h"
#include "spark/md/coconut2.h"
#include "spark/utils/bts_no_copy.h"
#include "onixs.h"
#include "spark/config/protos/market_data.pb.h"
#include "sparkd/md/platforms/IMDPlatform.h"
#include <map>
#include <memory>
#include <vector>
namespace bts {
namespace md {
namespace ice {
// void run_onixs_ice_server(UserSymbol* sym, size_t symcount);
namespace bts::md::ice {
struct ICEChannel;
@@ -28,27 +20,22 @@ struct ICEChannel;
class ICEMain : public IMDPlatform {
public:
ICEMain();
~ICEMain();
explicit ICEMain(ICEOptions options);
ICEMain(const ICEMain &) = delete;
ICEMain &operator=(const ICEMain &) = delete;
~ICEMain() = default;
void start(const std::vector<UserSymbol> &symbols);
void send_heartbeats() override;
std::unique_ptr<onixs_ice::Handler>
prepare_handler(const ICEChannel &channel, const std::string &license);
std::unique_ptr<ICEListener>
prepare_listener(onixs_ice::Handler &handler, const ICEChannel &channel);
std::unique_ptr<onixs_ice::Handler> prepare_handler(
const ICEChannel &channel, const std::string &license);
std::unique_ptr<ICEListener> prepare_listener(
onixs_ice::Handler &handler, const ICEChannel &channel);
private:
BTS_NO_COPY(ICEMain);
ICESecurityIndex _index;
SecurityIDRecorder _recorder;
MDProducer _producer;
std::vector<std::pair<ICEChannel, std::unique_ptr<onixs_ice::Handler>>>
_handlers;
std::vector<std::unique_ptr<ICEListener>> _listeners;
struct PImpl;
std::unique_ptr<PImpl> me_;
};
} // namespace ice
} // namespace md
} // namespace bts
} // namespace bts::md::ice
@@ -1,24 +1,20 @@
#include "MDP3Main.h"
#include "domain/protobufs/trading_status.pb.h"
#include "spark/config/config.h"
#include "spark/config/protos/deployment_type.pb.h"
#include "spark/md/MBOProcessor.h"
#include "spark/md/SecurityDB.h"
#include "spark/md/cme/MDP3Utils.h"
#include "spark/md/coconut2.h"
#include "spark/md/protos/co2.pb.h"
#include "spark/md/cme/mdp3_data_directory.h"
#include "spark/md/vendor/OnixsUtils.h"
#include "spark/utils/Dispatcher.h"
#include "spark/config/protos/market_data.pb.h"
#include "spark/spark_data_directory.h"
#include "spark/utils/thread_manager.h"
#include "system/logging/logging.h"
#include "system/os.h"
#include "system/protobufs/proto_helper.h"
#include <boost/filesystem.hpp>
#include <memory>
#include <optional>
#include <set>
#include <sstream>
@@ -31,16 +27,32 @@ namespace md {
#define TRADING_STATUS(x) bts::domain::protobufs::TRADINGSTATUS_##x
MDP3Main::MDP3Main()
: _index(), _recorder(
{utils::Dispatcher::current(),
[=, this](ExchangeKey k) {
return SecurityKey(_index.get_key(k.value()));
}}),
_producer(_recorder), _engines(), _handlers(), _listeners(), _recovery() {
}
using Path = boost::filesystem::path;
MDP3Main::~MDP3Main() {}
struct MDP3Main::PImpl {
boost::filesystem::path data_path;
boost::filesystem::path log_path;
CMESecurityIndex index;
SecurityIDRecorder recorder;
MDProducer producer;
std::map<std::string, std::unique_ptr<onixs::FeedEngine>> engines;
std::map<std::string, std::unique_ptr<onixs::Handler>> handlers;
std::vector<std::unique_ptr<MDP3Listener>> listeners;
std::vector<std::unique_ptr<onixs::TcpRecoveryService>> recovery;
PImpl()
: data_path(spark::SparkDataDirectory{}.root() / "cme_mdp3/"),
log_path(spark::SparkDataDirectory{}.log_dir() / "onixs/"), index(),
recorder(
{utils::Dispatcher::current(),
[=, this](ExchangeKey k) {
return SecurityKey(index.get_key(k.value()));
}}),
producer(recorder), engines(), handlers(), listeners(), recovery() {}
};
MDP3Main::MDP3Main() : me_(std::make_unique<PImpl>()) {}
MDP3Main::~MDP3Main() = default;
const CmeChannelConfig channel_settings_for(const string &id) {
const auto &config = config::get<CMEOptions>();
@@ -162,24 +174,53 @@ onixs::SessionSettings session_settings_for_channel(
return settings;
}
static void validate_config_file(const std::string &config_file) {
if (!boost::filesystem::exists(config_file)) {
const bool is_dev = config::get<config::DeploymentType>().type() == "dev";
const std::string config_url =
is_dev ? "ftp://ftp.cmegroup.com/SBEFix/Cert/Configuration/config.xml"
: "ftp://ftp.cmegroup.com/SBEFix/Production/Configuration/"
"config.xml";
bts_assert_msgf(
false, "MDP3 config file not found '{}'. Please download from {}",
config_file, config_url);
}
}
static void validate_templates_file(const std::string &templates_file) {
if (!boost::filesystem::exists(templates_file)) {
const bool is_dev = config::get<config::DeploymentType>().type() == "dev";
const std::string templates_url =
is_dev ? "ftp://ftp.cmegroup.com/SBEFix/Cert/Templates/"
"templates_FixBinary.xml"
: "ftp://ftp.cmegroup.com/SBEFix/Cert/Templates/"
"templates_FixBinary.xml";
bts_assert_msgf(
false, "MDP3 templates file not found '{}'. Please download from {}",
templates_file, templates_url);
}
}
void MDP3Main::start(
const std::vector<UserSymbol> &symbols,
MBOWriter *mbo,
TradeSummarySignalDispatcher *tssd) {
Mdp3DataDirectory data_dir;
validate_config_file(data_dir.config_file().string());
validate_templates_file(data_dir.templates_file().string());
std::ostringstream oss;
for (const auto &us : symbols) {
oss << us << " ";
}
LOG(md, Info, "MDP3Main::start symbols: {}", oss.str());
await_cme_config();
auto license = onixs_create_temporary_license();
initialize(license.path.string());
const auto &channels = parse_channels(symbols);
_engines = create_feed_engines(channels);
me_->engines = create_feed_engines(channels);
for (const auto &channel : channels) {
unique_ptr<onixs::Handler> phandler = prepare_handler(channel.id, mbo);
_listeners.push_back(prepare_listener(*phandler, channel, mbo, tssd));
_handlers.insert(std::make_pair(channel.id, std::move(phandler)));
me_->listeners.push_back(prepare_listener(*phandler, channel, mbo, tssd));
me_->handlers.insert(std::make_pair(channel.id, std::move(phandler)));
std::stringstream symstr;
for (const auto &sym : channel.symbols) {
symstr << sym.symbol() << "-" << SecurityType_Name(sym.type()) << " ";
@@ -188,7 +229,7 @@ void MDP3Main::start(
symstr.str());
}
for (auto &pair : _handlers) {
for (auto &pair : me_->handlers) {
onixs::SessionSettings settings =
session_settings_for_channel(pair.first, mbo);
pair.second->start(settings);
@@ -198,7 +239,7 @@ void MDP3Main::start(
}
void MDP3Main::send_heartbeats() {
for (const auto &listener : _listeners) {
for (const auto &listener : me_->listeners) {
listener->heartbeat();
}
}
@@ -221,7 +262,8 @@ unique_ptr<onixs::Handler> MDP3Main::prepare_handler(
onixs::HandlerSettings settings;
settings.channel(std::stoul(channel_id));
settings.feeds().connectivityConfigurationFile(config_path());
settings.feeds().connectivityConfigurationFile(
(me_->data_path / "config.xml").string());
// Market data options
settings.bookManagement().directBooks().maintain(true);
@@ -308,7 +350,7 @@ unique_ptr<onixs::Handler> MDP3Main::prepare_handler(
logger = new onixs::NullLogger();
} else {
onixs::FileLoggerSettings loggerSettings;
loggerSettings.filename(log_path() + "/log_" + channel_id);
loggerSettings.filename((me_->log_path / ("log_" + channel_id)).string());
loggerSettings.severityLevel(
(onixs::LogSeverity::Enum)options.onixs_log_mode());
logger = new onixs::FileLogger(loggerSettings);
@@ -340,19 +382,19 @@ unique_ptr<onixs::Handler> MDP3Main::prepare_handler(
try {
auto handler = unique_ptr<onixs::Handler>(new onixs::Handler(settings));
auto iter = _engines.find(options.feed_engine());
if (iter == _engines.end()) {
auto iter = me_->engines.find(options.feed_engine());
if (iter == me_->engines.end()) {
LOG(md, Fatal,
"Missing feed engine definition '{}' for channel id '{}'. Add a "
"feed_engine entry with name:'{}' to the CMEOptions config key.",
options.feed_engine(), channel_id, options.feed_engine());
bts_assert_msg(
iter != _engines.end(), "Missing feed engine definition.");
iter != me_->engines.end(), "Missing feed engine definition.");
}
handler->bindFeedEngine(*(iter->second));
if (recovery) {
handler->bindTcpRecovery(*recovery);
_recovery.push_back(std::move(recovery));
me_->recovery.push_back(std::move(recovery));
}
if (logger) {
handler->bindLogger(*logger);
@@ -377,12 +419,13 @@ unique_ptr<MDP3Listener> MDP3Main::prepare_listener(
// heartbeats
vector<MDProducerChannel> producer_channels;
for (auto &symbol : channel.symbols) {
producer_channels.push_back(_producer.get_channel(
producer_channels.push_back(me_->producer.get_channel(
symbol.symbol().c_str(), symbol.type(), symbol.exchange()));
}
unique_ptr<MDP3Listener> listener(new MDP3Listener(
_index, _producer, mbo, producer_channels, trade_summary_dispatcher));
me_->index, me_->producer, mbo, producer_channels,
trade_summary_dispatcher));
for (auto &symbol : channel.symbols) {
listener->add_filter_symbol(symbol.symbol());
}
@@ -2,9 +2,9 @@
#include "CMESecurityIndex.h"
#include "MDP3Listener.h"
#include "onixs.h"
#include "spark/md/coconut2.h"
#include "spark/utils/bts_no_copy.h"
#include "onixs.h"
#include "sparkd/md/platforms/IMDPlatform.h"
#include <map>
@@ -29,7 +29,10 @@ struct CMEChannel;
*/
class MDP3Main : public IMDPlatform {
public:
MDP3Main();
MDP3Main();
explicit MDP3Main(const std::string &data_path, const std::string &log_path);
MDP3Main(const MDP3Main &) = delete;
MDP3Main &operator=(const MDP3Main &) = delete;
~MDP3Main();
void start(
@@ -39,8 +42,8 @@ class MDP3Main : public IMDPlatform {
void send_heartbeats() override;
void initialize(const std::string &license_store);
std::unique_ptr<onixs::Handler>
prepare_handler(const std::string &channel, MBOWriter *);
std::unique_ptr<onixs::Handler> prepare_handler(
const std::string &channel, MBOWriter *);
std::unique_ptr<MDP3Listener> prepare_listener(
onixs::Handler &handler,
const CMEChannel &channel,
@@ -48,16 +51,8 @@ class MDP3Main : public IMDPlatform {
TradeSummarySignalDispatcher *);
private:
BTS_NO_COPY(MDP3Main);
CMESecurityIndex _index;
SecurityIDRecorder _recorder;
MDProducer _producer;
// co2::SettlementRecorder _settlement_recorder;
std::map<std::string, std::unique_ptr<onixs::FeedEngine>> _engines;
std::map<std::string, std::unique_ptr<onixs::Handler>> _handlers;
std::vector<std::unique_ptr<MDP3Listener>> _listeners;
std::vector<std::unique_ptr<onixs::TcpRecoveryService>> _recovery;
struct PImpl;
std::unique_ptr<PImpl> me_;
};
} // namespace md
+11 -22
View File
@@ -5,18 +5,15 @@
#include "spark/config/protos/deployment_type.pb.h"
#include "spark/config/protos/market_data.pb.h"
#include "spark/md/SymbolLoader.h"
#include "spark/utils/bts_chrono.h"
#include "spark/utils/datetime.h"
#include "spark/md/cme/mdp3_data_directory.h"
#include "spark/utils/download.h"
#include "system/FMT.h"
#include "system/logging/logging.h"
#include "system/protobufs/config/system_config.pb.h"
#include <boost/filesystem.hpp>
#include <iostream>
#include <mutex>
#include <pugixml/pugixml.hpp>
#include <sstream>
#include <thread>
using namespace std;
using namespace bts::api;
@@ -25,16 +22,6 @@ namespace bts {
namespace md {
using bts::domain::SecurityCriteria;
using bts::system::protobufs::SystemConfig;
string data_path() {
auto p = config::get<SystemConfig>().data_path() + "cme_mdp3/";
os::normalize_path(p);
return p;
}
const string config_path() { return data_path() + "config.xml"; }
const string template_path() { return data_path() + "templates.xml"; }
const std::string log_path() { return logging::log_path().string() + "/onix"; }
bool check_file_exists_with_instructions(
const string &filename, const string &url, bool log) {
@@ -75,8 +62,9 @@ void await_cme_config() {
"templates_FixBinary.xml";
}
boost::filesystem::create_directories(data_path());
boost::filesystem::create_directories(log_path());
Mdp3DataDirectory data_dir;
boost::filesystem::create_directories(data_dir.data_dir());
boost::filesystem::create_directories(data_dir.log_dir());
// 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
@@ -84,13 +72,14 @@ void await_cme_config() {
// killed.
uint32_t count = 0;
while (!check_file_exists_with_instructions(
config_path(), config_url, is_pow_two_or_0(count))) {
data_dir.config_file().string(), 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))) {
data_dir.templates_file().string(), templates_url,
is_pow_two_or_0(count))) {
++count;
std::this_thread::sleep_for(1s);
}
@@ -133,14 +122,14 @@ std::string to_str(const std::vector<T> &vec) {
return ss.str();
}
const vector<CMEChannel> parse_channels(const vector<UserSymbol> &symbols) {
Mdp3DataDirectory data_dir{};
LOG(md, Info, "parse_channels symbols: {}", FMT_JOIN(symbols, ", "));
await_cme_config();
vector<CMEChannel> result;
bool skip_options = config::get<PublisherOptions>().skip_options();
pugi::xml_document doc;
bts_assert_msg(
doc.load_file(config_path().c_str()), "Error parsing config.xml as xml");
doc.load_file(data_dir.config_file().c_str()),
"Error parsing config.xml as xml");
auto configuration = doc.root().child("configuration");
bts_assert(configuration);
+2 -9
View File
@@ -1,24 +1,17 @@
#pragma once
#include "spark/md/Shm/FixedSecurity.h"
#include "spark/md/cme/CMEChannel.h"
#include "spark/md/cme/CMEConnection.h"
#include "spark/md/coconut2.h"
#include "system/FMT_IMPL.h"
#include <set>
#include <string>
#include <vector>
namespace bts::md {
void await_cme_config();
const std::vector<CMEChannel> get_configured_cme_channels();
const std::vector<CMEChannel> parse_channels(
const std::vector<UserSymbol> &symbols);
const std::string config_path();
const std::string template_path();
const std::string log_path();
//https://www.cmegroup.com/confluence/display/EPICSANDBOX/MDP%203.0%20-%20CME%20Globex%20Pricing
inline void decode_ticks(int vtt, double mintick, FixedSecurity &dest) {
switch (vtt) {
@@ -0,0 +1,32 @@
#pragma once
#include "spark/spark_data_directory.h"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
namespace bts::md {
struct Mdp3DataDirectory {
boost::filesystem::path log_dir() const { return root.log_dir() / "onixs"; }
boost::filesystem::path data_dir() const { return root.root() / "cme_mdp3"; }
boost::filesystem::path config_file() const {
return data_dir() / "config.xml";
}
boost::filesystem::path templates_file() const {
return data_dir() / "templates.xml";
}
void create_dirs() {
boost::filesystem::create_directories(data_dir());
boost::filesystem::create_directories(log_dir());
}
private:
spark::SparkDataDirectory root{};
};
} // namespace bts::md
+10 -34
View File
@@ -4,6 +4,7 @@
#include "domain/security_criteria.h"
#include "spark/config/config.h"
#include "spark/md/SymbolLoader.h"
#include "spark/md/ice/ice_data_directory.h"
#include "spark/utils/bts_chrono.h"
#include "spark/utils/datetime.h"
#include "spark/utils/download.h"
@@ -24,25 +25,15 @@ namespace md {
namespace ice {
using bts::domain::SecurityCriteria;
using bts::system::protobufs::SystemConfig;
std::string ICEChannel::to_string() const {
std::string mt = name;
for (const auto &x : market_types)
mt += " " + std::to_string(x);
for (const auto &x : uds_market_types)
mt += " " + std::to_string(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<ICEChannel> parse_ice_channels(const vector<UserSymbol> &symbols) {
const vector<ICEChannel> parse_ice_channels(
const vector<UserSymbol> &symbols, const ICEOptions &ice_options) {
vector<ICEChannel> result;
const auto &ice_options = config::get<bts::md::ICEOptions>();
for (const auto &x : ice_options.channel()) {
md::ice::ICEChannel chan;
chan.name = x.name();
@@ -57,22 +48,6 @@ const vector<ICEChannel> parse_ice_channels(const vector<UserSymbol> &symbols) {
return result;
}
string ice_data_path() {
auto p = config::get<SystemConfig>().data_path() + "onixs_ice/";
os::normalize_path(p);
return p;
}
const string ice_config_file() {
return config::get<bts::md::ICEOptions>().ice_config_file();
}
const string ice_config_path() {
return ice_data_path() + "/" + ice_config_file();
}
const std::string ice_log_path() {
return logging::log_path().string() + "/onix_ice";
}
bool ice_check_file_exists_with_instructions(
const string &filename, const string &url, bool log) {
// if (!boost::filesystem::exists(filename)) {
@@ -104,14 +79,15 @@ void await_ice_config() {
config_url = "https://community.theice.com/docs/DOC-19989";
}
boost::filesystem::create_directories(ice_data_path());
boost::filesystem::create_directories(ice_log_path());
IceDataDirectory data_dir;
boost::filesystem::create_directories(data_dir.data_dir());
boost::filesystem::create_directories(data_dir.log_dir());
// 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.
auto configpath = ice_config_path();
const auto configpath = data_dir.config_file().string();
uint32_t count = 0;
while (!ice_check_file_exists_with_instructions(
configpath, config_url, is_pow_two_or_0(count))) {
@@ -127,9 +103,9 @@ void await_ice_config() {
const std::vector<ICEChannel> get_configured_ice_channels() {
// Get all ice symbols
const auto symbols =
SymbolLoader::load(SecurityCriteria::create({domain::protobufs::VENUE_ICE}));
return parse_ice_channels({symbols.begin(), symbols.end()});
const auto symbols = SymbolLoader::load(
SecurityCriteria::create({domain::protobufs::VENUE_ICE}));
return ICEChannel::parse_all({symbols.begin(), symbols.end()});
}
} // namespace ice
+11 -9
View File
@@ -1,6 +1,8 @@
#pragma once
#include "spark/md/coconut2.h"
#include "spark/md/ice/ice_channel.h"
#include <set>
#include <string>
#include <vector>
@@ -9,18 +11,18 @@ namespace bts {
namespace md {
namespace ice {
struct ICEChannel {
std::string name;
std::vector<uint32_t> market_types;
std::vector<uint32_t> uds_market_types;
std::set<UserSymbol> symbols;
std::string to_string() const;
};
// struct ICEChannel {
// std::string name;
// std::vector<uint32_t> market_types;
// std::vector<uint32_t> uds_market_types;
// std::set<UserSymbol> symbols;
// std::string to_string() const;
// };
void await_ice_config();
const std::vector<ICEChannel> get_configured_ice_channels();
const std::vector<ICEChannel>
parse_ice_channels(const std::vector<UserSymbol> &symbols);
// const std::vector<ICEChannel> parse_ice_channels(
// const std::vector<UserSymbol> &symbols);
const std::string ice_config_path();
const std::string ice_log_path();
@@ -0,0 +1,39 @@
#include "ice_channel.h"
#include "spark/config/config.h"
#include "spark/config/protos/market_data.pb.h"
namespace bts::md::ice {
std::string ICEChannel::to_string() const {
std::string mt = name;
for (const auto &x : market_types)
mt += " " + std::to_string(x);
for (const auto &x : uds_market_types)
mt += " " + std::to_string(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
std::vector<ICEChannel> ICEChannel::parse_all(
const std::vector<UserSymbol> &symbols) {
std::vector<ICEChannel> result;
const auto &ice_options = config::get<bts::md::ICEOptions>();
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);
for (const auto &xx : x.uds_market_type())
chan.uds_market_types.push_back(xx);
result.push_back(chan);
}
return result;
}
} // namespace bts::md::ice
+23
View File
@@ -0,0 +1,23 @@
#pragma once
#include "spark/md/UserSymbol.h"
#include <cstdint>
#include <set>
#include <string>
#include <vector>
namespace bts::md::ice {
struct ICEChannel {
std::string name;
std::vector<uint32_t> market_types;
std::vector<uint32_t> uds_market_types;
std::set<UserSymbol> symbols;
std::string to_string() const;
static std::vector<ICEChannel> parse_all(
const std::vector<UserSymbol> &symbols);
};
} // namespace bts::md::ice
@@ -0,0 +1,36 @@
#pragma once
#include "spark/spark_data_directory.h"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
namespace bts::md {
struct IceDataDirectory {
boost::filesystem::path log_dir() const {
return root.log_dir() / "onixs_ice/";
}
boost::filesystem::path data_dir() const {
return root.root() / "onixs_ice/";
}
boost::filesystem::path config_file() const {
return data_dir() / "config.xml";
}
boost::filesystem::path templates_file() const {
return data_dir() / "templates.xml";
}
void create_dirs() {
boost::filesystem::create_directories(data_dir());
boost::filesystem::create_directories(log_dir());
}
private:
spark::SparkDataDirectory root{};
};
} // namespace bts::md
@@ -0,0 +1,31 @@
#include "spark_data_directory.h"
#include "spark/config/config.h"
#include "system/protobufs/config/system_config.pb.h"
#include <boost/filesystem/path.hpp>
#include <fmt/format.h>
#include <string>
namespace bts::spark {
SparkDataDirectory::SparkDataDirectory()
: SparkDataDirectory(
config::get<system::protobufs::SystemConfig>().data_path()) {}
SparkDataDirectory::SparkDataDirectory(const std::string &root) : root_(root) {}
boost::filesystem::path SparkDataDirectory::root() const { return root_; }
boost::filesystem::path SparkDataDirectory::log_dir() const {
return root_ / "logging";
}
boost::filesystem::path SparkDataDirectory::log_file() const {
return log_dir() / "log";
}
boost::filesystem::path SparkDataDirectory::log_cache_file() const {
return log_dir() / "log_cache";
}
} // namespace bts::spark
@@ -0,0 +1,23 @@
#pragma once
#include <boost/filesystem/path.hpp>
#include <string>
namespace bts::spark {
class SparkDataDirectory {
public:
SparkDataDirectory();
explicit SparkDataDirectory(const std::string &root);
boost::filesystem::path root() const;
boost::filesystem::path log_dir() const;
boost::filesystem::path log_file() const;
boost::filesystem::path log_cache_file() const;
private:
boost::filesystem::path root_;
};
} // namespace bts::spark