From 59a0eba9022cc91df304de99dd7b124115bfbfb4 Mon Sep 17 00:00:00 2001 From: Taha Afzal Date: Mon, 16 Nov 2020 12:12:12 -0500 Subject: [PATCH] Fixing the aggressive order's qty adjustment for icebergs --- .../md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp | 9 ++++++++- .../md/mdp3/back_testing/matcher/tests/matcher_tests.cpp | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp index ee4104b20..8907011dd 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/FifoSecurityMatcher.cpp @@ -110,7 +110,14 @@ void FifoSecurityMatcher::_on_new_order(const MDP3Order &ord, price_level = &*std::get<0>(p); } MDP3Order ord_corrected = ord; - ord_corrected.quantity.value() = new_ord_rem; + if(ord.iceberg_quantity.has_value()){ + ord_corrected.iceberg_quantity.value().total = MDP3Quantity(new_ord_rem); + ord_corrected.quantity = MDP3Quantity(std::min( + new_ord_rem, + static_cast(ord_corrected.iceberg_quantity.value().show.value()))); + } + else + ord_corrected.quantity.value() = new_ord_rem; price_level->on_new_same_side_order(ord_corrected); } else{ diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/tests/matcher_tests.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/tests/matcher_tests.cpp index 8f0ed9b1a..33b781229 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/tests/matcher_tests.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/back_testing/matcher/tests/matcher_tests.cpp @@ -495,6 +495,11 @@ TEST_CASE("fifo_matching_engine_book", "[matcher]") { add_to_book((lp.i + 1) * 10, api::Side::SIDE_SELL, lp.p); auto bid_bk = sec_me.book(api::Side::SIDE_BUY); verify_book_level(bid_bk.at(0), 15.09, 5050, 100); + // the bid book is + // 15.09 5050 100 + // 15.08 4095 90 + // 15.07 3240 80 + // 15.06 2485 70 // send a new sell at 15.07 to take the first 3 levels auto cross_ib = create_order(10000, sec_key, api::Side::SIDE_SELL, 10000, 15.07, 13,