#include "QuickTest.h" #include "ICmd.h" #include "lib/config/config.h" #include "lib/config/protos/orders_fills_cleanup.pb.h" #include "lib/orderman/orders/algo/IAlgoServices.h" #include "lib/tracing/PerfLog.h" #include "lib/utils/datetime.h" #include "lib/config/protos/logging.pb.h" #include "lib/domain_model/sod.h" #include "lib/logging/logging.h" #include "lib/utils/datetime.h" #include "server/sparkd/cmds/spartan/analysis/RunAnalysis.h" #include "server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h" #include "server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h" #include "server/sparkd/cmds/spartan/md/mdp3/feed_control/AB_Arbitrageur.h" #include "server/sparkd/cmds/spartan/md/mdp3/feed_control/IFeedController.h" #include "server/sparkd/cmds/spartan/md/mdp3/handler/ChannelHandler.h" #include "server/sparkd/cmds/spartan/md/mdp3/handler/IChannelObserver.h" #include "server/sparkd/cmds/spartan/md/mdp3/parsing/MDP3Parser.h" #include "server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.h" #include "server/sparkd/cmds/spartan/util/PCapReader.h" #include #include #include #include #include namespace bts { namespace cmd { using namespace bts::orderman; using namespace spartan::mdp3; using namespace spartan; struct TimeWriter { mdp3::MDP3PacketView packet; void on_begin_packet(mdp3::MDP3PacketView const &p) { packet = p; } void on_end_packet() { std::cout << packet.sending_time() << std::endl; } template void operator()(M const &) { } }; void print_times(std::string const &file) { struct PacketBuffers { spartan::mdp3::MDP3Packet i; spartan::mdp3::MDP3Packet n; }; auto feed_map = spartan::mdp3::guess_feed_map(file); bts_assert(feed_map); auto reader = PCapReader{file}; mdp3::AB_Arbitrageur ab; reader.on_packet() = [&](auto const &info, auto const &payload) { if ((info.dst_ip == feed_map.incremental[0].ip && info.dst_port == feed_map.incremental[0].port)) { TimeWriter tw; parse_packet(MDP3PacketView {payload},tw); } return true; }; while (reader.read_next()) ; } int QuickTest::execute(std::vector const &args) { auto cfg = config::get(); cfg.mutable_console()->set_default_level("Fatal"); log::configure_logging(cfg); auto file = args[0]; print_times(file); return 0; using namespace bts::spartan::mdp3; struct Obs : IChannelObserver { void on_recovery_complete( std::vector const &secs) override { for (auto s : secs) { std::cout << "Bootstrap -----------------------------------------" "------------------------------" << std::endl; std::cout << "Symbol: " << s->definition().symbol() << std::endl << "Status: " << s->trading_status() << std::endl << "Orders:\n" << s->orders(); } } void on_real_time_event(MDP3Event const &ev) override { for (auto s : ev.affected_securities) { if (s->order_changes().size() || s->fills().size()) { std::cout << "Event " << ev.transact_time << " -----------------------------" << std::endl; std::cout << "Symbol: " << s->definition().symbol() << std::endl << "Status: " << s->trading_status() << std::endl << "Seq Num: " << ev.first_packet_sn << " to " << ev.last_packet_sn << std::endl << "Orders:\n" << s->order_changes() << "Fills:\n" << s->fills(); } } } void on_real_time_channel_loss() override { std::cout << "Observed loss, resetting\n"; } } obs; spartan::observe_channel(file, obs); return 0; } std::string QuickTest::help() { return "This is a place holder to make it easy to quickly write " "discardable " "test code"; } } // namespace cmd } // namespace bts