From 511b9551e369e2d6f24ca2f291e280aa44f04a84 Mon Sep 17 00:00:00 2001 From: John Colvin Date: Fri, 23 Oct 2020 18:18:51 -0400 Subject: [PATCH] delete old test code, clean up logging/console output in FifoMergedSecurityMatcher --- .../matcher/FifoMergedSecurityMatcher.cpp | 52 ++++--------------- .../cmds/spartan/md/mdp3/utils/book_utils.h | 31 +++++++++++ .../cmds/spartan/md/mdp3/utils/order_utils.h | 2 +- 3 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoMergedSecurityMatcher.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoMergedSecurityMatcher.cpp index 4bf97b101..ec88014bc 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoMergedSecurityMatcher.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoMergedSecurityMatcher.cpp @@ -8,39 +8,21 @@ #include "server/sparkd/cmds/spartan/md/mdp3/common/mdp3_quantity_operators.h" #include "server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.h" #include "server/sparkd/cmds/spartan/md/mdp3/utils/order_utils.h" -#include "server/sparkd/cmds/spartan/util/action_summarizer.h" #include "server/sparkd/cmds/spartan/util/action_summarizer_macros.h" #include "server/sparkd/cmds/spartan/util/table_display.h" #include #include #include -// Error logs are automatically logged to the console -// (w/ default logging configuration), but they lag behind -// immediate console output (i.e., calls to std::cout). -// If _ECHO_ON is defined, the _ERROR_LEVEL macro is set to Info -// to avoid duplicate, and (perhaps more importantly) unsynchronized output. -//#define _ECHO_ON -#ifdef _ECHO_ON -#define _ECHO(...) std::cout << bts::orderman::Formatter::fmt(__VA_ARGS__) -#define _ECHO_LINE(...) std::cout << bts::orderman::Formatter::fmt(__VA_ARGS__) << std::endl -#define _ERROR_LEVEL Info -#else -#define _ECHO(...) -#define _ERROR_LEVEL Error -#endif -#define _LOG(level, msg) \ - _ECHO(_log_header(), " ", msg, "\n"); \ - LOG(OrderMan, level, "{} {}", _log_header(), msg) +#define _LOG(level, msg) LOG(OrderMan, level, "{} {}", _log_header(), msg) +#define DIAG(...) _LOG(Diag, bts::orderman::Formatter::fmt(__VA_ARGS__)) #define INFO(...) _LOG(Info, bts::orderman::Formatter::fmt(__VA_ARGS__)) +#define WARN(...) _LOG(Info, bts::orderman::Formatter::fmt(__VA_ARGS__)) #define ERROR(...) _LOG(_ERROR_LEVEL, bts::orderman::Formatter::fmt(__VA_ARGS__)) -// SUMMARIZE macro wrappers -#define _SUMMARIZE SUMMARIZE(_log_header()) -#define _SUMMARIZE_TRANSACTION(...) SUMMARIZE_TRANSACTION(_log_header(), FMT(__VA_ARGS__)) -#define _SUMMARIZE_TRANSACTION_NAMED(name, ...) SUMMARIZE_TRANSACTION_NAMED(name, _log_header(), FMT(__VA_ARGS__)) - using namespace ranges; +using namespace bts::spartan::mdp3::book_utils; + namespace bts::spartan::mdp3 { struct FifoMergedSecurityMatcher::PImpl { PImpl(const FifoMergedSecurityMatcher::InitArgs& args) @@ -125,7 +107,6 @@ void FifoMergedSecurityMatcher::implied_matching_status(bool value) { } void FifoMergedSecurityMatcher::on_order_change(const SmallOrderChange& ch, std::vector* effects, FillDepot& fills) { - // SUMMARIZE_TRANSACTION(_log_header(), FMT("updating order: ", ch)); switch (ch.change) { case OrderChange::ChangeType::updated: { auto prev_ord_tup = matcher()->find_order(ch.order.key); @@ -138,7 +119,6 @@ void FifoMergedSecurityMatcher::on_order_change(const SmallOrderChange& ch, std: // price improved, try to fill the order auto new_ch = ch; _fill(new_ch.order, effects, fills, false); - // PRINT_LINE(_log_header(), " updated order rem qty: ", new_ch.order.quantity, ", orig state: ", ch.order); if (new_ch.order.quantity.value() == 0) { matcher()->on_order_completed(ch.order.key); } else { @@ -303,7 +283,6 @@ MDP3Quantity FifoMergedSecurityMatcher::_fill( // auto oside = bts::securities::other_side(side); bts::orderman::SidePriceComp oside_comp(oside); - SUMMARIZE_TRANSACTION_NAMED(_order_fill_log, _log_header(), FMT("filling ", fmt_order(key, side, quantity, price))); while (quantity.value() > 0) { // Fill one price level at a time. // While one market may have the best 1st price level, @@ -318,29 +297,18 @@ MDP3Quantity FifoMergedSecurityMatcher::_fill( if (!is_dcross && !is_icross) break; // the order crossed at least one of the markets - // if (is_dcross) - // PRINT_LINE("best dir ", oside, ": ", std::get<0>(dtop), " (", std::get<1>(dtop), ")"); - // if (is_icross) - // PRINT_LINE("best imp ", oside, ": ", std::get<0>(itop), " (", std::get<1>(itop), ")"); + auto ord_desc = [&]() { return fmt_order(key, side, price, quantity); }; if (!is_dcross || (is_icross && oside_comp(get_price(itop), get_price(dtop)))) { // fill with the implied market - // _SUMMARIZE_TRANSACTION_NAMED( - // _impl_fill_log, "filling implied market. Top of book (beforehand): ", oside, - // " ", std::get<0>(itop), " (", std::get<1>(itop), ")"); - // for (auto& im : _me->implied_matchers) { - // im->print_legs(); - // std::cout << "-----------------------------------------------" << std::endl; - // } + DIAG("filling ", ord_desc(), " in implied market ", fmt_price_level(oside, itop)); auto target_fill_qty = std::min(quantity, get_qty(itop)); auto rem = imatcher->fill(key, side, target_fill_qty, effects, fills); auto fill_qty = target_fill_qty - rem; - // PRINT_LINE("orig qty: ", quantity, ", filled qty: ", fill_qty, ", rem qty: ", quantity - fill_qty); + DIAG("filled ", fill_qty, ". Order now: ", ord_desc()); quantity -= fill_qty; } else { // fill with the direct market - // _SUMMARIZE_TRANSACTION_NAMED( - // _dir_fill_log, "filling direct market. Top of book (beforehand): ", oside, - // " ", std::get<0>(dtop), " (", std::get<1>(dtop), ")"); + DIAG("filling ", ord_desc(), " in direct market ", fmt_price_level(oside, dtop)); bool local_effects = effects == nullptr; if (local_effects) effects = new std::vector(); @@ -348,7 +316,7 @@ MDP3Quantity FifoMergedSecurityMatcher::_fill( auto target_fill_qty = std::min(quantity, get_qty(dtop)); auto rem = matcher()->fill(key, side, get_price(dtop), target_fill_qty, effects, true); auto fill_qty = target_fill_qty - rem; - // PRINT_LINE("orig qty: ", quantity, ", filled qty: ", fill_qty, ", rem qty: ", quantity - fill_qty); + DIAG("filled ", fill_qty, ". Order now: ", ord_desc()); quantity -= fill_qty; MDP3Fill aggr_fill; bts_assert(aggr_fill.price.is_nan()); diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.h index 2b82c10b0..eb8bca541 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.h @@ -9,6 +9,37 @@ #include namespace bts::spartan::mdp3::book_utils { +inline std::ostream& fmt_price_level(std::ostream& out, md::IntPrice price, MDP3Quantity qty) { + out << qty << " @ " << price; + return out; +} + +inline std::ostream& fmt_price_level(std::ostream& out, api::Side side, md::IntPrice price, MDP3Quantity qty) { + out << side << " "; + fmt_price_level(out, price, qty); + return out; +} + +inline std::string fmt_price_level(md::IntPrice price, MDP3Quantity qty) { + std::stringstream out; + fmt_price_level(out, price, qty); + return out.str(); +} + +inline std::string fmt_price_level(const std::tuple& pl) { + return fmt_price_level(std::get<0>(pl), std::get<1>(pl)); +} + +inline std::string fmt_price_level(api::Side side, md::IntPrice price, MDP3Quantity qty) { + std::stringstream out; + fmt_price_level(out, side, price, qty); + return out.str(); +} + +inline std::string fmt_price_level(api::Side side, const std::tuple& pl) { + return fmt_price_level(side, std::get<0>(pl), std::get<1>(pl)); +} + template inline std::ostream& fmt_ladder( TIter first_bid, diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/order_utils.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/order_utils.h index f2e1d4807..14984c2ed 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/order_utils.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/order_utils.h @@ -66,7 +66,7 @@ inline bool orders_equal(const MDP3Order& lhs, const MDP3Order& rhs) { } inline std::string -fmt_order(MDP3OrderKey key, api::Side side, MDP3Quantity qty, md::IntPrice price) { +fmt_order(MDP3OrderKey key, api::Side side, md::IntPrice price, MDP3Quantity qty) { std::stringstream str; str << "[" << key.value() << "] " << " " << (side == api::Side::SIDE_BUY ? "Buy" : "Sell") << " " << qty.value()