Refactor
This commit is contained in:
1 parent
aa6d453d5b
commit
3e817d4fb0
81 files changed
+249
-228
No files matched your search
@@ -11,6 +11,56 @@ double min(std::vector<double> const&v);
|
||||
double max(std::vector<double> const&v);
|
||||
double sum(std::vector<double> const&v);
|
||||
double avg(std::vector<double> const&v);
|
||||
|
||||
inline double med(std::vector<double> const&v) {
|
||||
return percentile(v,0.5);
|
||||
}
|
||||
|
||||
template <class C, class E>
|
||||
std::vector<double> extract(C const&ts, E const &e) {
|
||||
std::vector<double> result;
|
||||
result.reserve(ts.size());
|
||||
for (auto const&t :ts)
|
||||
result.push_back(e(t));
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class C, class E>
|
||||
double stdev(C const&ts, E const&e) {
|
||||
return stddev(extract(ts,e));
|
||||
}
|
||||
|
||||
template <class C, class E>
|
||||
double percentile(C const&ts,E const&e,double p) {
|
||||
return percentile(extract(ts,e),p);
|
||||
}
|
||||
|
||||
template <class C, class E>
|
||||
double med(C const&ts,E const&e) {
|
||||
return med(extract(ts,e));
|
||||
}
|
||||
template <class C, class E>
|
||||
double min(C const&ts, E const&e) {
|
||||
return min(extract(ts,e));
|
||||
}
|
||||
|
||||
template <class C, class E>
|
||||
double max(C const&ts, E const&e) {
|
||||
return max(extract(ts,e));
|
||||
}
|
||||
|
||||
template <class C, class E>
|
||||
double sum(C const&ts, E const&e) {
|
||||
return sum(extract(ts,e));
|
||||
}
|
||||
|
||||
template <class C, class E>
|
||||
double avg(C const&ts, E const&e) {
|
||||
return avg(extract(ts,e));
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
set(sources algo/AlgoDefinitionServiceServer.cpp;cmds/AdminReport.cpp;cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/FIXSim.cpp;cmds/Help.cpp;cmds/KeyCode.cpp;cmds/Md.cpp;cmds/ParseHistoricalFIX.cpp;cmds/PrintHedgeOrders.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/Span.cpp;cmds/Spartan.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;cmds/Web.cpp;cmds/spartan_tas/algo/TASOrderReactor.cpp;cmds/spartan_tas/algo/TASTriggerDef.cpp;cmds/spartan_tas/util/MCastReceiver.cpp;cmds/spartan_tas/util/MDPWriter.cpp;cmds/spartan_tas/util/PCapReader.cpp;cmds/spartan_tas/util/SecurityDB.cpp;dspark/mirage/quick_queue/quick_queue.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/MultipartFormDecoder.cpp;http/WebServer.cpp;http/tests/MultiPartFormTests.cpp;main.cpp;md/ChannelVolume.cpp;md/MarketDataAuxiliaryServiceServer.cpp;md/VolumeAtPriceState.cpp;md/platforms/IMDPlatform.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/ice_onixs/ICEListener.cpp;md/platforms/ice_onixs/ICEMain.cpp;md/platforms/ice_onixs/tests/ice_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/MarginServiceServer.cpp;position/PositionAggregator.cpp;position/PositionMap.cpp;position/PositionServicePNLHelper.cpp;position/PositionServiceServer.cpp;position/import/BasePositionServiceServer.cpp;position/import/DownloadCommonStateMachine.cpp;position/import/DownloadWindow.cpp;position/import/MoneyFileServiceServer.cpp;position/import/parsing/gmi_parser.cpp;position/import/parsing/money_parser.cpp;position/import/parsing/parser_common.cpp;position/tests/PositionTests.cpp;position/tests/position_tests_internal.cpp;subprocess/SubProcessRunner.cpp;support/ErrorReportService.cpp;support/ShellLatencyServer.cpp;user/AdminServiceDB.cpp;user/AdminServiceServer.cpp;user/AuthServiceServer.cpp;user/tests/admin_service_tests.cpp)
|
||||
set(sources algo/AlgoDefinitionServiceServer.cpp;cmds/AdminReport.cpp;cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/FIXSim.cpp;cmds/Help.cpp;cmds/KeyCode.cpp;cmds/Md.cpp;cmds/ParseHistoricalFIX.cpp;cmds/PrintHedgeOrders.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/Span.cpp;cmds/Spartan.cpp;cmds/Test.cpp;cmds/TestCeloxica.cpp;cmds/Web.cpp;cmds/spartan/algo/TASOrderReactor.cpp;cmds/spartan/algo/TASTriggerDef.cpp;cmds/spartan/analysis/ActionableEventAnalyzer.cpp;cmds/spartan/util/MCastReceiver.cpp;cmds/spartan/util/PCapReader.cpp;cmds/spartan/util/SecurityDB.cpp;dspark/mirage/quick_queue/quick_queue.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/MultipartFormDecoder.cpp;http/WebServer.cpp;http/tests/MultiPartFormTests.cpp;main.cpp;md/ChannelVolume.cpp;md/MarketDataAuxiliaryServiceServer.cpp;md/VolumeAtPriceState.cpp;md/platforms/IMDPlatform.cpp;md/platforms/celoxica/CXListener.cpp;md/platforms/celoxica/CXMain.cpp;md/platforms/celoxica/tests/cx_tests.cpp;md/platforms/ice_onixs/ICEListener.cpp;md/platforms/ice_onixs/ICEMain.cpp;md/platforms/ice_onixs/tests/ice_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/MarginServiceServer.cpp;position/PositionAggregator.cpp;position/PositionMap.cpp;position/PositionServicePNLHelper.cpp;position/PositionServiceServer.cpp;position/import/BasePositionServiceServer.cpp;position/import/DownloadCommonStateMachine.cpp;position/import/DownloadWindow.cpp;position/import/MoneyFileServiceServer.cpp;position/import/parsing/gmi_parser.cpp;position/import/parsing/money_parser.cpp;position/import/parsing/parser_common.cpp;position/tests/PositionTests.cpp;position/tests/position_tests_internal.cpp;subprocess/SubProcessRunner.cpp;support/ErrorReportService.cpp;support/ShellLatencyServer.cpp;user/AdminServiceDB.cpp;user/AdminServiceServer.cpp;user/AuthServiceServer.cpp;user/tests/admin_service_tests.cpp)
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ private:
|
||||
int run_from_pcap(std::vector<std::string> const &);
|
||||
int run_from_mcast(std::vector<std::string> const &);
|
||||
int parse_pcap(std::vector<std::string> const &);
|
||||
int analyze_pcap(std::vector<std::string> const &);
|
||||
void run(std::vector<std::string> const &);
|
||||
};
|
||||
|
||||
|
||||
+4
-4
@@ -7,8 +7,9 @@
|
||||
#include "lib/jetfix/gateway/JetFIXGateway.h"
|
||||
#include "lib/orderman/order_factory/OrderFactory.h"
|
||||
#include "lib/orderman/orderman_utils/fix_order_codec.h"
|
||||
#include "server/sparkd/cmds/spartan_tas/algo/TASTriggerDef.h"
|
||||
#include "server/sparkd/cmds/spartan_tas/mdp3_gen/SecurityStatus30.h"
|
||||
#include "TASTriggerDef.h"
|
||||
#include "../mdp3_gen/SecurityStatus30.h"
|
||||
#include "../util/MDPParser.h"
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
|
||||
@@ -80,8 +81,7 @@ bool TASOrderReactor::do_work() {
|
||||
return me->pending_reactions;
|
||||
}
|
||||
|
||||
void TASOrderReactor::on_security_status(
|
||||
mktdata::SecurityStatus30 const &status) {
|
||||
void TASOrderReactor::operator()(Header const&, mktdata::SecurityStatus30 const &status) {
|
||||
for (auto &r : me->group_reactors) {
|
||||
if (status.getSecurityGroupAsStringView() == r.group) {
|
||||
for (auto &gr : r.gw_reactors) {
|
||||
+6
-4
@@ -11,19 +11,21 @@ namespace mktdata {
|
||||
class SecurityStatus30;
|
||||
}
|
||||
namespace bts {
|
||||
namespace jetfix {
|
||||
template <class...> class JetFIXGateway;
|
||||
}}
|
||||
namespace jetfix {template <class...> class JetFIXGateway;}
|
||||
}
|
||||
|
||||
namespace bts {
|
||||
namespace spartan {
|
||||
|
||||
struct Header;
|
||||
|
||||
class TASOrderReactor {
|
||||
public:
|
||||
TASOrderReactor(std::vector<TASTriggerDef> const &);
|
||||
~TASOrderReactor();
|
||||
bool do_work();
|
||||
void on_security_status(mktdata::SecurityStatus30 const &status);
|
||||
void operator()(Header const&header,
|
||||
mktdata::SecurityStatus30 const &status);
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1 @@
|
||||
#include "ActionableEventAnalyzer.h"
|
||||
@@ -0,0 +1,59 @@
|
||||
#pragma once
|
||||
#include "../util/MDPParser.h"
|
||||
#include "lib/utils/stats.h"
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
|
||||
namespace bts {
|
||||
namespace spartan {
|
||||
|
||||
struct ActionableEventAnalyzer {
|
||||
|
||||
struct Event {
|
||||
uint64_t transact_time;
|
||||
uint64_t send_time;
|
||||
uint64_t actionable_window;
|
||||
uint64_t exchange_latency;
|
||||
uint64_t time_from_last_transaction;
|
||||
};
|
||||
std::vector<Event> events;
|
||||
template <class M> void operator()(Header const &h, const M &m) {
|
||||
Event e{m.transactTime(), h.sending_time, 0,
|
||||
h.sending_time - m.transactTime(), 0};
|
||||
if (events.size()) {
|
||||
auto &previous = events.back();
|
||||
previous.actionable_window =
|
||||
std::max(0l, (int64_t)(previous.send_time - m.transactTime()));
|
||||
previous.time_from_last_transaction = m.transactTime() - previous.transact_time;
|
||||
}
|
||||
events.push_back(e);
|
||||
}
|
||||
|
||||
std::string single_stat(uint64_t Event::*field) {
|
||||
std::ostringstream str;
|
||||
str.precision(0);
|
||||
str << std::fixed << "\tmin: "
|
||||
<< stats::min(events, [field](auto const &ev) { return ev.*field; })
|
||||
<< "\t\tmed: "
|
||||
<< stats::med(events, [field](auto const &ev) { return ev.*field; })
|
||||
<< "\t\tmax: "
|
||||
<< stats::max(events, [field](auto const &ev) { return ev.*field; });
|
||||
return str.str();
|
||||
}
|
||||
|
||||
~ActionableEventAnalyzer() {
|
||||
std::cout << "Data points:\n \t\t" << events.size()
|
||||
|
||||
<< "\nExchange Latency:\n"
|
||||
<< single_stat(&Event::exchange_latency)
|
||||
|
||||
<< "\nTransaction Gap:\n"
|
||||
<< single_stat(&Event::time_from_last_transaction)
|
||||
|
||||
<< "\nActionable Window:\n"
|
||||
<< single_stat(&Event::actionable_window) << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace spartan
|
||||
} // namespace bts
|
||||
Whitespace-only changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+1
-1
@@ -5,7 +5,7 @@
|
||||
#include <boost/bind/bind.hpp>
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
namespace spartan {
|
||||
|
||||
struct MCastReceiver::PImpl {
|
||||
PImpl(boost::asio::io_service &io) : socket(io) {}
|
||||
+1
-1
@@ -13,7 +13,7 @@ class io_service;
|
||||
} // namespace boost
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
namespace spartan {
|
||||
|
||||
class MCastReceiver {
|
||||
public:
|
||||
+50
-114
@@ -29,14 +29,14 @@
|
||||
#include "../mdp3_gen/SnapshotFullRefresh52.h"
|
||||
#include "../mdp3_gen/SnapshotFullRefreshOrderBook44.h"
|
||||
#include "../mdp3_gen/SnapshotFullRefreshOrderBook53.h"
|
||||
#include "server/sparkd/cmds/spartan_tas/util/meta_type_pack.h"
|
||||
#include "meta_type_pack.h"
|
||||
|
||||
#include "lib/utils/bts_assert.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
namespace spartan {
|
||||
|
||||
struct __attribute__((__packed__)) Header {
|
||||
uint32_t msg_seq_num;
|
||||
@@ -61,132 +61,68 @@ class MDPParser {
|
||||
}
|
||||
|
||||
bool on_bytes(std::string_view const &bytes) {
|
||||
bts_assert_d(bytes.size() >= sizeof(utils::Header));
|
||||
utils::MDP3Msg *msg = (utils::MDP3Msg *)bytes.data();
|
||||
bts_assert_d(bytes.size() >= sizeof(spartan::Header));
|
||||
spartan::MDP3Msg *msg = (spartan::MDP3Msg *)bytes.data();
|
||||
return handlers[msg->header.template_id](*msg);
|
||||
}
|
||||
|
||||
template <class T, class C> void set_handler(C const &c) {
|
||||
handlers[T::sbeTemplateId()] = [c](auto const &msg) {
|
||||
c(T{(char*)msg.payload.data(), msg.payload.size()});
|
||||
template <class T, class C> void set_handler(C &c) {
|
||||
handlers[T::sbeTemplateId()] = [&c](auto const &msg) {
|
||||
c(msg.header,T{(char*)msg.payload.data(), msg.payload.size()});
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
private:
|
||||
std::array<std::function<bool(utils::MDP3Msg const &)>,
|
||||
std::array<std::function<bool(spartan::MDP3Msg const &)>,
|
||||
std::numeric_limits<uint16_t>::max()>
|
||||
handlers;
|
||||
};
|
||||
|
||||
|
||||
template <class Handler, class MsgHead, class... MsgTail>
|
||||
void bind(MDPParser &p, Handler &h) {
|
||||
p.set_handler<MsgHead> (h);
|
||||
bind<Handler,MsgTail...>(p,h);
|
||||
}
|
||||
|
||||
template <class Handler>
|
||||
void bind(MDPParser &, Handler&) {}
|
||||
|
||||
template <class... M> struct Binder {
|
||||
template <class Handler> Binder(MDPParser &p,Handler &h) {
|
||||
bind<Handler,M...> (p,h);
|
||||
}
|
||||
};
|
||||
|
||||
using ForAllMDPTypes =
|
||||
meta_type_pack<
|
||||
mktdata::AdminLogin15, mktdata::AdminLogout16,
|
||||
mktdata::ChannelReset4, mktdata::MDIncrementalRefreshBook32,
|
||||
mktdata::MDIncrementalRefreshBook46,
|
||||
mktdata::MDIncrementalRefreshDailyStatistics33,
|
||||
mktdata::MDIncrementalRefreshDailyStatistics49,
|
||||
mktdata::MDIncrementalRefreshLimitsBanding34,
|
||||
mktdata::MDIncrementalRefreshLimitsBanding50,
|
||||
mktdata::MDIncrementalRefreshOrderBook43,
|
||||
mktdata::MDIncrementalRefreshOrderBook47,
|
||||
mktdata::MDIncrementalRefreshSessionStatistics35,
|
||||
mktdata::MDIncrementalRefreshSessionStatistics51,
|
||||
mktdata::MDIncrementalRefreshTradeSummary42,
|
||||
mktdata::MDIncrementalRefreshTradeSummary48,
|
||||
mktdata::MDIncrementalRefreshVolume37,
|
||||
mktdata::MDInstrumentDefinitionFuture27,
|
||||
mktdata::MDInstrumentDefinitionFuture54,
|
||||
mktdata::MDInstrumentDefinitionOption41,
|
||||
mktdata::MDInstrumentDefinitionOption55,
|
||||
mktdata::MDInstrumentDefinitionSpread29,
|
||||
mktdata::MDInstrumentDefinitionSpread56, mktdata::QuoteRequest39,
|
||||
mktdata::SecurityStatus30, mktdata::SnapshotFullRefresh38,
|
||||
mktdata::SnapshotFullRefresh52, mktdata::SnapshotFullRefreshOrderBook44,
|
||||
mktdata::SnapshotFullRefreshOrderBook53>;
|
||||
|
||||
using AllMDTypesBinder = ForAllMDPTypes::type<Binder>;
|
||||
|
||||
} // namespace utils
|
||||
} // namespace bts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
#include <Pcap++/PcapFileDevice.h>
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
namespace spartan {
|
||||
|
||||
struct PCapReader::PImpl {
|
||||
PImpl(std::string const &file_path)
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
namespace spartan {
|
||||
|
||||
class PCapReader {
|
||||
public:
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
namespace bts {
|
||||
namespace spartan {
|
||||
|
||||
template <class... Ts> struct meta_type_pack {
|
||||
template<template <typename...> class T, class... T2s>
|
||||
using type = T<T2s...,Ts...>;
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -1 +0,0 @@
|
||||
#include "MDPWriter.h"
|
||||
@@ -1,57 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "server/sparkd/cmds/spartan_tas/util/MDPParser.h"
|
||||
#include <ostream>
|
||||
|
||||
namespace bts {
|
||||
namespace utils {
|
||||
|
||||
template <class... Msgs> class MDPWriterT {
|
||||
public:
|
||||
template <class Parser> MDPWriterT(std::ostream &out,Parser &parser) {
|
||||
set_handler<Parser,Msgs...>(out, parser);
|
||||
}
|
||||
|
||||
private:
|
||||
template <class Parser, class Head, class... Tail>
|
||||
void set_handler(std::ostream &out, Parser &parser) {
|
||||
parser.template set_handler<Head>(
|
||||
[&out](Head const &head) { out << head;});
|
||||
set_handler<Parser,Tail...>(out, parser);
|
||||
}
|
||||
|
||||
template <class Parser>
|
||||
void set_handler(std::ostream&, Parser&)
|
||||
{}
|
||||
};
|
||||
|
||||
using AllMDPTypes =
|
||||
meta::meta_type_pack<
|
||||
mktdata::AdminLogin15, mktdata::AdminLogout16,
|
||||
mktdata::ChannelReset4, mktdata::MDIncrementalRefreshBook32,
|
||||
mktdata::MDIncrementalRefreshBook46,
|
||||
mktdata::MDIncrementalRefreshDailyStatistics33,
|
||||
mktdata::MDIncrementalRefreshDailyStatistics49,
|
||||
mktdata::MDIncrementalRefreshLimitsBanding34,
|
||||
mktdata::MDIncrementalRefreshLimitsBanding50,
|
||||
mktdata::MDIncrementalRefreshOrderBook43,
|
||||
mktdata::MDIncrementalRefreshOrderBook47,
|
||||
mktdata::MDIncrementalRefreshSessionStatistics35,
|
||||
mktdata::MDIncrementalRefreshSessionStatistics51,
|
||||
mktdata::MDIncrementalRefreshTradeSummary42,
|
||||
mktdata::MDIncrementalRefreshTradeSummary48,
|
||||
mktdata::MDIncrementalRefreshVolume37,
|
||||
mktdata::MDInstrumentDefinitionFuture27,
|
||||
mktdata::MDInstrumentDefinitionFuture54,
|
||||
mktdata::MDInstrumentDefinitionOption41,
|
||||
mktdata::MDInstrumentDefinitionOption55,
|
||||
mktdata::MDInstrumentDefinitionSpread29,
|
||||
mktdata::MDInstrumentDefinitionSpread56, mktdata::QuoteRequest39,
|
||||
mktdata::SecurityStatus30, mktdata::SnapshotFullRefresh38,
|
||||
mktdata::SnapshotFullRefresh52, mktdata::SnapshotFullRefreshOrderBook44,
|
||||
mktdata::SnapshotFullRefreshOrderBook53>;
|
||||
|
||||
using MDPWriter = AllMDPTypes::type<MDPWriterT>;
|
||||
|
||||
} // namespace utils
|
||||
} // namespace bts
|
||||
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace bts {
|
||||
namespace meta {
|
||||
|
||||
template <class... Ts> struct meta_type_pack {
|
||||
template<template <typename...T2s> class T>
|
||||
using type = T<Ts...>;
|
||||
};
|
||||
|
||||
}}
|
||||
Reference in new issue
Block a user