#include "run_md.h" #include "lib/md/relay/RelayRecorder.h" #include "lib/md/PlatformLoader.h" #include "lib/md/relay/RelayRecorder.h" #include "lib/utils/bts_assert.h" #include "lib/config/config.h" #include "lib/config/protos/MarketData.pb.h" #include "lib/logging/logging.h" #include #include #include using namespace bts; using namespace md; using namespace md2; void clean_dir(const std::string base_path) { LOG(MarketData, Info, "Cleaning shared memory"); namespace fs = boost::filesystem; const fs::path p(base_path); auto file_prefix = "bts_edge_" + config::get().shared_memory_namespace() + "_"; if (fs::is_directory(p)) { fs::directory_iterator end_iter; for (fs::directory_iterator dir_iter(p); dir_iter != end_iter; ++dir_iter) { if (fs::is_regular_file(dir_iter->status())) { auto name = dir_iter->path().filename().string(); if (name.find(file_prefix) != std::string::npos) { boost::system::error_code err; fs::remove(dir_iter->path(), err); if (!err) LOG(MarketData, Info, "Cleaned up {}", dir_iter->path()); } } else if (fs::is_directory(dir_iter->status())) { std::string path = dir_iter->path().string(); clean_dir(path); } } } } void run_relay() { auto naggle_ms = config::get().naggle_ms(); auto file = "http://mdreplay/spark/futures.coconut"; replay_recording(file, naggle_ms); } std::thread* _md_thread; void run_market_datapublishers() { bts_assert(_md_thread == nullptr); // start a thread for the md _md_thread = new std::thread([]() { os::set_thread_name("md publisher"); clean_dir("/dev/shm"); // just relay for now. More coming soon run_relay(); }); } void run_recorder(const char* path, const char* filename) { run_market_datapublishers(); record_everything(path, filename); }