#ifndef _WIN32 #include "ICEUtils.h" #include "lib/config/config.h" #include "lib/utils/datetime.h" #include "lib/utils/bts_chrono.h" #include "lib/utils/download.h" #include "lib/logging/logging.h" #include "lib/md/get_symbols.h" #include "lib/config/protos/MarketData.pb.h" #include "lib/config/protos/system.pb.h" #include #include using namespace std; 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 += " " + 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 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/"; #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 ice_config_file() { return config::get().ice_config_file(); } const string ice_config_path() { return ice_data_path() + "/" + ice_config_file(); } const std::string ice_log_path() {return log:: 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)) { // download_file(url.c_str(), filename.c_str()); // } if (!boost::filesystem::exists(filename)) { if (log) { LOG(md,Error, "File {} is not present on this system. " "Please download it from the ICE web 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; } void await_ice_config() { std::string config_url; if (config::get().type() != "dev") { config_url = "https://drive.google.com/open?id=13_eyF2pKtn3F7chgsa_75ftUdf7emMbp"; } else { config_url = "https://community.theice.com/docs/DOC-19989"; } boost::filesystem::create_directories(ice_data_path()); boost::filesystem::create_directories(ice_log_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. auto configpath = ice_config_path(); uint32_t count = 0; while(!ice_check_file_exists_with_instructions(configpath, config_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); } } const std::vector get_configured_ice_channels() { std::vector symbols; // Get all ice symbols get_system_md_symbols(api::VENUE_ICE, api::SECURITYTYPE_UNSET, &symbols); return parse_ice_channels(symbols); } }}} //namespace #endif