This commit is contained in:
Pedro Pinto committed 2020-04-29 13:16:16 -04:00
1 parent aa6d453d5b
commit 3e817d4fb0
81 files changed
+249 -228

No files matched your search

+62 -32
View File
@@ -5,13 +5,15 @@
#include "lib/config/protos/spartan.pb.h"
#include "lib/logging/logging.h"
#include "lib/md/cme/MDP3Utils.h"
#include "server/sparkd/cmds/spartan_tas/algo/TASOrderReactor.h"
#include "server/sparkd/cmds/spartan_tas/algo/TASTriggerDef.h"
#include "server/sparkd/cmds/spartan_tas/util/MCastReceiver.h"
#include "server/sparkd/cmds/spartan_tas/util/MDPParser.h"
#include "server/sparkd/cmds/spartan_tas/util/MDPWriter.h"
#include "server/sparkd/cmds/spartan_tas/util/PCapReader.h"
#include "server/sparkd/cmds/spartan_tas/util/SecurityDB.h"
#include "lib/utils/stats.h"
#include "lib/utils/type_name.h"
#include "server/sparkd/cmds/spartan/algo/TASOrderReactor.h"
#include "server/sparkd/cmds/spartan/algo/TASTriggerDef.h"
#include "server/sparkd/cmds/spartan/analysis/ActionableEventAnalyzer.h"
#include "server/sparkd/cmds/spartan/util/MCastReceiver.h"
#include "server/sparkd/cmds/spartan/util/MDPParser.h"
#include "server/sparkd/cmds/spartan/util/PCapReader.h"
#include "server/sparkd/cmds/spartan/util/SecurityDB.h"
#include "server/sparkd/user/AdminServiceDB.h"
#include <boost/asio.hpp>
@@ -42,8 +44,8 @@ build_trigger_defs(SecurityDB &db, config::SpartanTASCfg const &cfg) {
for (auto const &t : cfg.tas_trigger()) {
auto sec = db.query_single([t](auto const &sec) {
return sec.has_glbx() &&
securities::security_type(sec) == t.security_type() &&
securities::descriptor(sec) == t.security();
securities::security_type(sec) == t.security_type() &&
securities::descriptor(sec) == t.security();
});
bts_assert(sec);
admin::AdminServiceOperationResult result;
@@ -129,8 +131,8 @@ std::set<md::UserSymbol> get_symbols(SecurityDB &db,
for (auto const &t : cfg.tas_trigger()) {
auto sec = db.query_single([&t](auto const &sec) {
return sec.has_glbx() &&
securities::security_type(sec) == t.security_type() &&
securities::descriptor(sec) == t.security();
securities::security_type(sec) == t.security_type() &&
securities::descriptor(sec) == t.security();
});
bts_assert(sec);
@@ -183,17 +185,14 @@ int Spartan::run_from_mcast(std::vector<std::string> const &args) {
}
boost::asio::io_service io;
utils::MDPParser parser;
MDPParser parser;
TASOrderReactor reactor(triggers);
bind<TASOrderReactor, mktdata::SecurityStatus30>(parser, reactor);
parser.set_handler<mktdata::SecurityStatus30>(
[&reactor](auto const &sec_status) {
reactor.on_security_status(sec_status);
});
std::vector<std::unique_ptr<utils::MCastReceiver>> mc_receivers;
std::vector<std::unique_ptr<MCastReceiver>> mc_receivers;
for (auto const &c : connections) {
auto receiver =
std::make_unique<utils::MCastReceiver>(io, "0.0.0.0", c.ip, c.port);
std::make_unique<MCastReceiver>(io, "0.0.0.0", c.ip, c.port);
receiver->on_receive() = [&parser](auto const &bytes) {
parser.on_bytes(bytes);
};
@@ -207,6 +206,25 @@ int Spartan::run_from_mcast(std::vector<std::string> const &args) {
return 0;
}
int Spartan::analyze_pcap(std::vector<std::string> const &args) {
if (args.size() != 2)
return 1;
PCapReader pcap_reader(args[1]);
MDPParser parser;
ActionableEventAnalyzer analyzer;
Binder<mktdata::MDIncrementalRefreshBook46,
mktdata::MDIncrementalRefreshOrderBook47,
mktdata::MDIncrementalRefreshTradeSummary48>{parser, analyzer};
pcap_reader.on_packet() = [&parser](auto const &bytes) {
parser.on_bytes(bytes);
};
while (pcap_reader.read_next())
;
return 0;
}
int Spartan::run_from_pcap(std::vector<std::string> const &args) {
if (args.size() != 2)
return 1;
@@ -215,13 +233,9 @@ int Spartan::run_from_pcap(std::vector<std::string> const &args) {
auto triggers = build_and_validate_triggers(db);
TASOrderReactor reactor(triggers);
utils::PCapReader pcap_reader(args[1]);
utils::MDPParser parser;
parser.set_handler<mktdata::SecurityStatus30>(
[&reactor](auto const &sec_status) {
reactor.on_security_status(sec_status);
});
PCapReader pcap_reader(args[1]);
MDPParser parser;
bind<TASOrderReactor, mktdata::SecurityStatus30>(parser, reactor);
pcap_reader.on_packet() = [&parser](auto const &bytes) {
parser.on_bytes(bytes);
@@ -234,22 +248,35 @@ int Spartan::run_from_pcap(std::vector<std::string> const &args) {
return 0;
}
struct SummaryWriter {
SummaryWriter() { std::cout << "SeqNum,SendingTime,TransactTime,MsgType\n"; }
template <class M> void operator()(Header const &h, const M &m) {
std::cout << h.msg_seq_num << ","
<< h.sending_time << ","
<< m.transactTime() << ","
<< utils::type_name<M>() << "\n";
}
};
int Spartan::parse_pcap(std::vector<std::string> const &args) {
if (args.size() != 2 && args.size() != 3)
return 1;
std::cout << "[\n";
utils::MDPParser parser;
utils::MDPWriter writer(std::cout, parser);
utils::PCapReader pcap_reader(
MDPParser parser;
SummaryWriter writer;
bind<SummaryWriter, mktdata::MDIncrementalRefreshBook46,
mktdata::MDIncrementalRefreshOrderBook47,
mktdata::MDIncrementalRefreshTradeSummary48>(parser, writer);
PCapReader pcap_reader(
args[1], args.size() == 3 ? std::string("net ") + args[2] : "");
pcap_reader.on_packet() = [&parser](auto const &bytes) {
if (parser.on_bytes(bytes))
std::cout << ",\n";
parser.on_bytes(bytes);
};
while (pcap_reader.read_next())
;
std::cout << "]\n";
return 0;
}
@@ -262,6 +289,8 @@ int Spartan::execute(std::vector<std::string> const &args) {
error = run_from_pcap(args);
else if (args[0] == "run_from_mcast")
error = run_from_mcast(args);
else if (args[0] == "analyze_pcap")
error = analyze_pcap(args);
}
if (error)
std::cout << help();
@@ -271,6 +300,7 @@ int Spartan::execute(std::vector<std::string> const &args) {
std::string Spartan::help() {
return fmt::format("\tparse_pcap file [filter]\n"
"\trun_from_pcap pcap_file\n"
"\tanalyze_pcap pcap_file\n"
"\trun_from_mcast\n");
}