diff --git a/src/lib/md/MBOServiceServer.cpp b/src/lib/md/MBOServiceServer.cpp index e25715ee4..6cabb35a0 100644 --- a/src/lib/md/MBOServiceServer.cpp +++ b/src/lib/md/MBOServiceServer.cpp @@ -148,14 +148,14 @@ std::optional search_orders(const ExchangeOrderKey oid, const std::vec const auto& oo = orders[x]; if (oo.id == oid) { if (oo.price == price) return { position }; - else return 0 ; + else return 0; } else if (price == oo.price) { - position += 1; + position += oo.size; } else { price = oo.price; - position = 1; + position = oo.size; } } return std::nullopt; diff --git a/src/lib/md/MBOServiceServer.h b/src/lib/md/MBOServiceServer.h index d0f590a18..6eccab38c 100644 --- a/src/lib/md/MBOServiceServer.h +++ b/src/lib/md/MBOServiceServer.h @@ -2,6 +2,7 @@ #include "lib/api/public/ServiceContext.h" #include "lib/api/services/MBOService.server.pb.h" #include +#include namespace bts { namespace utils { class Dispatcher; } @@ -24,4 +25,5 @@ class MBOServiceServer : public MBOServiceBase { }; + }} //namespace diff --git a/src/lib/md/test/mbo_tests.cpp b/src/lib/md/test/mbo_tests.cpp index a275a54c0..69abb194e 100644 --- a/src/lib/md/test/mbo_tests.cpp +++ b/src/lib/md/test/mbo_tests.cpp @@ -9,6 +9,10 @@ namespace bts { namespace md { + +// fwd declare from MBOServiceServer.cpp +std::optional search_orders(const ExchangeOrderKey oid, const std::vector& orders); + namespace test { int mbo_tests = 0; @@ -202,6 +206,7 @@ TEST_CASE("MBO sort order", "[md][mbo]") { } } + TEST_CASE("MBO change price and size", "[md][mbo]") { // When an order's size goes up it gets a new priority Co2TestInstrument instr { "MBO", api::SECURITYTYPE_FUTURE }; @@ -288,7 +293,27 @@ TEST_CASE("MBO change price and size", "[md][mbo]") { } } } + + // Do some tests on the snapshot + MBOSnapshot result; + copy_to_snapshot(state, &result); + + auto ask30 = search_orders(ExchangeOrderKey(701267928346), result.asks); + REQUIRE(ask30); + REQUIRE(*ask30 == 0); + + auto bid2875 = search_orders(ExchangeOrderKey(701267993135), result.bids); + REQUIRE(bid2875); + REQUIRE(*bid2875 == 20); + bid2875 = search_orders(ExchangeOrderKey(701267299079), result.bids); + REQUIRE(bid2875); + REQUIRE(*bid2875 == 6); + + auto not_bid = search_orders(ExchangeOrderKey(701967299879), result.bids); + auto not_ask = search_orders(ExchangeOrderKey(701967299879), result.asks); + REQUIRE(!not_bid); + REQUIRE(!not_ask); } }}}