diag: Add Trace parameter to matcher constructor

This makes it easy for matcher-validation commands to bind trace
parameters, such as order/event ids, to cli options.
This commit is contained in:
John Colvin committed 2021-02-01 22:56:21 -06:00
1 parent 9c53f4b949
commit 3efb4da14b
8 files changed
+34 -23

No files matched your search

@@ -37,6 +37,7 @@ static inline Quantity _norm_qty(Side side, Quantity qty) {
struct FifoMatcherContext::PImpl {
const bool ignore_ops_on_deleted_orders;
const Trace trace;
// _implied_candidates_dirty should be set to true anytime a security is
// added/removed. This signals that implied market candidates must be
// re-evaluated before any susbequent order-matching (re-evaluation is
@@ -49,7 +50,8 @@ struct FifoMatcherContext::PImpl {
PImpl() : ignore_ops_on_deleted_orders(false) {}
PImpl(const InitArgs &args)
: ignore_ops_on_deleted_orders(args.ignore_ops_on_deleted_orders) {}
: ignore_ops_on_deleted_orders(args.ignore_ops_on_deleted_orders),
trace(args.trace) {}
~PImpl() {
for (auto &p : matchers)
@@ -90,8 +92,9 @@ bool FifoMatcherContext::add_security(
ic.add_leg(l.security_id, _norm_qty(l.side, l.ratio));
}
_me->matchers.insert(std::make_pair(
sec_id, new FifoMergedSecurityMatcher(
{sec_id, _me->ignore_ops_on_deleted_orders})));
sec_id,
new FifoMergedSecurityMatcher(
{sec_id, _me->ignore_ops_on_deleted_orders, _me->trace})));
} else {
// Not sure why, but [John]I've seen _me->symbols contain empty strings.
// Overwrite the existing value to ensure a valid symbol.
@@ -134,16 +137,14 @@ BookSide FifoMatcherContext::book(SecurityID sec_id, Side side) {
return _get_matcher(sec_id)->book(side);
}
ImpliedBookSide
FifoMatcherContext::implied_book(SecurityID sec_id, Side side) {
ImpliedBookSide FifoMatcherContext::implied_book(SecurityID sec_id, Side side) {
return _get_matcher(sec_id)->implied_book(side);
}
///////////////////////
// matcher accessors
///////////////////////
FifoMergedSecurityMatcher *
FifoMatcherContext::_get_matcher(SecurityID sec_id) {
FifoMergedSecurityMatcher *FifoMatcherContext::_get_matcher(SecurityID sec_id) {
auto m = _me->matchers.find(sec_id);
return m == _me->matchers.end() ? nullptr : m->second;
}
@@ -159,7 +160,7 @@ FifoMatcherContext::_get_or_add_matcher(SecurityID sec_id) {
auto m = _me->matchers.find(sec_id);
if (m == _me->matchers.end()) {
auto *new_m = new FifoMergedSecurityMatcher(
{sec_id, _me->ignore_ops_on_deleted_orders});
{sec_id, _me->ignore_ops_on_deleted_orders, _me->trace});
_me->matchers.insert(std::make_pair(sec_id, new_m));
return new_m;
}
@@ -212,12 +213,7 @@ void FifoMatcherContext::clear() {
kv.second->matcher()->clear();
}
using BBORow = std::tuple<
std::string,
Price,
Quantity,
Price,
Quantity>;
using BBORow = std::tuple<std::string, Price, Quantity, Price, Quantity>;
void FifoMatcherContext::print_all_bbos(std::ostream &out) {
std::vector<BBORow> rows;
@@ -18,6 +18,7 @@ namespace bts::spartan::mdp3 {
struct FifoMatcherContext {
struct InitArgs {
bool ignore_ops_on_deleted_orders;
Trace trace{};
};
FifoMatcherContext();
@@ -27,10 +27,11 @@ struct FifoMergedSecurityMatcher::PImpl {
PImpl(const FifoMergedSecurityMatcher::InitArgs &args)
: security_id(args.security_id),
ignore_ops_on_deleted_orders(args.ignore_ops_on_deleted_orders),
trace(args.trace),
implied_matching_status(true),
matcher(new FifoSecurityMatcher(
{args.security_id, 0, args.ignore_ops_on_deleted_orders,
nullptr})),
nullptr, args.trace})),
implied_matchers() {}
~PImpl() {
@@ -41,6 +42,7 @@ struct FifoMergedSecurityMatcher::PImpl {
const SecurityID security_id;
const bool ignore_ops_on_deleted_orders;
const Trace trace;
bool implied_matching_status;
// the Security matcher is kept in a shared_ptr
// so it can be passed around to one or more ImpliedMatchers.
@@ -15,6 +15,7 @@ struct FifoMergedSecurityMatcher {
struct InitArgs {
SecurityID security_id;
bool ignore_ops_on_deleted_orders;
const Trace trace;
};
FifoMergedSecurityMatcher(const InitArgs &args);
@@ -269,8 +269,8 @@ FifoSecurityMatcher::FifoSecurityMatcher(
SecurityID{},
Price(),
Side::Buy,
Trace()),
_sec(args.security_id), _event_id(args.event_id), _trace(),
args.trace),
_sec(args.security_id), _event_id(args.event_id), _trace(args.trace),
_ignore_ops_on_deleted_orders(args.ignore_ops_on_deleted_orders),
_clean_up_op_threshold(2500), _running_op_count(0) {
if (args.orders != nullptr) {
@@ -19,6 +19,7 @@ class FifoSecurityMatcher : public SecurityMatcher {
const size_t event_id = 0;
const bool ignore_ops_on_deleted_orders = true;
Orders const *orders = nullptr;
Trace trace{};
};
private:
@@ -12,9 +12,9 @@ using namespace google::protobuf::util;
namespace bts::spartan::mdp3 {
struct MergedMatcher::PImpl {
PImpl()
: matcher_map(), trace(), match_count(0), match_count_this_per(0),
per_start_time(TimeUtil::GetCurrentTime()) {}
PImpl(MergedMatcher::Args args)
: matcher_map(), trace(args.trace), match_count(0),
match_count_this_per(0), per_start_time(TimeUtil::GetCurrentTime()) {}
std::unordered_set<OrderKey> used_order_keys;
std::map<SecurityID, std::string> asset_map;
@@ -25,7 +25,10 @@ struct MergedMatcher::PImpl {
google::protobuf::Timestamp per_start_time;
};
MergedMatcher::MergedMatcher() : _me(new MergedMatcher::PImpl()) {}
MergedMatcher::MergedMatcher() : MergedMatcher(Args{}) {}
MergedMatcher::MergedMatcher(MergedMatcher::Args args)
: _me(new MergedMatcher::PImpl(args)) {}
MergedMatcher::~MergedMatcher() {}
@@ -34,7 +37,8 @@ void MergedMatcher::add_def(const SecurityDefinition &def) {
_me->asset_map.emplace(def.security_id(), ass);
auto m = _me->matcher_map.find(ass);
if (m == _me->matcher_map.end())
m = _me->matcher_map.emplace(ass, FifoMatcherContext({true})).first;
m = _me->matcher_map.emplace(ass, FifoMatcherContext({true, _me->trace}))
.first;
m->second.add_security(
def.security_id(), std::string(def.symbol()),
std::vector<LegDef>{def.legs().begin(), def.legs().end()});
@@ -112,7 +116,8 @@ MergedMatcher::_asset_matcher(SecurityID sec, bool add_if_missing) {
auto mat_it = _me->matcher_map.find(ass_it->second);
if (add_if_missing && mat_it == _me->matcher_map.end())
mat_it =
_me->matcher_map.emplace(ass_it->second, FifoMatcherContext({true}))
_me->matcher_map
.emplace(ass_it->second, FifoMatcherContext({true, _me->trace}))
.first;
bts_assert(mat_it != _me->matcher_map.end());
return mat_it->second;
@@ -17,7 +17,12 @@ class SecurityDefinition;
class MergedMatcher {
public:
struct Args {
Trace trace;
};
MergedMatcher();
MergedMatcher(Args);
~MergedMatcher();
using MatchEffect = std::variant<SimBookUpdate, SimOrderUpdate>;