diff --git a/src/lib/orderman/actors/ilink3/SessionStore.cpp b/src/lib/orderman/actors/ilink3/SessionStore.cpp index b25224d7a..e36d54fc0 100644 --- a/src/lib/orderman/actors/ilink3/SessionStore.cpp +++ b/src/lib/orderman/actors/ilink3/SessionStore.cpp @@ -1,12 +1,13 @@ #include "SessionStore.h" #include "lib/orderman/actors/ilink3/ILinkGW.h" #include "lib/orderman/orderman_utils/ExecutionReport.h" +#include "lib/utils/base64.hpp" #include "lib/utils/bts_chrono.h" #include "lib/utils/file_utils.h" #include "lib/utils/thread_manager.h" -#include "lib/utils/base64.hpp" #include +#include #include #include @@ -46,40 +47,42 @@ static std::vector load_replay(md::SecurityOracle &, config::JetFIX::Connection const &cfg, std::string const &path) { std::vector result; - if (boost::filesystem::exists(path)) { - std::ifstream f(path); - std::string line_buffer; - line_buffer.reserve(10 * 1024); - std::string date_buffer("20150427-19:05:17.032"); + if (boost::filesystem::exists(path)) { + + std::ifstream f(path); + nlohmann::json j; for (;;) { - std::getline(f, line_buffer); - if (!f.eof()) { - if (line_buffer[22] == '<') { - auto ts = - datetime::parse_FIX_timestamp(line_buffer.substr(0, 21)); + while (!f.eof() && f.get() != '{') + ; + if (f.eof()) + break; + else { + f.unget(); + f >> j; + if (j["direction"] == "<") { + auto ts = datetime::parse_FIX_timestamp(j["time"]); if (!datetime::is_at_least_secs_old(ts, cfg.seconds_to_replay())) { - // figure out if its an execution report and if so - // load it - // il3executionreportparser.h::parse_report + } } - } else - break; + } } } + return result; } static void save_raw_msg(std::ofstream &out, RawMessageDirection d, RawMessageData const &msg) { - out << datetime::FIX_timestamp(datetime::now()) << " " - << (d == RawMessageDirection::OUTGOING ? ">" : "<") << " "; - out.write(msg.json.data(), msg.json.size()); - auto encoded = websocketpp::base64_encode(msg.binary); - out.write(encoded.data(), encoded.size()); - out << std::endl; + nlohmann::json j; + j["direction"] = d == RawMessageDirection::INCOMING ? "<" : ">"; + j["time"] = datetime::FIX_timestamp(datetime::now()); + j["msg_sbe"] = websocketpp::base64_encode(msg.binary); + j["msg_json"] = nlohmann::json::parse(msg.json); + out << j << std::endl; + out.flush(); } void save_session(std::string const &path, Session const &session) { @@ -88,8 +91,9 @@ void save_session(std::string const &path, Session const &session) { } Session load_session(std::string const &path) { - auto result = Session{ 0, 1, 0}; - bts_assert_msg(result.uuid != 0, "todo: Determine session from current date/time"); + auto result = Session{0, 1, 0}; + bts_assert_msg(result.uuid != 0, + "todo: Determine session from current date/time"); if (boost::filesystem::exists(path)) { Session result; std::ifstream f(path);