diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.cpp index 41e70c0cd..4a3f3ddef 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.cpp @@ -244,14 +244,42 @@ void DirectMatcher::match(ChangeSrc, std::vector> dirty; dirty.reserve(_matcher_map.size()); - for (const auto& c : changes){ - _trace.log_incoming_change(c); - MatcherUtils::validate_incoming_order_change(c); - auto it = _matcher_map.find(c.order.security); + for (const auto& c : changes) { + auto new_ch = c; + auto it = _matcher_map.find(new_ch.order.security); bts_assert (it != _matcher_map.end()); auto& sec_matcher = it->second.matcher; - sec_matcher.on_order_change(c, res); - dirty.emplace_back(c.order.security,&it->second); + switch (c.change) { + case OrderChange::ChangeType::added: + if (new_ch.order.iceberg_quantity.has_value()) + icebergs.insert(std::make_pair(new_ch.order.key, new_ch.order.iceberg_quantity.value())); + break; + case OrderChange::ChangeType::updated: { + auto* old_ord = std::get<1>(sec_matcher.find_order(c.order.key)); + if (old_ord == nullptr) { + // the matcher may not have this order anymore; + // it may have been filled already due to an algo shot. + continue; + } + OrderChange big_ch; + big_ch.change = c.change; + big_ch.previous_order = to_mdp3_order(*old_ord); + big_ch.order = c.order; + if (big_ch.order.iceberg_quantity.has_value()) { + iceberg_helper::detect_show_qty_changes(big_ch, icebergs); + auto it = icebergs.find(big_ch.order.key); + bts_assert(it != icebergs.end()); + big_ch.order.iceberg_quantity = it->second; + } + new_ch.order = big_ch.order; + break; + } + default: break; + } + _trace.log_incoming_change(new_ch); + MatcherUtils::validate_incoming_order_change(new_ch); + sec_matcher.on_order_change(new_ch, res); + dirty.emplace_back(new_ch.order.security,&it->second); } for(const auto& u : *res) _trace.log_outgoing_update(std::get(u)); diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.h b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.h index 70b42ecb3..8c128af05 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/Matcher.h @@ -69,6 +69,7 @@ private: bool dirty = false; }; std::map _matcher_map; + boost::container::flat_map icebergs; Trace _trace; size_t _match_count; size_t _match_count_this_per; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/GatewayAgent.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/GatewayAgent.cpp index 98e2be51b..c9491f04b 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/GatewayAgent.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/simulator/agents/GatewayAgent.cpp @@ -14,7 +14,7 @@ // i need to dedicate more ram to my vm). // If you want to run the simulator with implied matching, // just uncomment the line below. -#define ENABLE_IMPLIED_MATCHING +//#define ENABLE_IMPLIED_MATCHING namespace bts::spartan::mdp3 { #ifdef ENABLE_IMPLIED_MATCHING