diff --git a/src/server/sparkd/CMakeDeps.cmake b/src/server/sparkd/CMakeDeps.cmake index 91b10219b..dd4b9d3ab 100644 --- a/src/server/sparkd/CMakeDeps.cmake +++ b/src/server/sparkd/CMakeDeps.cmake @@ -1 +1 @@ -set(sources algo/AlgoDefinitionServiceServer.cpp;cmds/AdminReport.cpp;cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CMECertCmd.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/FIXSim.cpp;cmds/Help.cpp;cmds/KeyCode.cpp;cmds/Md.cpp;cmds/ParseHistoricalFIX.cpp;cmds/PrintHedgeOrders.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/Span.cpp;cmds/Spartan.cpp;cmds/Test.cpp;cmds/Web.cpp;cmds/spartan/algo/tas/RunTAS.cpp;cmds/spartan/algo/tas/TASOrderReactor.cpp;cmds/spartan/algo/tas/TASTriggerDef.cpp;cmds/spartan/back_testing/algos/PolyObserver.cpp;cmds/spartan/back_testing/algos/SniperModel.cpp;cmds/spartan/back_testing/algos/spreader/SimOrderGateway.cpp;cmds/spartan/back_testing/algos/spreader/SimSpreader.cpp;cmds/spartan/back_testing/algos/spreader/tests/sim_spreader_tests.cpp;cmds/spartan/back_testing/db/SimDB.cpp;cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.cpp;cmds/spartan/back_testing/matcher/FifoMatcherContext.cpp;cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.cpp;cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.cpp;cmds/spartan/back_testing/matcher/FifoSecurityMatcher.cpp;cmds/spartan/back_testing/matcher/Matcher.cpp;cmds/spartan/back_testing/matcher/MatchingCommon.cpp;cmds/spartan/back_testing/matcher/fill_depot.cpp;cmds/spartan/back_testing/matcher/iceberg_helper.cpp;cmds/spartan/back_testing/matcher/tests/matcher_tests.cpp;cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.cpp;cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.cpp;cmds/spartan/back_testing/run/SimSessionOptions.proto;cmds/spartan/back_testing/run/run_sim.cpp;cmds/spartan/back_testing/sim/ISim.cpp;cmds/spartan/back_testing/sim/Sim.cpp;cmds/spartan/back_testing/sim/pandl/PandL.cpp;cmds/spartan/back_testing/sim/pcap/PCapEventGenerator.cpp;cmds/spartan/back_testing/sim/pcap/PCapEventSource.cpp;cmds/spartan/back_testing/sim/spark_bridge/AlgoServicesBridge.cpp;cmds/spartan/back_testing/sim/spark_bridge/BeforeLaunchBridge.cpp;cmds/spartan/common/TimeStamp.cpp;cmds/spartan/md/mdp3/common/InstrumentDefinition.cpp;cmds/spartan/md/mdp3/common/InstrumentSnapshot.cpp;cmds/spartan/md/mdp3/common/mdp3_common.cpp;cmds/spartan/md/mdp3/common/tests/book_merging_tests.cpp;cmds/spartan/md/mdp3/feed_control/IFeedController.cpp;cmds/spartan/md/mdp3/handler/ChannelHandler.cpp;cmds/spartan/md/mdp3/implied/implied_market.cpp;cmds/spartan/md/mdp3/parsing/MDP3MsgBox.cpp;cmds/spartan/md/mdp3/realtime/RealTimeHandler.cpp;cmds/spartan/md/mdp3/recovery/BookSnapshot.cpp;cmds/spartan/md/mdp3/recovery/DefinitionSnapshot.cpp;cmds/spartan/md/mdp3/recovery/IncrementalQueue.cpp;cmds/spartan/md/mdp3/recovery/RecoveryHandler.cpp;cmds/spartan/md/mdp3/tests/spartan_md_tests.cpp;cmds/spartan/md/mdp3/utils/book_utils.cpp;cmds/spartan/md/mdp3/utils/mdp3_utils.cpp;cmds/spartan/md/mdp3/utils/order_utils.cpp;cmds/spartan/md/mdp3/utils/polygon_utils.cpp;cmds/spartan/md/mdp3/utils/queries/DefinitionCollector.cpp;cmds/spartan/md/mdp3/utils/queries/FillCounter.cpp;cmds/spartan/md/mdp3/utils/queries/IcebergFinder.cpp;cmds/spartan/md/mdp3/utils/queries/PolygonFinder.cpp;cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.cpp;cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.cpp;cmds/spartan/md/mdp3/utils/security_comp.cpp;cmds/spartan/md/mdp3/utils/security_parser.cpp;cmds/spartan/md/mdp3/utils/tests/synthetic_book_tests.cpp;cmds/spartan/md/mdp3/utils/tests/test_polygon_finder.cpp;cmds/spartan/util/MCastReceiver.cpp;cmds/spartan/util/PCapReader.cpp;cmds/spartan/util/SecurityDB.cpp;cmds/spartan/util/action_summarizer.cpp;cmds/spartan/util/args_parser.cpp;cmds/spartan/util/sql/adapters/polygon_defs.cpp;dspark/mirage/quick_queue/quick_queue.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/MultipartFormDecoder.cpp;http/WebServer.cpp;http/tests/MultiPartFormTests.cpp;main.cpp;md/ChannelVolume.cpp;md/MarketDataAuxiliaryServiceServer.cpp;md/VolumeAtPriceState.cpp;md/platforms/IMDPlatform.cpp;md/platforms/ice_onixs/ICEListener.cpp;md/platforms/ice_onixs/ICEMain.cpp;md/platforms/ice_onixs/tests/ice_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/TradeSummarySignalDispatcher.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/MarginServiceServer.cpp;position/PositionAggregator.cpp;position/PositionMap.cpp;position/PositionServicePNLHelper.cpp;position/PositionServiceServer.cpp;position/import/BasePositionServiceServer.cpp;position/import/DownloadCommonStateMachine.cpp;position/import/DownloadWindow.cpp;position/import/MoneyFileServiceServer.cpp;position/import/parsing/gmi_parser.cpp;position/import/parsing/money_parser.cpp;position/import/parsing/parser_common.cpp;position/tests/PositionTests.cpp;position/tests/position_tests_internal.cpp;subprocess/SubProcessRunner.cpp;support/ErrorReportService.cpp;support/ShellLatencyServer.cpp;user/AdminServiceDB.cpp;user/AdminServiceServer.cpp;user/AuthServiceServer.cpp;user/tests/admin_service_tests.cpp) \ No newline at end of file +set(sources algo/AlgoDefinitionServiceServer.cpp;cmds/AdminReport.cpp;cmds/AutoCert.cpp;cmds/Benchmark.cpp;cmds/CMECertCmd.cpp;cmds/CmdRegistry.cpp;cmds/ConfigCheck.cpp;cmds/FIXSim.cpp;cmds/Help.cpp;cmds/KeyCode.cpp;cmds/Md.cpp;cmds/ParseHistoricalFIX.cpp;cmds/PrintHedgeOrders.cpp;cmds/QuickTest.cpp;cmds/Run.cpp;cmds/Span.cpp;cmds/Spartan.cpp;cmds/Test.cpp;cmds/Web.cpp;cmds/spartan/algo/tas/RunTAS.cpp;cmds/spartan/algo/tas/TASOrderReactor.cpp;cmds/spartan/algo/tas/TASTriggerDef.cpp;cmds/spartan/back_testing/algos/PolyObserver.cpp;cmds/spartan/back_testing/algos/SniperModel.cpp;cmds/spartan/back_testing/algos/spreader/SimOrderGateway.cpp;cmds/spartan/back_testing/algos/spreader/SimSpreader.cpp;cmds/spartan/back_testing/algos/spreader/tests/sim_spreader_tests.cpp;cmds/spartan/back_testing/db/SimDB.cpp;cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.cpp;cmds/spartan/back_testing/matcher/FifoMatcherContext.cpp;cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.cpp;cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.cpp;cmds/spartan/back_testing/matcher/FifoSecurityMatcher.cpp;cmds/spartan/back_testing/matcher/Matcher.cpp;cmds/spartan/back_testing/matcher/MatchingCommon.cpp;cmds/spartan/back_testing/matcher/fill_depot.cpp;cmds/spartan/back_testing/matcher/iceberg_helper.cpp;cmds/spartan/back_testing/matcher/tests/matcher_tests.cpp;cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.cpp;cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.cpp;cmds/spartan/back_testing/run/SimSessionOptions.proto;cmds/spartan/back_testing/run/run_sim.cpp;cmds/spartan/back_testing/sim/ISim.cpp;cmds/spartan/back_testing/sim/Sim.cpp;cmds/spartan/back_testing/sim/pandl/PandL.cpp;cmds/spartan/back_testing/sim/pcap/PCapEventGenerator.cpp;cmds/spartan/back_testing/sim/pcap/PCapEventSource.cpp;cmds/spartan/back_testing/sim/spark_bridge/AlgoServicesBridge.cpp;cmds/spartan/back_testing/sim/spark_bridge/BeforeLaunchBridge.cpp;cmds/spartan/common/OrderKey.cpp;cmds/spartan/common/SecurityID.cpp;cmds/spartan/common/TimeInterval.cpp;cmds/spartan/common/TimeStamp.cpp;cmds/spartan/md/mdp3/common/InstrumentDefinition.cpp;cmds/spartan/md/mdp3/common/InstrumentSnapshot.cpp;cmds/spartan/md/mdp3/common/mdp3_common.cpp;cmds/spartan/md/mdp3/common/tests/book_merging_tests.cpp;cmds/spartan/md/mdp3/feed_control/IFeedController.cpp;cmds/spartan/md/mdp3/handler/ChannelHandler.cpp;cmds/spartan/md/mdp3/implied/implied_market.cpp;cmds/spartan/md/mdp3/parsing/MDP3MsgBox.cpp;cmds/spartan/md/mdp3/realtime/RealTimeHandler.cpp;cmds/spartan/md/mdp3/recovery/BookSnapshot.cpp;cmds/spartan/md/mdp3/recovery/DefinitionSnapshot.cpp;cmds/spartan/md/mdp3/recovery/IncrementalQueue.cpp;cmds/spartan/md/mdp3/recovery/RecoveryHandler.cpp;cmds/spartan/md/mdp3/tests/spartan_md_tests.cpp;cmds/spartan/md/mdp3/utils/book_utils.cpp;cmds/spartan/md/mdp3/utils/mdp3_utils.cpp;cmds/spartan/md/mdp3/utils/order_utils.cpp;cmds/spartan/md/mdp3/utils/polygon_utils.cpp;cmds/spartan/md/mdp3/utils/queries/DefinitionCollector.cpp;cmds/spartan/md/mdp3/utils/queries/FillCounter.cpp;cmds/spartan/md/mdp3/utils/queries/IcebergFinder.cpp;cmds/spartan/md/mdp3/utils/queries/PolygonFinder.cpp;cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.cpp;cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.cpp;cmds/spartan/md/mdp3/utils/security_comp.cpp;cmds/spartan/md/mdp3/utils/security_parser.cpp;cmds/spartan/md/mdp3/utils/tests/synthetic_book_tests.cpp;cmds/spartan/md/mdp3/utils/tests/test_polygon_finder.cpp;cmds/spartan/util/MCastReceiver.cpp;cmds/spartan/util/PCapReader.cpp;cmds/spartan/util/SecurityDB.cpp;cmds/spartan/util/action_summarizer.cpp;cmds/spartan/util/args_parser.cpp;cmds/spartan/util/sql/adapters/polygon_defs.cpp;dspark/mirage/quick_queue/quick_queue.cpp;exchange_sim/ExchangeSim.cpp;exchange_sim/ExchangeSimApplication.cpp;exchange_sim/book/Book.cpp;exchange_sim/book/ExchangeSim.proto;exchange_sim/book/Order.cpp;exchange_sim/book/OrderMatcher.cpp;exchange_sim/book/book_transform.cpp;exchange_sim/tests/test_book_transform.cpp;http/ApiGateway.cpp;http/MultipartFormDecoder.cpp;http/WebServer.cpp;http/tests/MultiPartFormTests.cpp;main.cpp;md/ChannelVolume.cpp;md/MarketDataAuxiliaryServiceServer.cpp;md/VolumeAtPriceState.cpp;md/platforms/IMDPlatform.cpp;md/platforms/ice_onixs/ICEListener.cpp;md/platforms/ice_onixs/ICEMain.cpp;md/platforms/ice_onixs/tests/ice_tests.cpp;md/platforms/mdp3_onixs/MDP3Listener.cpp;md/platforms/mdp3_onixs/MDP3Main.cpp;md/platforms/mdp3_onixs/TradeSummarySignalDispatcher.cpp;md/platforms/mdp3_onixs/tests/mdp3_tests.cpp;md/run_md.cpp;position/IPositionObserver.cpp;position/MarginServiceCore.cpp;position/MarginServiceServer.cpp;position/PositionAggregator.cpp;position/PositionMap.cpp;position/PositionServicePNLHelper.cpp;position/PositionServiceServer.cpp;position/import/BasePositionServiceServer.cpp;position/import/DownloadCommonStateMachine.cpp;position/import/DownloadWindow.cpp;position/import/MoneyFileServiceServer.cpp;position/import/parsing/gmi_parser.cpp;position/import/parsing/money_parser.cpp;position/import/parsing/parser_common.cpp;position/tests/PositionTests.cpp;position/tests/position_tests_internal.cpp;subprocess/SubProcessRunner.cpp;support/ErrorReportService.cpp;support/ShellLatencyServer.cpp;user/AdminServiceDB.cpp;user/AdminServiceServer.cpp;user/AuthServiceServer.cpp;user/tests/admin_service_tests.cpp) \ No newline at end of file diff --git a/src/server/sparkd/cmds/Spartan.cpp b/src/server/sparkd/cmds/Spartan.cpp index 5887ba7e7..67d5a4f7e 100644 --- a/src/server/sparkd/cmds/Spartan.cpp +++ b/src/server/sparkd/cmds/Spartan.cpp @@ -125,7 +125,7 @@ template void print_book(std::ostream &books, B const &b) { } int icebergs_to_csv( - const std::unordered_map &ibs, + const std::unordered_map &ibs, const std::string &out_csv) { const char *ok_col = "ok"; const char *eid_col = "eid"; diff --git a/src/server/sparkd/cmds/spartan/back_testing/algos/PolyObserver.cpp b/src/server/sparkd/cmds/spartan/back_testing/algos/PolyObserver.cpp index 1522ecf46..b1bd68bf1 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/algos/PolyObserver.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/algos/PolyObserver.cpp @@ -16,7 +16,7 @@ struct PolyObserver::Target { api::Side side; std::string const product; double value = Worthless; - MDP3Quantity quantity = MDP3Quantity{0}; + Quantity quantity = Quantity{0}; void mark_as_worthless() { value = Worthless; } bool has_value() const { return value > securities::market_epsilon(); } }; @@ -24,14 +24,14 @@ struct PolyObserver::Target { struct PolyObserver::Opportunity { Target *target; double value; - MDP3Quantity quantity; + Quantity quantity; EventHeader start; }; struct PolyObserver::PImpl { std::vector> targets; std::optional current_opportunity; - std::unordered_map books; + std::unordered_map books; EventHeader last_event; ISim *sim = nullptr; }; @@ -117,7 +117,7 @@ void PolyObserver::try_start_new_opportunity() { "opportunity_begin", best->polygon_id, best->descriptor, api::Side_Name(best->side), best->value, best->quantity.value(), 0, 0, (me->last_event.observable_time - me->last_event.transact_time) - .microseconds(), + .micros(), me->last_event.event_id.first, me->last_event.event_id.first); } } @@ -133,12 +133,12 @@ void PolyObserver::analyze() { api::Side_Name(target.side), target.value, target.quantity.value(), (me->last_event.observable_time - opportunity.start.observable_time) - .microseconds(), + .micros(), (me->last_event.transact_time - opportunity.start.transact_time) - .microseconds(), + .micros(), (opportunity.start.observable_time - opportunity.start.transact_time) - .microseconds(), + .micros(), opportunity.start.event_id.first); } else { // Had value but not anymore, opportunity is concluded @@ -148,12 +148,12 @@ void PolyObserver::analyze() { opportunity.quantity.value(), (me->last_event.observable_time - opportunity.start.observable_time) - .microseconds(), + .micros(), (me->last_event.transact_time - opportunity.start.transact_time) - .microseconds(), + .micros(), (opportunity.start.observable_time - opportunity.start.transact_time) - .microseconds(), + .micros(), opportunity.start.event_id.first, me->last_event.event_id.first - 1); me->current_opportunity.reset(); diff --git a/src/server/sparkd/cmds/spartan/back_testing/algos/SniperModel.cpp b/src/server/sparkd/cmds/spartan/back_testing/algos/SniperModel.cpp index 6a585642a..51f19abd6 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/algos/SniperModel.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/algos/SniperModel.cpp @@ -24,7 +24,7 @@ struct SniperModel::Target { std::string const descriptor; api::Side side; double value = Worthless; - MDP3Quantity quantity = MDP3Quantity{0}; + Quantity quantity = Quantity{0}; void mark_as_worthless() { value = Worthless; } bool has_value(double v) const { return value > v; } }; @@ -39,9 +39,9 @@ struct SniperModel::Shot { EventHeader observed; EventHeader concluded; double value_at_observation_ts; - MDP3Quantity quantity; + Quantity quantity; bool forced_completion; - std::unordered_map working; + std::unordered_map working; size_t transaction_duration; }; @@ -72,7 +72,7 @@ struct SniperModel::PImpl { size_t streak_id = 0; State state = State::W_OPPORTUNITY; - std::unordered_map books = {}; + std::unordered_map books = {}; std::vector> targets = {}; std::optional current_shot{}; }; @@ -337,12 +337,12 @@ void SniperModel::eval(std::vector const &targets) { bool SniperModel::within_safety_margin(Target const &t) const { Book synth_book; - using LegInfo = std::tuple; + using LegInfo = std::tuple; std::vector leg_mkts; for (auto &leg : t.polygon.parts) { auto &leg_mkt = leg_mkts.emplace_back(); - std::get<0>(leg_mkt) = MDP3Quantity{leg.ratio}; + std::get<0>(leg_mkt) = Quantity{leg.ratio}; std::get<1>(leg_mkt) = {}; auto leg_book_side = securities::other_side(side_from_ratio(leg.ratio)); std::get<2>(leg_mkt) = me->books[leg.sec_id].book.mbp_side(leg_book_side); @@ -466,7 +466,7 @@ void SniperModel::fire(Shot const &s) { order_change.order.security = p.sec_id; order_change.order.price = worst_price; order_change.order.quantity = - MDP3Quantity{s.quantity.value() * std::abs(p.ratio)}; + Quantity{s.quantity.value() * std::abs(p.ratio)}; order_change.order.side = part_side; order_change.change = OrderChange::added; order_change.order.key = me->sim->send(order_change); @@ -493,7 +493,7 @@ void SniperModel::fire(Shot const &s) { order_change.order.security = p.sec_id; order_change.order.price = limit_price; order_change.order.quantity = - MDP3Quantity{s.quantity.value() * std::abs(p.ratio)}; + Quantity{s.quantity.value() * std::abs(p.ratio)}; order_change.order.side = part_side; order_change.change = OrderChange::added; order_change.order.key = me->sim->send(order_change); diff --git a/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimOrderGateway.cpp b/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimOrderGateway.cpp index 6c1fc76a6..eaba67a7c 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimOrderGateway.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimOrderGateway.cpp @@ -44,7 +44,7 @@ // return nullptr; // } -// OrderTuple* find_ord(MDP3OrderKey key, +// OrderTuple* find_ord(OrderKey key, // std::vector& orders){ // for(auto& o : orders) // if(o.ochange.order.key == key) @@ -82,11 +82,11 @@ // MDP3Order(), // MDP3Order{ // me->sim_services->generate_order_key(), -// MDP3SecurityID{static_cast(skey.value())}, +// SecurityID{static_cast(skey.value())}, // side, // MDP3OrderPriority{}, // md::IntPrice_from_double<7>(p.value()), -// MDP3Quantity{static_cast(q.value())}, +// Quantity{static_cast(q.value())}, // {} // }, // OrderChange::added @@ -104,7 +104,7 @@ // auto& ochange = t->ochange; // ochange.previous_order = ochange.order; // ochange.order.price = md::IntPrice_from_double<7>(p.value()); -// ochange.order.quantity = MDP3Quantity{static_cast(q.value())}; +// ochange.order.quantity = Quantity{static_cast(q.value())}; // ochange.change = OrderChange::updated; // me->sim_services->send(ochange); // } @@ -135,7 +135,7 @@ // OrderUpdate::Status::PARTIALLY_FILLED, // t.ochange.order.security, // t.ochange.order.side, -// MDP3Quantity{}, +// Quantity{}, // md::IntPrice() // }); // } diff --git a/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimSpreader.cpp b/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimSpreader.cpp index d13e80be0..ca35c0cec 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimSpreader.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/SimSpreader.cpp @@ -28,11 +28,11 @@ // } // bool compare_keys (SecurityKey spark_k, -// MDP3SecurityID spartan_k){ +// SecurityID spartan_k){ // return static_cast(spark_k.value()) == spartan_k.value(); // } -// bts::orderman::Book* find_book(MDP3SecurityID id, +// bts::orderman::Book* find_book(SecurityID id, // std::vector& books){ // for (auto& b : books) // if(compare_keys(b.security_key(),id)) diff --git a/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/tests/sim_spreader_tests.cpp b/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/tests/sim_spreader_tests.cpp index b9dfc65b2..66595f851 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/tests/sim_spreader_tests.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/algos/spreader/tests/sim_spreader_tests.cpp @@ -46,11 +46,11 @@ // return _polygons; // } -// spartan::mdp3::Book book(MDP3SecurityID,api::Side) const override { +// spartan::mdp3::Book book(SecurityID,api::Side) const override { // return {}; // } -// MDP3OrderKey generate_order_key() override{ -// return MDP3OrderKey(key++); +// OrderKey generate_order_key() override{ +// return OrderKey(key++); // } // TimeStamp now() const override{ // return TimeStamp(0); @@ -73,17 +73,17 @@ // for(auto[p,q] : bids) // rv.mbp_buy[i++] = BookLevel{ // md::IntPrice_from_double<7>(p), -// bts::spartan::mdp3::MDP3Quantity(q), +// bts::spartan::mdp3::Quantity(q), // 0 // }; // i=0; // for(auto[p,q] : asks) // rv.mbp_sell[i++] = BookLevel{ // md::IntPrice_from_double<7>(p), -// bts::spartan::mdp3::MDP3Quantity(q), +// bts::spartan::mdp3::Quantity(q), // 0 // }; -// rv.security_id = MDP3SecurityID(key); +// rv.security_id = SecurityID(key); // return rv; // } @@ -151,7 +151,7 @@ // REQUIRE(sim_services.n_updates==1); // REQUIRE(sim_services.last_change.order.side == api::Side::SIDE_SELL); // REQUIRE(sim_services.last_change.order.quantity == -// bts::spartan::mdp3::MDP3Quantity(1)); REQUIRE( +// bts::spartan::mdp3::Quantity(1)); REQUIRE( // bts::securities::is_same(Price(sim_services.last_change.order.price.price()), // Price(113))); // // send multiple book updates @@ -172,11 +172,11 @@ // }); // REQUIRE(sim_services.n_updates==i+1); // +1 because order_place is // also counted REQUIRE(sim_services.last_change.order.security == -// bts::spartan::mdp3::MDP3SecurityID(2)); +// bts::spartan::mdp3::SecurityID(2)); // REQUIRE(sim_services.last_change.order.side == // api::Side::SIDE_SELL); // REQUIRE(sim_services.last_change.order.quantity == -// bts::spartan::mdp3::MDP3Quantity(1)); REQUIRE( +// bts::spartan::mdp3::Quantity(1)); REQUIRE( // bts::securities::is_same(Price(sim_services.last_change.order.price.price()), // Price(p+10))); // p++; @@ -191,15 +191,15 @@ // bts::spartan::mdp3::OrderUpdate::FILLED, // q_ord.security, // q_ord.side, -// bts::spartan::mdp3::MDP3Quantity(1), +// bts::spartan::mdp3::Quantity(1), // md::IntPrice_from_double<7>(202) // } // }); // // the above should have sent a hedge order, verify that // auto hedge_ord = sim_services.last_change.order; -// REQUIRE(hedge_ord.security == bts::spartan::mdp3::MDP3SecurityID(1)); +// REQUIRE(hedge_ord.security == bts::spartan::mdp3::SecurityID(1)); // REQUIRE(hedge_ord.side == api::Side::SIDE_BUY); -// REQUIRE(hedge_ord.quantity == bts::spartan::mdp3::MDP3Quantity(1)); +// REQUIRE(hedge_ord.quantity == bts::spartan::mdp3::Quantity(1)); // REQUIRE( // bts::securities::is_same(Price(hedge_ord.price.price()), // Price(192))); @@ -215,7 +215,7 @@ // bts::spartan::mdp3::OrderUpdate::FILLED, // hedge_ord.security, // hedge_ord.side, -// bts::spartan::mdp3::MDP3Quantity(1), +// bts::spartan::mdp3::Quantity(1), // md::IntPrice_from_double<7>(192) // } // }); diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.cpp index 6469bd6a1..89d41db9a 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.cpp @@ -41,31 +41,31 @@ SUMMARIZE_TRANSACTION_NAMED(name, _log_header(), FMT(__VA_ARGS__)) namespace bts::spartan::mdp3 { -using _BookLevel = std::tuple; +using _BookLevel = std::tuple; struct FifoImpliedSecurityMatcher::PImpl { - PImpl(MDP3SecurityID security_id, std::string symbol) + PImpl(SecurityID security_id, std::string symbol) : security_id(security_id), implied_mkt(), symbol(symbol), leg_symbols() {} - MDP3SecurityID security_id; - std::map> + SecurityID security_id; + std::map> implied_mkt; // symbol/leg_symbols serve diagnostic purposes // (easier to read logs w/ actual symbols than sec ids) std::string symbol; - std::map leg_symbols; + std::map leg_symbols; }; /////////////////////// // constructors /////////////////////// FifoImpliedSecurityMatcher::FifoImpliedSecurityMatcher( - MDP3SecurityID security_id) + SecurityID security_id) : FifoImpliedSecurityMatcher(security_id, std::string()) {} FifoImpliedSecurityMatcher::FifoImpliedSecurityMatcher( - MDP3SecurityID security_id, std::string symbol) + SecurityID security_id, std::string symbol) : _me(new FifoImpliedSecurityMatcher::PImpl(security_id, symbol)) {} FifoImpliedSecurityMatcher::~FifoImpliedSecurityMatcher() {} @@ -73,7 +73,7 @@ FifoImpliedSecurityMatcher::~FifoImpliedSecurityMatcher() {} /////////////////////// // diagnostic /////////////////////// -MDP3SecurityID FifoImpliedSecurityMatcher::security_id() const { +SecurityID FifoImpliedSecurityMatcher::security_id() const { return _me->security_id; } std::string FifoImpliedSecurityMatcher::symbol() const { return _me->symbol; } @@ -127,13 +127,13 @@ SmallBookLevel FifoImpliedSecurityMatcher::top_of_book(api::Side side) const { SmallBook b; _book(side, b, 1); if (b.empty()) - return {md::IntPrice(), MDP3Quantity(0)}; + return {md::IntPrice(), Quantity(0)}; return b[0]; } void FifoImpliedSecurityMatcher::_book( api::Side side, SmallBook &dest, uint32_t depth) const { - std::vector> im_vec; + std::vector> im_vec; for (const auto &p : _me->implied_mkt) { SmallBook bk; auto [sec_matcher, leg_qty] = p.second; @@ -147,18 +147,18 @@ void FifoImpliedSecurityMatcher::_book( } void FifoImpliedSecurityMatcher::add_leg( - MDP3SecurityID sec_id, + SecurityID sec_id, FifoSecurityMatcher *m, - MDP3Quantity unit_qty, + Quantity unit_qty, std::string leg_sym) { _me->implied_mkt.insert({sec_id, {m, unit_qty}}); _me->leg_symbols.insert_or_assign(sec_id, leg_sym); } -MDP3Quantity FifoImpliedSecurityMatcher::fill( - MDP3OrderKey key, +Quantity FifoImpliedSecurityMatcher::fill( + OrderKey key, api::Side side, - MDP3Quantity qty, + Quantity qty, std::vector *effects, FillDepot &fills) { SmallBook b; @@ -229,6 +229,6 @@ MDP3Quantity FifoImpliedSecurityMatcher::fill( } } bts_assert(fill_qty <= orig_qty.value()); - return MDP3Quantity(orig_qty.value() - fill_qty); + return Quantity(orig_qty.value() - fill_qty); } } // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.h index 2a48523e3..1a5a76470 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoImpliedSecurityMatcher.h @@ -13,18 +13,18 @@ namespace bts::spartan::mdp3 { struct FifoImpliedSecurityMatcher { - FifoImpliedSecurityMatcher(MDP3SecurityID security_id); + FifoImpliedSecurityMatcher(SecurityID security_id); // Symbol/sec id serve diagnostic purposes, but aren't absolutely neccessary. // Logs made by this class begin with a header that includes the symbol/sec // id. - FifoImpliedSecurityMatcher(MDP3SecurityID security_id, std::string symbol); + FifoImpliedSecurityMatcher(SecurityID security_id, std::string symbol); ~FifoImpliedSecurityMatcher(); ImpliedBook book(api::Side) const; - MDP3Quantity fill( - MDP3OrderKey, + Quantity fill( + OrderKey, api::Side, - MDP3Quantity, + Quantity, std::vector *, FillDepot &); // Note: this class is NOT responsible for deleting any FifoSecurityMatcher @@ -36,11 +36,11 @@ struct FifoImpliedSecurityMatcher { // Note the absense of a 'side' parameter: unit_qty should be positive for // Buys, negative for Sells. void add_leg( - MDP3SecurityID sec_id, + SecurityID sec_id, FifoSecurityMatcher *m, - MDP3Quantity unit_qty, + Quantity unit_qty, std::string leg_sym); - MDP3SecurityID security_id() const; + SecurityID security_id() const; std::string symbol() const; SmallBookLevel top_of_book(api::Side side) const; void print_legs(std::ostream &out = std::cout) const; diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.cpp index 94d0b1b29..85d659d12 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.cpp @@ -24,7 +24,7 @@ namespace bts::spartan::mdp3 { /////////////////////// // static inline std::string _log_header() { return "FifoMatcherContext"; } -static inline MDP3Quantity _norm_qty(api::Side side, MDP3Quantity qty) { +static inline Quantity _norm_qty(api::Side side, Quantity qty) { switch (side) { case api::Side::SIDE_BUY: return qty; @@ -44,8 +44,8 @@ struct FifoMatcherContext::PImpl { // performed lazily). bool implied_candidates_dirty; ImpliedMarket contract_matrix; - flat_map matchers; - flat_map symbols; + flat_map matchers; + flat_map symbols; PImpl() : ignore_ops_on_deleted_orders(false) {} @@ -73,7 +73,7 @@ FifoMatcherContext::~FifoMatcherContext() {} // security accessors /////////////////////// bool FifoMatcherContext::add_security( - MDP3SecurityID sec_id, + SecurityID sec_id, const std::string &symbol, const std::vector &legs) { auto curr = _me->matchers.find(sec_id); @@ -85,7 +85,7 @@ bool FifoMatcherContext::add_security( if (legs.empty()) { // must be an outright (to normalize outrights and spreads, // the former is treated like a 'single leg spread') - ic.add_leg(sec_id, MDP3Quantity(1)); + ic.add_leg(sec_id, Quantity(1)); } else { for (auto l : legs) ic.add_leg(l.security_id, _norm_qty(l.side, l.ratio)); @@ -103,7 +103,7 @@ bool FifoMatcherContext::add_security( return true; } -bool FifoMatcherContext::remove_security(MDP3SecurityID sec_id) { +bool FifoMatcherContext::remove_security(SecurityID sec_id) { auto curr = _me->symbols.find(sec_id); if (curr == _me->symbols.end()) return false; @@ -114,13 +114,13 @@ bool FifoMatcherContext::remove_security(MDP3SecurityID sec_id) { return true; } -bool FifoMatcherContext::implied_matching_status(MDP3SecurityID sec_id) const { +bool FifoMatcherContext::implied_matching_status(SecurityID sec_id) const { auto *m = _get_matcheri(sec_id); return m != nullptr && m->implied_matching_status(); } void FifoMatcherContext::implied_matching_status( - MDP3SecurityID sec_id, bool value) { + SecurityID sec_id, bool value) { auto *m = _get_or_add_matcher(sec_id); if (m->implied_matching_status() != value) { m->implied_matching_status(value); @@ -131,12 +131,12 @@ void FifoMatcherContext::implied_matching_status( /////////////////////// // book /////////////////////// -Book FifoMatcherContext::book(MDP3SecurityID sec_id, api::Side side) { +Book FifoMatcherContext::book(SecurityID sec_id, api::Side side) { return _get_matcher(sec_id)->book(side); } ImpliedBook -FifoMatcherContext::implied_book(MDP3SecurityID sec_id, api::Side side) { +FifoMatcherContext::implied_book(SecurityID sec_id, api::Side side) { return _get_matcher(sec_id)->implied_book(side); } @@ -144,19 +144,19 @@ FifoMatcherContext::implied_book(MDP3SecurityID sec_id, api::Side side) { // matcher accessors /////////////////////// FifoMergedSecurityMatcher * -FifoMatcherContext::_get_matcher(MDP3SecurityID sec_id) { +FifoMatcherContext::_get_matcher(SecurityID sec_id) { auto m = _me->matchers.find(sec_id); return m == _me->matchers.end() ? nullptr : m->second; } const FifoMergedSecurityMatcher * -FifoMatcherContext::_get_matcheri(MDP3SecurityID sec_id) const { +FifoMatcherContext::_get_matcheri(SecurityID sec_id) const { auto m = _me->matchers.find(sec_id); return m == _me->matchers.end() ? nullptr : m->second; } FifoMergedSecurityMatcher * -FifoMatcherContext::_get_or_add_matcher(MDP3SecurityID sec_id) { +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( @@ -168,7 +168,7 @@ FifoMatcherContext::_get_or_add_matcher(MDP3SecurityID sec_id) { } std::tuple -FifoMatcherContext::find_order(MDP3SecurityID sec_id, MDP3OrderKey ok) { +FifoMatcherContext::find_order(SecurityID sec_id, OrderKey ok) { auto *m = _get_matcher(sec_id); if (m != nullptr) return m->matcher()->find_order(ok); @@ -179,7 +179,7 @@ FifoMatcherContext::find_order(MDP3SecurityID sec_id, MDP3OrderKey ok) { // order callbacks /////////////////////// void FifoMatcherContext::on_order_change( - MDP3SecurityID sec_id, + SecurityID sec_id, const std::vector &changes, std::vector *effects, FillDepot &fills) { @@ -204,7 +204,7 @@ void FifoMatcherContext::on_order_change( // diagnostic /////////////////////// std::optional -FifoMatcherContext::has_same_orders(MDP3SecurityID sec, const Orders &orders) { +FifoMatcherContext::has_same_orders(SecurityID sec, const Orders &orders) { return _get_matcher(sec)->matcher()->has_same_orders(orders); } @@ -216,9 +216,9 @@ void FifoMatcherContext::clear() { using BBORow = std::tuple< std::string, bts::md::IntPrice, - MDP3Quantity, + Quantity, bts::md::IntPrice, - MDP3Quantity>; + Quantity>; void FifoMatcherContext::print_all_bbos(std::ostream &out) { std::vector rows; diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.h index adfc58896..a2d46aece 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMatcherContext.h @@ -24,20 +24,20 @@ struct FifoMatcherContext { ~FifoMatcherContext(); bool add_security( - MDP3SecurityID sec_id, + SecurityID sec_id, const std::string &symbol, const std::vector &legs); - bool remove_security(MDP3SecurityID sec_id); - void implied_matching_status(MDP3SecurityID sec_id, bool value); - bool implied_matching_status(MDP3SecurityID sec_id) const; + bool remove_security(SecurityID sec_id); + void implied_matching_status(SecurityID sec_id, bool value); + bool implied_matching_status(SecurityID sec_id) const; void clear(); - Book book(MDP3SecurityID sec_id, api::Side side); - ImpliedBook implied_book(MDP3SecurityID sec_id, api::Side side); + Book book(SecurityID sec_id, api::Side side); + ImpliedBook implied_book(SecurityID sec_id, api::Side side); // the Fills param records individual fills (potentially more than one per // order) void on_order_change( - MDP3SecurityID sec_id, + SecurityID sec_id, const std::vector &changes, std::vector *effects, FillDepot &fills); @@ -46,22 +46,22 @@ struct FifoMatcherContext { std::vector *effects, FillDepot &fills); void print_all_bbos(std::ostream &out); - std::optional has_same_orders(MDP3SecurityID, const Orders &); + std::optional has_same_orders(SecurityID, const Orders &); std::tuple - find_order(MDP3SecurityID, MDP3OrderKey); + find_order(SecurityID, OrderKey); private: struct PImpl; std::shared_ptr _me; // FifoMatcherContext(const FifoMatcherContext& other); - FifoMergedSecurityMatcher *_get_matcher(MDP3SecurityID sec_id); - const FifoMergedSecurityMatcher *_get_matcheri(MDP3SecurityID sec_id) const; - FifoMergedSecurityMatcher *_get_or_add_matcher(MDP3SecurityID sec_id); + FifoMergedSecurityMatcher *_get_matcher(SecurityID sec_id); + const FifoMergedSecurityMatcher *_get_matcheri(SecurityID sec_id) const; + FifoMergedSecurityMatcher *_get_or_add_matcher(SecurityID sec_id); void _ensure_sync_implied_candidates(); public: - FifoMergedSecurityMatcher *get_matcher(MDP3SecurityID sec_id) { + FifoMergedSecurityMatcher *get_matcher(SecurityID sec_id) { return _get_matcher(sec_id); } // This method doesn't check for crosses, as it assumes all of the orders @@ -70,7 +70,7 @@ struct FifoMatcherContext { // or after reset events). template inline void reset( - MDP3SecurityID sec_id, + SecurityID sec_id, TIter first, TIter last, std::vector *effects = nullptr) { diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.cpp index d146a7d41..5c73de5da 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.cpp @@ -40,7 +40,7 @@ struct FifoMergedSecurityMatcher::PImpl { implied_matchers.clear(); } - const MDP3SecurityID security_id; + const SecurityID security_id; const bool ignore_ops_on_deleted_orders; bool implied_matching_status; // the Security matcher is kept in a shared_ptr @@ -69,7 +69,7 @@ std::string FifoMergedSecurityMatcher::_log_header() const { return FMT("[", security_id(), "]", "FifoMergedSecurityMatcher"); } -MDP3SecurityID FifoMergedSecurityMatcher::security_id() const { +SecurityID FifoMergedSecurityMatcher::security_id() const { return _me->security_id; } /////////////////////// @@ -86,7 +86,7 @@ FifoMergedSecurityMatcher::implied_matchers() { return _me->implied_matchers; } FifoImpliedSecurityMatcher * -FifoMergedSecurityMatcher::add_implied_matcher(MDP3SecurityID sec) { +FifoMergedSecurityMatcher::add_implied_matcher(SecurityID sec) { auto *m = new FifoImpliedSecurityMatcher(sec); _me->implied_matchers.push_back(m); return m; @@ -224,14 +224,14 @@ ImpliedBook FifoMergedSecurityMatcher::implied_book(api::Side side) { .price; if (curr.price.is_nan()) break; - curr.quantity = MDP3Quantity(0); + curr.quantity = Quantity(0); // combine quantities of implied books with the same top price, as there // could be multiple. for (auto &ib_tup : ibooks) { auto &ib = std::get<0>(ib_tup); auto &index = std::get<1>(ib_tup); if (ib[index].price == curr.price) - curr.quantity = MDP3Quantity( + curr.quantity = Quantity( curr.quantity.value() + ib[index++].quantity.value()); } rem_exhausted(); @@ -268,10 +268,10 @@ void FifoMergedSecurityMatcher::merged_book( bts::md::IntPrice dprice( static_cast(dindex) < dbook.size() ? dbook[dindex].price : bts::md::IntPrice()); - MDP3Quantity dqty(dprice.is_nan() ? 0 : dbook[dindex].quantity.value()); + Quantity dqty(dprice.is_nan() ? 0 : dbook[dindex].quantity.value()); // init best price/qty bts::md::IntPrice best_price(dprice); - MDP3Quantity curr_qty(0); + Quantity curr_qty(0); // find best impl price for (auto &ib_tup : ibooks) { auto &ib = std::get<0>(ib_tup); @@ -285,12 +285,12 @@ void FifoMergedSecurityMatcher::merged_book( auto &index = std::get<1>(ib_tup); auto &bl = ib[index]; if (bl.price == best_price) { - curr_qty = MDP3Quantity(curr_qty.value() + bl.quantity.value()); + curr_qty = Quantity(curr_qty.value() + bl.quantity.value()); index++; } } if (dprice == best_price) { - curr_qty = MDP3Quantity(curr_qty.value() + dqty.value()); + curr_qty = Quantity(curr_qty.value() + dqty.value()); dindex++; } if (curr_qty.value() == 0) @@ -317,15 +317,15 @@ void FifoMergedSecurityMatcher::_fill( } inline SmallBookLevel -tuple_to_small_book_level(std::tuple t) { +tuple_to_small_book_level(std::tuple t) { return SmallBookLevel(std::get<0>(t), std::get<1>(t)); } -MDP3Quantity FifoMergedSecurityMatcher::_fill( - MDP3OrderKey key, +Quantity FifoMergedSecurityMatcher::_fill( + OrderKey key, api::Side side, bts::md::IntPrice price, - MDP3Quantity quantity, + Quantity quantity, std::vector *effects, FillDepot &fills) { // @@ -384,11 +384,11 @@ MDP3Quantity FifoMergedSecurityMatcher::_fill( aggr_fill.price = upd.last_price; aggr_fill.quantity = upd.last_fills; } else if (aggr_fill.price == upd.last_price) { - aggr_fill.quantity = MDP3Quantity( + aggr_fill.quantity = Quantity( aggr_fill.quantity.value() + upd.last_fills.value()); } else { fills.add_fill(security_id(), key, aggr_fill); - aggr_fill.quantity = MDP3Quantity(0); + aggr_fill.quantity = Quantity(0); aggr_fill.price = bts::md::IntPrice(); bts_assert(aggr_fill.price.is_nan()); } diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.h index 9fd8de45e..cbe92dec2 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoMergedSecurityMatcher.h @@ -12,19 +12,19 @@ namespace bts::spartan::mdp3 { struct FifoMergedSecurityMatcher { struct InitArgs { - MDP3SecurityID security_id; + SecurityID security_id; bool ignore_ops_on_deleted_orders; }; FifoMergedSecurityMatcher(const InitArgs &args); ~FifoMergedSecurityMatcher(); - MDP3SecurityID security_id() const; + SecurityID security_id() const; void implied_matching_status(bool value); bool implied_matching_status() const; void on_order_change( const SmallOrderChange &, std::vector *, FillDepot &); - FifoImpliedSecurityMatcher *add_implied_matcher(MDP3SecurityID); + FifoImpliedSecurityMatcher *add_implied_matcher(SecurityID); FifoSecurityMatcher *matcher(); const FifoSecurityMatcher *matcheri() const; const std::vector &implied_matchers(); @@ -47,11 +47,11 @@ struct FifoMergedSecurityMatcher { std::vector *, FillDepot &, bool reset_show_qty); - MDP3Quantity _fill( - MDP3OrderKey, + Quantity _fill( + OrderKey, api::Side, bts::md::IntPrice, - MDP3Quantity, + Quantity, std::vector *, FillDepot &); std::string _log_header() const; diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.cpp index dbb4c9f1f..04f81b2c1 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.cpp @@ -21,7 +21,7 @@ api::Side _opp_side(api::Side side) { : api::Side::SIDE_BUY; } // O(n) linear search -MatcherOrder *FifoPriceLevelMatcher::_find(MDP3OrderKey key) { +MatcherOrder *FifoPriceLevelMatcher::_find(OrderKey key) { for (MatcherOrder *op : _orders) if (in_this_level(op) && op->key == key) return op; @@ -61,10 +61,10 @@ void FifoPriceLevelMatcher::_reload_icebergs() { _orders.push_back(o); } } -std::tuple +std::tuple FifoPriceLevelMatcher::_one_pass_cross_order( - MDP3OrderKey cross_ord_key, - MDP3Quantity cross_ord_qty, + OrderKey cross_ord_key, + Quantity cross_ord_qty, bool add_agg_side_to_match_effect, std::vector *res) { // go through all the orders and see which ones get filled @@ -73,7 +73,7 @@ FifoPriceLevelMatcher::_one_pass_cross_order( if (in_this_level(op)) { auto &o = *op; auto [o_rem, cross_rem, filled] = o.cross(cross_ord_qty.value()); - cross_ord_qty = MDP3Quantity(cross_rem); + cross_ord_qty = Quantity(cross_rem); if (res != nullptr) { OrderUpdate passive_upd = { o.key, @@ -82,7 +82,7 @@ FifoPriceLevelMatcher::_one_pass_cross_order( : OrderUpdate::Status::FILLED, _sec, _side, - MDP3Quantity(filled), + Quantity(filled), _price, OrderUpdate::FillType::PASSIVE}; MatcherUtils::validate_outgoing_update(passive_upd); @@ -95,7 +95,7 @@ FifoPriceLevelMatcher::_one_pass_cross_order( : OrderUpdate::Status::FILLED, _sec, _opp_side(_side), - MDP3Quantity(filled), + Quantity(filled), _price, OrderUpdate::FillType::AGGRESSIVE}; MatcherUtils::validate_outgoing_update(agg_upd); @@ -125,7 +125,7 @@ void FifoPriceLevelMatcher::_log_order( if (_trace.log(ord.key)) LOG(OrderMan, Diag, "{} key:{} side:{} qty:{} ib_qty:{} price:{}", msg, ord.key, static_cast(side()), ord.quantity, - ord.ib.has_value() ? ord.ib.value().total : MDP3Quantity(0), price()); + ord.ib.has_value() ? ord.ib.value().total : Quantity(0), price()); } void FifoPriceLevelMatcher::_log_order( const MDP3Order &ord, const std::string &msg) { @@ -133,14 +133,14 @@ void FifoPriceLevelMatcher::_log_order( LOG(OrderMan, Diag, "{} key:{} side:{} qty:{} ib_qty:{} price:{}", msg, ord.key, static_cast(ord.side), ord.quantity, ord.iceberg_quantity.has_value() ? FMT(ord.iceberg_quantity.value()) - : FMT(MDP3Quantity(0)), + : FMT(Quantity(0)), ord.price.price()); } // constructors /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// FifoPriceLevelMatcher::FifoPriceLevelMatcher( - std::map &master_order_map, - MDP3SecurityID sec, + std::map &master_order_map, + SecurityID sec, md::IntPrice price, api::Side side, const Trace &trace) @@ -216,9 +216,9 @@ void FifoPriceLevelMatcher::on_new_same_side_order(const MDP3Order &new_ord) { _add_order(new_ord); } -std::tuple FifoPriceLevelMatcher::on_new_opp_order( - MDP3OrderKey opp_ord_key, - MDP3Quantity cross_qty, +std::tuple FifoPriceLevelMatcher::on_new_opp_order( + OrderKey opp_ord_key, + Quantity cross_qty, bool add_agg_side_to_match_effect, std::vector *res) { auto rv = _one_pass_cross_order( @@ -264,19 +264,19 @@ void FifoPriceLevelMatcher::on_order_cancel( OrderUpdate::Status::CANCELED, _sec, _side, - MDP3Quantity(0), + Quantity(0), _price, std::nullopt}; if (res != nullptr) res->push_back(o); } void FifoPriceLevelMatcher::on_order_remove( - MDP3OrderKey k, std::vector *res) { + OrderKey k, std::vector *res) { MatcherOrder *ord_p = _find(k); bts_assert(ord_p != nullptr); on_order_cancel(*ord_p, res); } -void FifoPriceLevelMatcher::remove_from_price_level(MDP3OrderKey k) { +void FifoPriceLevelMatcher::remove_from_price_level(OrderKey k) { // puts a nullptr in place of where this order was // (perioric cleanup will physically delete the slot) auto it = std::find_if(_orders.begin(), _orders.end(), [&](MatcherOrder *o) { diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.h index b3914efd4..51a90add5 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoPriceLevelMatcher.h @@ -16,8 +16,8 @@ class FifoPriceLevelMatcher { // for all the orders for the security. orders are created // here but added to the map mantained by the // sec level matcher - std::map *_master_order_map; - MDP3SecurityID _sec; + std::map *_master_order_map; + SecurityID _sec; md::IntPrice _price; api::Side _side; std::vector _orders; @@ -28,7 +28,7 @@ class FifoPriceLevelMatcher { // //////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// private: - MatcherOrder *_find(MDP3OrderKey key); + MatcherOrder *_find(OrderKey key); void _logically_delete(MatcherOrder &o); void _add_order(const MDP3Order &ord); // crosses the cross_order with existing orders. returns @@ -37,9 +37,9 @@ class FifoPriceLevelMatcher { // crosses the order in the args with the orders at this level. // returns the tuple of rem qty at this level and the rem qty // of the cross order - std::tuple _one_pass_cross_order( - MDP3OrderKey cross_ord_key, - MDP3Quantity cross_ord_qty, + std::tuple _one_pass_cross_order( + OrderKey cross_ord_key, + Quantity cross_ord_qty, bool add_agg_side_to_match_effect, std::vector *res); void _log_order(const MatcherOrder &ord, const std::string &msg); @@ -49,8 +49,8 @@ class FifoPriceLevelMatcher { // constructors //////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// FifoPriceLevelMatcher( - std::map &, - MDP3SecurityID sec, + std::map &, + SecurityID sec, md::IntPrice price, api::Side side, const Trace &); @@ -72,18 +72,18 @@ class FifoPriceLevelMatcher { // simple accessors //////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// std::tuple n_orders_qty(bool visible_only = true) const; - MDP3Quantity quantity() const { - return MDP3Quantity(std::get<1>(n_orders_qty())); + Quantity quantity() const { + return Quantity(std::get<1>(n_orders_qty())); } - MDP3Quantity total_quantity() const { - return MDP3Quantity(std::get<1>(n_orders_qty(false))); + Quantity total_quantity() const { + return Quantity(std::get<1>(n_orders_qty(false))); } uint32_t n_orders() const { return std::get<0>(n_orders_qty()); } bool populated() const; md::IntPrice price() const { return _price; } double price_double() const { return _price.price(); } api::Side side() const { return _side; } - MatcherOrder *find_order(MDP3OrderKey key) { return _find(key); } + MatcherOrder *find_order(OrderKey key) { return _find(key); } BookLevel book_level() const { return BookLevel{_price, quantity(), static_cast(n_orders())}; } @@ -101,17 +101,17 @@ class FifoPriceLevelMatcher { // order update such that only the qty changed (other changes // are handled at a higher level) // new order such that it crosses this price level - std::tuple on_new_opp_order( - MDP3OrderKey opp_ord_key, - MDP3Quantity opp_ord_qty, + std::tuple on_new_opp_order( + OrderKey opp_ord_key, + Quantity opp_ord_qty, bool add_agg_side_to_match_effect, std::vector * = nullptr); void on_order_update(const MDP3Order &upd_ord, MatcherOrder *ord_hint = nullptr); void on_order_cancel(MatcherOrder &order, std::vector * = nullptr); - void on_order_remove(MDP3OrderKey k, std::vector * = nullptr); - void remove_from_price_level(MDP3OrderKey k); + void on_order_remove(OrderKey k, std::vector * = nullptr); + void remove_from_price_level(OrderKey k); void cleanup(); std::string print_mbo(size_t n_orders) const; }; diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.cpp index 17491ed09..3fdaf9e01 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.cpp @@ -19,7 +19,7 @@ _is_cross(const MDP3Order &ord, const FifoPriceLevelMatcher &price_level) { ord.price <= price_level.price())); } -inline MDP3Quantity total_quantity(const MDP3Order &ord) { +inline Quantity total_quantity(const MDP3Order &ord) { return ord.iceberg_quantity.has_value() ? ord.iceberg_quantity.value().total : ord.quantity; } @@ -39,7 +39,7 @@ FifoSecurityMatcher::_find_price_level(api::Side side, md::IntPrice price) { } std::tuple -FifoSecurityMatcher::_find_order(MDP3OrderKey key) { +FifoSecurityMatcher::_find_order(OrderKey key) { auto map_it = _order_map.find(key); if (map_it != _order_map.end()) { auto &ord = map_it->second; @@ -106,7 +106,7 @@ void FifoSecurityMatcher::_on_new_order( for (FifoPriceLevelMatcher &pl : opp_book) { if (_is_cross(ord, pl)) { auto t = - pl.on_new_opp_order(ord.key, MDP3Quantity(new_ord_rem), true, res); + pl.on_new_opp_order(ord.key, Quantity(new_ord_rem), true, res); new_ord_rem = std::get<1>(t).value(); } else break; @@ -123,7 +123,7 @@ void FifoSecurityMatcher::_on_new_order( MDP3Order ord_corrected = ord; if (ord_corrected.iceberg_quantity.has_value()) { auto ibq = ord.iceberg_quantity.value(); - auto filled_qty = ibq.total - MDP3Quantity(new_ord_rem); + auto filled_qty = ibq.total - Quantity(new_ord_rem); // important: don't subtract filled_qty from the total // of the IcebergQuantity (ibq) param passed to 'get_reload_qty.' ord_corrected.quantity = @@ -138,7 +138,7 @@ void FifoSecurityMatcher::_on_new_order( auto it = _order_map.find(ord.key); if (it != _order_map.end()) { MatcherOrder &ex_ord = it->second; - ex_ord.quantity = MDP3Quantity(0); + ex_ord.quantity = Quantity(0); ex_ord.is_active = false; } } @@ -192,7 +192,7 @@ void FifoSecurityMatcher::_on_order_update( } void FifoSecurityMatcher::_on_order_remove( - MDP3OrderKey key, std::vector *res) { + OrderKey key, std::vector *res) { if (_trace.log(key)) LOG(OrderMan, Diag, "FifoSecurityMatcher::_on_order_remove " @@ -238,7 +238,7 @@ void FifoSecurityMatcher::_on_order_not_affecting_books( ord.key, new_ord_rem > 0 ? OrderUpdate::Status::PARTIALLY_FILLED : OrderUpdate::Status::FILLED, - ord.security, ord.side, MDP3Quantity(fill_size), pl.price(), + ord.security, ord.side, Quantity(fill_size), pl.price(), OrderUpdate::FillType::AGGRESSIVE}); } else break; @@ -251,7 +251,7 @@ void FifoSecurityMatcher::_on_order_not_affecting_books( if (res != nullptr) res->push_back(OrderUpdate{ ord.key, OrderUpdate::Status::CANCELED, ord.security, ord.side, - MDP3Quantity(0), md::IntPrice(), std::nullopt}); + Quantity(0), md::IntPrice(), std::nullopt}); // nothing to do since this order was never made a part of the book break; } @@ -259,12 +259,12 @@ void FifoSecurityMatcher::_on_order_not_affecting_books( // constructors /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// FifoSecurityMatcher::FifoSecurityMatcher( - MDP3SecurityID security, size_t event_id) + SecurityID security, size_t event_id) : FifoSecurityMatcher(FifoSecurityMatcher::FifoSecurityMatcherArgs{ security, event_id, true, nullptr}) {} FifoSecurityMatcher::FifoSecurityMatcher( - MDP3SecurityID security, size_t event_id, const Orders &orders) + SecurityID security, size_t event_id, const Orders &orders) : FifoSecurityMatcher(FifoSecurityMatcher::FifoSecurityMatcherArgs{ security, event_id, true, &orders}) {} @@ -272,7 +272,7 @@ FifoSecurityMatcher::FifoSecurityMatcher( FifoSecurityMatcher::FifoSecurityMatcherArgs args) : _order_map(), _bids(), _asks(), _search_tok( _order_map, - MDP3SecurityID{}, + SecurityID{}, md::IntPrice(), api::Side::SIDE_BUY, Trace()), @@ -335,19 +335,19 @@ size_t FifoSecurityMatcher::total_n_orders(api::Side side) const { rv += p_level.n_orders(); return rv; } -MDP3Quantity FifoSecurityMatcher::total_qty(api::Side side) const { +Quantity FifoSecurityMatcher::total_qty(api::Side side) const { auto rv = 0; for (const auto &p_level : _book(side)) rv += p_level.total_quantity().value(); - return MDP3Quantity(rv); + return Quantity(rv); } -std::tuple +std::tuple FifoSecurityMatcher::book_level(api::Side side, size_t idx) const { size_t i = 0; for (const auto &p_level : _book(side)) if (p_level.populated() && i++ == idx) return std::make_tuple(p_level.price(), p_level.total_quantity()); - return std::make_tuple(md::INT_NAN, MDP3Quantity(0)); + return std::make_tuple(md::INT_NAN, Quantity(0)); } void FifoSecurityMatcher::on_order_change( SmallOrderChange const &o, std::vector *res) { @@ -376,7 +376,7 @@ void FifoSecurityMatcher::on_order_change( } } -void FifoSecurityMatcher::on_order_completed(MDP3OrderKey key) { +void FifoSecurityMatcher::on_order_completed(OrderKey key) { // todo: actual implementation // (this is a hack that treats completed orders like cancels) auto [pl, ord] = _find_order(key); @@ -390,11 +390,11 @@ void FifoSecurityMatcher::on_order_completed(MDP3OrderKey key) { on_order_change(ch); } -MDP3Quantity FifoSecurityMatcher::fill( - MDP3OrderKey aggr_key, +Quantity FifoSecurityMatcher::fill( + OrderKey aggr_key, api::Side side, md::IntPrice agg_price, - MDP3Quantity qty, + Quantity qty, std::vector *res, bool add_aggr_fill) { FifoPriceLevelMatcher *top = _top(_opp_side(side)); @@ -404,7 +404,7 @@ MDP3Quantity FifoSecurityMatcher::fill( _invalidate_mbp(); return std::get<1>(t); } - return MDP3Quantity(0); + return Quantity(0); } std::optional @@ -488,7 +488,7 @@ std::string FifoSecurityMatcher::print_book(size_t n_levels) { } void FifoSecurityMatcher::_log_trace_order_state(const std::string &msg) { for (const auto &kv : _trace.traced_orders) { - MDP3OrderKey k = kv.first; + OrderKey k = kv.first; auto [pl, o] = _find_order(k); if (pl != nullptr && o != nullptr) LOG(OrderMan, Diag, diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.h index 5e6b71a58..f10d2443f 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/FifoSecurityMatcher.h @@ -14,7 +14,7 @@ namespace bts::spartan::mdp3 { class FifoSecurityMatcher : public SecurityMatcher { public: struct FifoSecurityMatcherArgs { - MDP3SecurityID security_id; + SecurityID security_id; const size_t event_id = 0; const bool ignore_ops_on_deleted_orders = true; Orders const *orders = nullptr; @@ -43,12 +43,12 @@ class FifoSecurityMatcher : public SecurityMatcher { // while map (trees) are slower than unordered_map (pure hashtables), // pointers get invalidated when they are rehashed (since we dont // have a key collision, would it be rehashed?) - std::map _order_map; + std::map _order_map; // ask prices are sorted lowest to highest and and bid prices // are sorted highest to lowest (see BookKeeper::_book). BookKeeper _bids, _asks; FifoPriceLevelMatcher _search_tok; - const MDP3SecurityID _sec; + const SecurityID _sec; const size_t _event_id; const Trace _trace; const bool _ignore_ops_on_deleted_orders; @@ -75,7 +75,7 @@ class FifoSecurityMatcher : public SecurityMatcher { // for the order, from the order it gets the price, side and searches // for price level in the book (flat_set) std::tuple - _find_order(MDP3OrderKey key); + _find_order(OrderKey key); FifoPriceLevelMatcher *_top(api::Side side); void _cleanup(); // order interaction @@ -84,7 +84,7 @@ class FifoSecurityMatcher : public SecurityMatcher { const MDP3Order &, bool price_only = false, std::vector * = nullptr); - void _on_order_remove(MDP3OrderKey, std::vector * = nullptr); + void _on_order_remove(OrderKey, std::vector * = nullptr); void _on_order_not_affecting_books( const SmallOrderChange &o, std::vector *res); std::string _log_header() const; @@ -92,9 +92,9 @@ class FifoSecurityMatcher : public SecurityMatcher { public: // cons/dest /////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////// - FifoSecurityMatcher(MDP3SecurityID security, size_t event_id = 0); + FifoSecurityMatcher(SecurityID security, size_t event_id = 0); FifoSecurityMatcher( - MDP3SecurityID security, size_t event_id, Orders const &); + SecurityID security, size_t event_id, Orders const &); FifoSecurityMatcher(FifoSecurityMatcher::FifoSecurityMatcherArgs); ~FifoSecurityMatcher(); // SecurityMatcher implementation ////////////////////////////////////////// @@ -114,22 +114,22 @@ class FifoSecurityMatcher : public SecurityMatcher { // However, the fill qty may also be constricted to a certain number of // price levels. This is because the market with the best price doesn't // necessarily have the 2nd best price as well. - MDP3Quantity fill( - MDP3OrderKey aggr_key, + Quantity fill( + OrderKey aggr_key, api::Side side, md::IntPrice price, - MDP3Quantity qty, + Quantity qty, std::vector *res, bool add_aggr_fill); - std::tuple + std::tuple book_level(api::Side side, size_t idx) const override; void on_order_change( SmallOrderChange const &, std::vector * = nullptr) override; - void on_order_completed(MDP3OrderKey key); + void on_order_completed(OrderKey key); // For testing std::optional has_same_orders(Orders const &); size_t total_n_orders(api::Side) const; - MDP3Quantity total_qty(api::Side) const; + Quantity total_qty(api::Side) const; // Removes existing orders. void clear(); // Removes existing orders, then populates the book with the @@ -143,7 +143,7 @@ class FifoSecurityMatcher : public SecurityMatcher { } std::tuple - find_order(MDP3OrderKey key) { + find_order(OrderKey key) { return _find_order(key); } // debugging logging diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/ImpliedFifoSecurityMatcher.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/ImpliedFifoSecurityMatcher.h index 95f53436c..ada708dea 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/ImpliedFifoSecurityMatcher.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/ImpliedFifoSecurityMatcher.h @@ -13,12 +13,12 @@ namespace bts::spartan::mdp3 { struct ImpliedFifoSecurityMatcher { - ImpliedFifoSecurityMatcher(MDP3SecurityID security_id) + ImpliedFifoSecurityMatcher(SecurityID security_id) : _security_id(security_id), _implied_mkt() {} ImpliedBook book(api::Side side) const; - MDP3Quantity - fill(MDP3OrderKey key, api::Side side, MDP3Quantity qty, FillDepot &fills); + Quantity + fill(OrderKey key, api::Side side, Quantity qty, FillDepot &fills); // Note: this class is NOT responsible for deleting any FifoSecurityMatcher // pointers. The FifoMatcherContext creates one FifoMergedSecurityMatcher per // each security, and each FifoMergedSecurityMatcher creates/owns a @@ -28,23 +28,23 @@ struct ImpliedFifoSecurityMatcher { // Note the absense of a 'side' parameter: unit_qty should be positive for // Buys, negative for Sells. void add_leg( - MDP3SecurityID sec_id, FifoSecurityMatcher *m, MDP3Quantity unit_qty) { + SecurityID sec_id, FifoSecurityMatcher *m, Quantity unit_qty) { _implied_mkt.insert({sec_id, {m, unit_qty}}); } - MDP3SecurityID security_id() const { return _security_id; } - std::tuple top_of_book(api::Side side) const; + SecurityID security_id() const { return _security_id; } + std::tuple top_of_book(api::Side side) const; private: - MDP3SecurityID _security_id; - std::map> + SecurityID _security_id; + std::map> _implied_mkt; // hide copy ctr ImpliedFifoSecurityMatcher(const ImpliedFifoSecurityMatcher &); void _book( api::Side side, - std::vector> &dest) const; + std::vector> &dest) const; uint32_t _fill_order(const MDP3Order &order); }; } // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.cpp index 28b1bfc8f..f5760146e 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.cpp @@ -30,7 +30,7 @@ void MergedMatcher::add_def(const InstrumentDefinition &def) { m->second.implied_matching_status(def.security_id(), def.implied_matching()); } -std::string MergedMatcher::_get_asset(MDP3SecurityID sec) const { +std::string MergedMatcher::_get_asset(SecurityID sec) const { auto it = _asset_map.find(sec); return it == _asset_map.end() ? std::string() : it->second; } @@ -92,7 +92,7 @@ struct MBPSnapshot { }; FifoMatcherContext & -MergedMatcher::_asset_matcher(MDP3SecurityID sec, bool add_if_missing) { +MergedMatcher::_asset_matcher(SecurityID sec, bool add_if_missing) { auto ass_it = _asset_map.find(sec); if (add_if_missing && ass_it == _asset_map.end()) ass_it = _asset_map.emplace(sec, std::string()).first; @@ -116,13 +116,13 @@ void MergedMatcher::match( // 2) process the order changes, // 3) compare the current books with the snapshots to detect mbp changes. // The map's hierarchcy is asset->security->books. - std::map> mbps; + std::map> mbps; for (const auto &c : changes) { bts_assert(c.order.key.value() != 0); auto ass = _get_asset(c.order.security); auto it = mbps.find(ass); if (it == mbps.end()) - it = mbps.emplace(ass, std::map()).first; + it = mbps.emplace(ass, std::map()).first; auto mbp_tup_it = it->second.find(c.order.security); if (mbp_tup_it == it->second.end()) { auto *mat = _matcher_map[ass].get_matcher(c.order.security); @@ -179,11 +179,11 @@ void MergedMatcher::match( } } -Book MergedMatcher::book(MDP3SecurityID id, api::Side s) { +Book MergedMatcher::book(SecurityID id, api::Side s) { return _asset_matcher(id).book(id, s); } -ImpliedBook MergedMatcher::implied_book(MDP3SecurityID id, api::Side s) { +ImpliedBook MergedMatcher::implied_book(SecurityID id, api::Side s) { return _asset_matcher(id).implied_book(id, s); } @@ -203,9 +203,9 @@ DirectMatcher::DirectMatcher(DirectMatcher &&src) { _matcher_map = std::move(src._matcher_map); } -DirectMatcher::DirectMatcher(const std::vector &inst_defs) { +DirectMatcher::DirectMatcher(const std::vector &inst_defs) { for (const auto &sec_id : inst_defs) - _matcher_map.insert(std::pair( + _matcher_map.insert(std::pair( sec_id, FifoSecurityMatcher(sec_id))); } @@ -215,7 +215,7 @@ void DirectMatcher::match( std::vector *res) { _match_count_this_per++; _match_count++; - std::vector> dirty; + std::vector> dirty; dirty.reserve(_matcher_map.size()); for (const auto &c : changes) { @@ -249,7 +249,7 @@ void DirectMatcher::match( } } -Book DirectMatcher::book(MDP3SecurityID id, api::Side s) { +Book DirectMatcher::book(SecurityID id, api::Side s) { auto it = _matcher_map.find(id); bts_assert(it != _matcher_map.end()); return it->second.book(s); diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.h index ea3b6828d..e9b1d2de3 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/Matcher.h @@ -16,16 +16,16 @@ class InstrumentDefinition; class MergedMatcher { private: - std::unordered_set _used_order_keys; - std::map _asset_map; + std::unordered_set _used_order_keys; + std::map _asset_map; std::map _matcher_map; Trace _trace; size_t _match_count; size_t _match_count_this_per; google::protobuf::Timestamp _per_start_time; - std::string _get_asset(MDP3SecurityID sec) const; + std::string _get_asset(SecurityID sec) const; FifoMatcherContext & - _asset_matcher(MDP3SecurityID, bool add_if_missing = true); + _asset_matcher(SecurityID, bool add_if_missing = true); public: MergedMatcher(); @@ -40,8 +40,8 @@ class MergedMatcher { void match(ChangeSrc, SmallOrderChangeVec const &, std::vector *); - Book book(MDP3SecurityID, api::Side); - ImpliedBook implied_book(MDP3SecurityID, api::Side); + Book book(SecurityID, api::Side); + ImpliedBook implied_book(SecurityID, api::Side); template void init(TIter first, TIter last) { while (first != last) { @@ -51,7 +51,7 @@ class MergedMatcher { } void reset( - MDP3SecurityID sec, + SecurityID sec, std::vector orders, std::vector *effects = nullptr) { for (const auto &o : orders) @@ -65,7 +65,7 @@ class MergedMatcher { // need to investigate before DirectMatcher can be retired). class DirectMatcher { private: - std::map _matcher_map; + std::map _matcher_map; Trace _trace; size_t _match_count; size_t _match_count_this_per; @@ -73,7 +73,7 @@ class DirectMatcher { public: DirectMatcher(); - DirectMatcher(std::vector const &); + DirectMatcher(std::vector const &); DirectMatcher(DirectMatcher &&); DirectMatcher &operator=(DirectMatcher &&) { return *this; } @@ -84,10 +84,10 @@ class DirectMatcher { void match(ChangeSrc, SmallOrderChangeVec const &, std::vector *); - Book book(MDP3SecurityID, api::Side); - ImpliedBook implied_book(MDP3SecurityID, api::Side); + Book book(SecurityID, api::Side); + ImpliedBook implied_book(SecurityID, api::Side); - template void reset(MDP3SecurityID sec, Iter first, Iter last) { + template void reset(SecurityID sec, Iter first, Iter last) { _matcher_map.try_emplace(sec).first->second.reset(first, last); } void clear(); diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.cpp index 9ea7494d6..eabb22956 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.cpp @@ -7,9 +7,9 @@ MatcherOrder::cross(uint32_t cross_qty) { auto [r, c] = compute_cross(quantity.value(), cross_qty); bts_assert(quantity.value() - r == cross_qty - c); auto filled = cross_qty - c; - quantity = MDP3Quantity(r); + quantity = Quantity(r); if (ib.has_value()) { - ib.value().total -= MDP3Quantity(filled); + ib.value().total -= Quantity(filled); is_active = ib.value().total.value() > 0; } else is_active = quantity.value() > 0; @@ -24,4 +24,4 @@ void MatcherOrder::reload_ib() { is_active = quantity.value() > 0; } } -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.h index e9dd63b90..267ce5150 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/MatchingCommon.h @@ -10,11 +10,11 @@ namespace bts::spartan::mdp3 { struct Trace { public: - const std::map traced_orders = { - {MDP3OrderKey(765164629193), true}}; + const std::map traced_orders = { + {OrderKey(765164629193), true}}; const std::map traced_events = {}; const std::map ignored_events = {}; - bool log(MDP3OrderKey key, size_t eid = 0) const { + bool log(OrderKey key, size_t eid = 0) const { return traced_orders.find(key) != traced_orders.end() || traced_events.find(eid) != traced_events.end(); } @@ -85,18 +85,18 @@ struct MatcherOrder { } return std::make_tuple(resting_qty, cross_qty); } - MDP3OrderKey key; + OrderKey key; api::Side side; md::IntPrice price; - MDP3Quantity quantity; + Quantity quantity; uint32_t priority = 0; std::optional ib; bool is_active = true; MatcherOrder( - MDP3OrderKey key, + OrderKey key, api::Side side, md::IntPrice price, - MDP3Quantity qty, // working qty out there + Quantity qty, // working qty out there uint32_t priority, std::optional ib = {}) : key(key), side(side), price(price), quantity(qty), priority(priority), @@ -105,10 +105,10 @@ struct MatcherOrder { // (ie the new qty NOT the filled qty, for that subtract from // original) std::tuple cross(uint32_t cross_qty); - MDP3Quantity total_qty() const { + Quantity total_qty() const { return ib.has_value() ? ib.value().total : quantity; } - MDP3Quantity working_qty() const { return quantity; } + Quantity working_qty() const { return quantity; } bool ready_to_load_ib() const { return ib.has_value() && quantity.value() == 0 && ib.value().total.value() > 0; diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/SecurityMatcher.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/SecurityMatcher.h index c0d5ddb07..14c9614ca 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/SecurityMatcher.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/SecurityMatcher.h @@ -14,7 +14,7 @@ class SecurityMatcher { // when this method is called if its book is dirty, // and has to be recomputed. virtual Book book(api::Side) = 0; - virtual std::tuple + virtual std::tuple book_level(api::Side, size_t level = 0) const = 0; // mutators virtual void on_order_change( diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.cpp index c15102ea2..8a1f4b155 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.cpp @@ -12,12 +12,12 @@ using namespace ranges; namespace bts::spartan::mdp3 { bool FillDepot::add_fill( - MDP3SecurityID sec, MDP3OrderKey aggressor, MDP3Fill f) { + SecurityID sec, OrderKey aggressor, MDP3Fill f) { auto sfit = _cache.find(sec); if (sfit == _cache.end()) { auto p = _cache.emplace( sec, std::unordered_map< - MDP3OrderKey, std::unordered_map>()); + OrderKey, std::unordered_map>()); sfit = p.first; } auto ofit = sfit->second.find(f.key); @@ -37,7 +37,7 @@ bool FillDepot::add_fill( return false; } -MDP3Quantity FillNode::total_fill_qty() const { +Quantity FillNode::total_fill_qty() const { auto dfills = accumulate( direct_passive | views::transform([](auto &f) { return f.quantity.value(); }), @@ -46,13 +46,13 @@ MDP3Quantity FillNode::total_fill_qty() const { implied_passive | views::transform([](auto &f) { return f.quantity.value(); }), 0); - return MDP3Quantity( + return Quantity( buy_aggressor.quantity.value() + sell_aggressor.quantity.value() + dfills + ifills); } -MDP3Quantity FillDepot::total_fill_qty() const { - return MDP3Quantity(accumulate( +Quantity FillDepot::total_fill_qty() const { + return Quantity(accumulate( _cache | views::transform([](auto &kv) { return accumulate( kv.second | views::transform([](auto &of) { @@ -77,7 +77,7 @@ void FillDepot::copy_to(std::vector &dest) const { } void FillDepot::copy_to( - std::unordered_map> &dest) const { + std::unordered_map> &dest) const { for (auto &sec_fills : _cache) { auto &fills = dest.emplace(sec_fills.first, std::vector()).first->second; @@ -103,4 +103,4 @@ bool FillNode::match(const MDP3Fill &f) const { } return false; } -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.h index bb15af7e4..131ce71d2 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_depot.h @@ -31,7 +31,7 @@ struct FillNode { bts_assert(target.aggressor == fill.aggressor); } target.quantity = - MDP3Quantity(fill.quantity.value() + target.quantity.value()); + Quantity(fill.quantity.value() + target.quantity.value()); return is_new; } @@ -49,8 +49,8 @@ struct FillNode { public: uint32_t fill_count() const { return _fill_count; } - void set_curr_aggressor(MDP3OrderKey k) { curr_aggressor = k; } - bool merge(MDP3OrderKey aggressor, MDP3Fill f) { + void set_curr_aggressor(OrderKey k) { curr_aggressor = k; } + bool merge(OrderKey aggressor, MDP3Fill f) { bool rv = false; switch (f.aggressor) { case MDP3Fill::Aggressor::THIS_BUY: @@ -87,32 +87,32 @@ struct FillNode { for (auto f : implied_passive) dest.push_back(f); } - MDP3Quantity total_fill_qty() const; + Quantity total_fill_qty() const; private: MDP3Fill buy_aggressor; MDP3Fill sell_aggressor; - MDP3OrderKey curr_aggressor; + OrderKey curr_aggressor; std::vector direct_passive, implied_passive; uint32_t _fill_count = 0; }; struct FillDepot { - bool add_fill(MDP3SecurityID sec, MDP3OrderKey aggressor, MDP3Fill f); + bool add_fill(SecurityID sec, OrderKey aggressor, MDP3Fill f); uint32_t fill_count() const { return _fill_count; } - MDP3Quantity total_fill_qty() const; - MDP3Quantity aggressor_fill_qty( - MDP3SecurityID sec, MDP3OrderKey ord, int max_fill_items = 9999999) { + Quantity total_fill_qty() const; + Quantity aggressor_fill_qty( + SecurityID sec, OrderKey ord, int max_fill_items = 9999999) { bts_assert(max_fill_items >= 0); if (max_fill_items == 0) - return MDP3Quantity(0); + return Quantity(0); auto it = _cache.find(sec); if (it == _cache.end()) { - return MDP3Quantity(0); + return Quantity(0); } auto ord_it = it->second.find(ord); if (ord_it == it->second.end()) { - return MDP3Quantity(0); + return Quantity(0); } int res = 0; for (auto pfit = ord_it->second.begin(); pfit != ord_it->second.end(); @@ -125,26 +125,26 @@ struct FillDepot { case MDP3Fill::Aggressor::THIS_SELL: res += f.quantity.value(); if (--max_fill_items == 0) - return MDP3Quantity(res); + return Quantity(res); break; default: break; } } } - return MDP3Quantity(res); + return Quantity(res); } void copy_to(std::vector &dest) const; void copy_to( - std::unordered_map> &dest) const; + std::unordered_map> &dest) const; private: uint32_t _fill_count = 0; std::unordered_map< - MDP3SecurityID, - std::unordered_map>> + SecurityID, + std::unordered_map>> _cache; }; std::ostream &operator<<(std::ostream &out, const FillDepot &fd); -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_factory.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_factory.h index 710f5afbf..5cc6d7489 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_factory.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/fill_factory.h @@ -25,7 +25,7 @@ _to_passive_fill(const OrderUpdate &upd, bool implied_aggressor) { } inline MDP3Fill -_to_aggressor_fill(MDP3OrderKey k, api::Side side, const OrderUpdate &upd) { +_to_aggressor_fill(OrderKey k, api::Side side, const OrderUpdate &upd) { MDP3Fill aggr; aggr.key = k; aggr.price = upd.last_price; @@ -33,4 +33,4 @@ _to_aggressor_fill(MDP3OrderKey k, api::Side side, const OrderUpdate &upd) { aggr.aggressor = _to_aggressor(side); return aggr; } -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp index 69414064a..1389081db 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.cpp @@ -13,7 +13,7 @@ namespace bts::spartan::mdp3::iceberg_helper { void add_iceberg_annotation( MDP3Order &o, OrderChange::ChangeType change_type, - const std::unordered_map &icebergs, + const std::unordered_map &icebergs, size_t event_id, bool set_exact_state) { const auto *ib = find_value(o.key, icebergs); @@ -88,9 +88,9 @@ void add_iceberg_annotation( } } -MDP3Quantity get_reload_qty( - MDP3Quantity vis_qty, - MDP3Quantity fill_qty, +Quantity get_reload_qty( + Quantity vis_qty, + Quantity fill_qty, const IcebergQuantity &ib_before_fill) { vis_qty = std::min(vis_qty, std::min(ib_before_fill.show, ib_before_fill.total)) - diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.h index 584d543b3..83cc9fd5d 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/iceberg_helper.h @@ -14,7 +14,7 @@ namespace bts::spartan::mdp3::iceberg_helper { void add_iceberg_annotation( MDP3Order &, OrderChange::ChangeType, - const std::unordered_map &, + const std::unordered_map &, size_t event_id, bool set_exact_state = false); @@ -58,8 +58,8 @@ void add_iceberg_annotation( size_t event_id, bool set_exact_state); -MDP3Quantity get_reload_qty( - MDP3Quantity vis_qty, - MDP3Quantity fill_qty, +Quantity get_reload_qty( + Quantity vis_qty, + Quantity fill_qty, const IcebergQuantity &ib_before_fill); } // namespace bts::spartan::mdp3::iceberg_helper diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/matcher_diagnostics.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/matcher_diagnostics.h index 74beb25ba..85cfd6948 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/matcher_diagnostics.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/matcher_diagnostics.h @@ -147,7 +147,7 @@ print_detailed_orders(TIter first, TIter last, std::ostream &out = std::cout) { std::vector)>>>{ + std::tuple)>>>{ {" Sec ID ", 12, [](auto o) { return FMT(std::get<0>(o)); }}, {" Symbol ", 12, [](auto o) { return std::get<1>(o); }}, {" Order ", 12, [](auto o) { return FMT(std::get<2>(o).key); }}, @@ -191,7 +191,7 @@ inline void print_detailed_order_changes( std::vector)>>>{ + std::tuple)>>>{ {" Sec ID ", 12, [](auto ch) { return FMT(std::get<0>(ch)); }}, {" Symbol ", 12, [](auto ch) { return std::get<1>(ch); }}, {" Order ", 12, @@ -223,10 +223,10 @@ inline void print_instrument_snapshots( b | ranges::views::transform( [](const BookLevel &l) { return l.quantity.value(); }), 0); - return MDP3Quantity(vol); + return Quantity(vol); }; auto total_book_volume = [&](const InstrumentSnapshot *snap) { - return MDP3Quantity( + return Quantity( book_volume(snap, api::Side::SIDE_BUY).value() + book_volume(snap, api::Side::SIDE_SELL).value()); }; @@ -320,8 +320,8 @@ inline void print_bbo(std::ostream &out, TIter first, TIter last) { std::string, int, std::function)>>>{ + std::string, bts::md::IntPrice, Quantity, + bts::md::IntPrice, Quantity>)>>>{ {" Security ", 12, [](auto r) { return std::get<0>(r); }}, {" Qty ", 10, [](auto r) { return FMT(std::get<2>(r)); }}, {" Bid ", 10, [](auto r) { return FMT(std::get<1>(r)); }}, @@ -333,8 +333,8 @@ inline void print_bbo(std::ostream &out, TIter first, TIter last) { template inline void print_many_bbo(std::ostream &out, TIter first, TIter last) { std::vector> + std::string, bts::md::IntPrice, Quantity, bts::md::IntPrice, + Quantity>> rows; while (first != last) { const InstrumentSnapshot *s = *first; @@ -351,8 +351,8 @@ inline void print_many_bbo(std::ostream &out, TIter first, TIter last) { template inline void print_many_bbo_implied(std::ostream &out, TIter first, TIter last) { std::vector> + std::string, bts::md::IntPrice, Quantity, bts::md::IntPrice, + Quantity>> rows; while (first != last) { const InstrumentSnapshot *s = *first; @@ -379,9 +379,9 @@ inline void print_many_bbo( print_many_bbo_implied(out, first, last); } else if (direct && implied) { std::vector> + std::string, bts::md::IntPrice, Quantity, bts::md::IntPrice, + Quantity, bts::md::IntPrice, Quantity, bts::md::IntPrice, + Quantity>> rows; while (first != last) { const InstrumentSnapshot *s = *first; @@ -401,9 +401,9 @@ inline void print_many_bbo( std::string, int, std::function)>>>{ + std::string, bts::md::IntPrice, Quantity, + bts::md::IntPrice, Quantity, bts::md::IntPrice, + Quantity, bts::md::IntPrice, Quantity>)>>>{ {" Security ", 12, [](auto r) { return std::get<0>(r); }}, {"I Qty", 6, [](auto r) { return FMT(std::get<6>(r)); }}, {" I Bid ", 8, [](auto r) { return FMT(std::get<5>(r)); }}, @@ -416,4 +416,4 @@ inline void print_many_bbo( out << std::endl; } } -} // namespace bts::spartan::mdp3::diagnostics \ No newline at end of file +} // namespace bts::spartan::mdp3::diagnostics diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/tests/matcher_tests.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/tests/matcher_tests.cpp index 7fc4bbacf..8a50ca8f2 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/tests/matcher_tests.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/tests/matcher_tests.cpp @@ -40,12 +40,12 @@ MDP3Order create_order( uint32_t qty, std::optional ib = {}) { auto rv = MDP3Order{ - MDP3OrderKey(key), - MDP3SecurityID(sec), + OrderKey(key), + SecurityID(sec), side, MDP3OrderPriority(priority), md::IntPrice_from_double<7>(price), - MDP3Quantity(qty), + Quantity(qty), ib}; return rv; } @@ -59,9 +59,9 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { double price = 100.0; api::Side side = api::Side::SIDE_BUY; Trace trace; - std::map master_ord_map; + std::map master_ord_map; FifoPriceLevelMatcher price_level( - master_ord_map, MDP3SecurityID(0), md::IntPrice_from_double<7>(price), + master_ord_map, SecurityID(0), md::IntPrice_from_double<7>(price), side, trace); auto create_book = [&](int n_orders) -> void { for (int i = 1; i <= n_orders; i++) { @@ -84,7 +84,7 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { // remove last 10 orders, 91-100 for (int i = 91; i <= 100; i++) { auto ord_key = static_cast(i); - price_level.on_order_remove(MDP3OrderKey(ord_key)); + price_level.on_order_remove(OrderKey(ord_key)); } REQUIRE(price_level.n_orders() == 90); REQUIRE(price_level.quantity().value() == 4095); @@ -94,7 +94,7 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { REQUIRE(price_level.n_orders() == 100); REQUIRE(price_level.quantity().value() == 5050); price_level.on_new_opp_order( - MDP3OrderKey(100001), MDP3Quantity(5100), false); + OrderKey(100001), Quantity(5100), false); REQUIRE(price_level.n_orders() == 0); REQUIRE(price_level.quantity().value() == 0); } @@ -103,7 +103,7 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { create_book(100); // take out the first 20 completely price_level.on_new_opp_order( - MDP3OrderKey(100001), MDP3Quantity(210), false); + OrderKey(100001), Quantity(210), false); REQUIRE(price_level.n_orders() == 80); REQUIRE(price_level.quantity().value() == 4840); price_level.copy_values_to(out_ords); @@ -113,7 +113,7 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { create_book(100); // take out the firdt 20 completely price_level.on_new_opp_order( - MDP3OrderKey(100001), MDP3Quantity(193), false); + OrderKey(100001), Quantity(193), false); REQUIRE(price_level.n_orders() == 81); REQUIRE(price_level.quantity().value() == 4857); } @@ -160,7 +160,7 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { // iceberg, show qty=2, total_qty=100 o = create_order( k++, sec_key, api::Side::SIDE_BUY, 0, price, 2, - IcebergQuantity{MDP3Quantity(2), MDP3Quantity(100)}); + IcebergQuantity{Quantity(2), Quantity(100)}); price_level.on_new_same_side_order(o); // non ib, to get the visible qty to 15 o = create_order(k++, sec_key, api::Side::SIDE_BUY, 0, price, 7); @@ -170,7 +170,7 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { // cross with a 10 lot, this should result in // {id=4,qty=5},{id=3,qty=2,total_qty=98} price_level.on_new_opp_order( - MDP3OrderKey(100001), MDP3Quantity(10), false); + OrderKey(100001), Quantity(10), false); auto [n_ords, vis_qty] = price_level.n_orders_qty(true); REQUIRE(n_ords == 2); REQUIRE(vis_qty == 7); @@ -178,20 +178,20 @@ TEST_CASE("fifo_matching_engine_single_level", "[matcher]") { REQUIRE(total_qty.value() == 103); // another 5 lot should only leave the IB {id=3,qty=2,total_qty=98} price_level.on_new_opp_order( - MDP3OrderKey(100001), MDP3Quantity(5), false); + OrderKey(100001), Quantity(5), false); REQUIRE(price_level.n_orders() == 1); REQUIRE(price_level.quantity().value() == 2); REQUIRE(price_level.total_quantity().value() == 98); // cross the remaining 98 IB price_level.on_new_opp_order( - MDP3OrderKey(100001), MDP3Quantity(49), false); + OrderKey(100001), Quantity(49), false); REQUIRE(price_level.n_orders() == 1); REQUIRE(price_level.quantity().value() == 1); REQUIRE(price_level.total_quantity().value() == 49); // 1 lots for (auto i = 0; i < 49; i++) price_level.on_new_opp_order( - MDP3OrderKey(100001), MDP3Quantity(1), false); + OrderKey(100001), Quantity(1), false); REQUIRE(price_level.n_orders() == 0); REQUIRE(price_level.quantity().value() == 0); REQUIRE(price_level.total_quantity().value() == 0); @@ -207,7 +207,7 @@ TEST_CASE("fifo_matching_engine_book", "[matcher]") { REQUIRE(bl.n_orders == n_orders); }; auto sec_key = 10; - FifoSecurityMatcher sec_me(MDP3SecurityID(100)); + FifoSecurityMatcher sec_me(SecurityID(100)); auto order_key = 0; auto priority = 0; auto add_to_book = [&](uint32_t n_orders, api::Side side, double price, @@ -360,7 +360,7 @@ TEST_CASE("fifo_matching_engine_book", "[matcher]") { auto init_qty = 4095; auto remvd = 0; for (auto i = 0; i < 90; i++) { - auto id = MDP3OrderKey(i + b); + auto id = OrderKey(i + b); sec_me.on_order_change(OrderChange{ MDP3Order{}, create_empty_order(id.value()), OrderChange::removed}); @@ -506,7 +506,7 @@ TEST_CASE("fifo_matching_engine_book", "[matcher]") { // 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, - IcebergQuantity{MDP3Quantity(13), MDP3Quantity(12500)}); + IcebergQuantity{Quantity(13), Quantity(12500)}); sec_me.on_order_change( OrderChange{MDP3Order{}, cross_ib, OrderChange::added}); bid_bk = sec_me.book(api::Side::SIDE_BUY); @@ -522,9 +522,9 @@ TEST_CASE("perf", "[matcher]") { const size_t n_levels = 500; const double tick_size = 0.01; const double top_bid = 100.0; - const MDP3SecurityID sec_id = MDP3SecurityID(1); + const SecurityID sec_id = SecurityID(1); - auto fill_ord = [&](MDP3Order &ord, MDP3OrderKey key) { + auto fill_ord = [&](MDP3Order &ord, OrderKey key) { ord.key = key; ord.security = sec_id; ord.side = rnd_gen.random_side(); @@ -537,7 +537,7 @@ TEST_CASE("perf", "[matcher]") { else price = (top_bid + tick_size) + (p_lev * tick_size); ord.price = md::IntPrice_from_double<7>(price); - ord.quantity = MDP3Quantity(rnd_gen.random_int(5, 20)); + ord.quantity = Quantity(rnd_gen.random_int(5, 20)); }; auto add_n_orders = [&](std::vector &out_v, size_t n_orders, size_t start_k) { @@ -545,7 +545,7 @@ TEST_CASE("perf", "[matcher]") { for (size_t i = 0; i < n_orders; i++) { OrderChange ord_change; ord_change.change = OrderChange::ChangeType::added; - fill_ord(ord_change.order, MDP3OrderKey(start_k++)); + fill_ord(ord_change.order, OrderKey(start_k++)); out_v.push_back(ord_change); } }; @@ -555,7 +555,7 @@ TEST_CASE("perf", "[matcher]") { SECTION("add orders") { for (size_t i = 0; i < n_runs; i++) { FifoSecurityMatcher sec_m(FifoSecurityMatcher::FifoSecurityMatcherArgs{ - MDP3SecurityID(100), 0, false}); + SecurityID(100), 0, false}); std::vector aux; // takes 22 secs to add 100,000 orders straght up add_n_orders(aux, n_orders, 0); @@ -576,7 +576,7 @@ TEST_CASE("perf", "[matcher]") { SECTION("cxl_orders") { for (size_t i = 0; i < n_runs; i++) { FifoSecurityMatcher sec_m(FifoSecurityMatcher::FifoSecurityMatcherArgs{ - MDP3SecurityID(100), 0, false}); + SecurityID(100), 0, false}); std::vector aux; // takes 22 secs to add 100,000 orders straght up add_n_orders(aux, n_orders, 0); @@ -601,7 +601,7 @@ TEST_CASE("perf", "[matcher]") { SECTION("update_dec_orders") { for (size_t i = 0; i < n_runs; i++) { FifoSecurityMatcher sec_m(FifoSecurityMatcher::FifoSecurityMatcherArgs{ - MDP3SecurityID(100), 0, false}); + SecurityID(100), 0, false}); std::vector aux; // takes 22 secs to add 100,000 orders straght up add_n_orders(aux, n_orders, 0); @@ -609,7 +609,7 @@ TEST_CASE("perf", "[matcher]") { sec_m.on_order_change(oc); auto t0 = TimeUtil::GetCurrentTime(); for (auto &oc : aux) { - oc.order.quantity = MDP3Quantity(oc.order.quantity.value() - 1); + oc.order.quantity = Quantity(oc.order.quantity.value() - 1); oc.change = OrderChange::ChangeType::updated; sec_m.on_order_change(oc); } @@ -627,7 +627,7 @@ TEST_CASE("perf", "[matcher]") { SECTION("update_inc_orders") { for (size_t i = 0; i < n_runs; i++) { FifoSecurityMatcher sec_m(FifoSecurityMatcher::FifoSecurityMatcherArgs{ - MDP3SecurityID(100), 0, false}); + SecurityID(100), 0, false}); std::vector aux; // takes 22 secs to add 100,000 orders straght up add_n_orders(aux, n_orders, 0); @@ -635,7 +635,7 @@ TEST_CASE("perf", "[matcher]") { sec_m.on_order_change(oc); auto t0 = TimeUtil::GetCurrentTime(); for (auto &oc : aux) { - oc.order.quantity = MDP3Quantity(oc.order.quantity.value() + 1); + oc.order.quantity = Quantity(oc.order.quantity.value() + 1); oc.change = OrderChange::ChangeType::updated; sec_m.on_order_change(oc); } @@ -653,7 +653,7 @@ TEST_CASE("perf", "[matcher]") { SECTION("order_price_change_no_cross") { for (size_t i = 0; i < n_runs; i++) { FifoSecurityMatcher sec_m(FifoSecurityMatcher::FifoSecurityMatcherArgs{ - MDP3SecurityID(100), 0, false}); + SecurityID(100), 0, false}); std::vector aux; // takes 22 secs to add 100,000 orders straght up add_n_orders(aux, n_orders, 0); @@ -684,7 +684,7 @@ TEST_CASE("perf", "[matcher]") { SECTION("new_order_cross") { for (size_t i = 0; i < n_runs; i++) { FifoSecurityMatcher sec_m(FifoSecurityMatcher::FifoSecurityMatcherArgs{ - MDP3SecurityID(100), 0, false}); + SecurityID(100), 0, false}); std::vector aux; // takes 22 secs to add 100,000 orders straght ups add_n_orders(aux, n_orders, 0); @@ -697,17 +697,17 @@ TEST_CASE("perf", "[matcher]") { OrderChange ochange; ochange.change = OrderChange::ChangeType::added; ochange.order = MDP3Order{ - MDP3OrderKey(0), - MDP3SecurityID(100), + OrderKey(0), + SecurityID(100), api::Side::SIDE_BUY, MDP3OrderPriority(0), md::IntPrice_from_double<7>(10000), - MDP3Quantity(1), + Quantity(1), std::nullopt}; std::vector exec_rep; auto t0 = TimeUtil::GetCurrentTime(); for (size_t i = 0; i < buy_orders_to_send; i++) { - ochange.order.key = MDP3OrderKey(n_orders + i + 1); + ochange.order.key = OrderKey(n_orders + i + 1); sec_m.on_order_change(ochange, &exec_rep); bts_assert(exec_rep.size() == (i + 1) * 2); auto l_it = exec_rep.end() - 1; diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.cpp index 1297ca3d3..bcebaf4d6 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.cpp @@ -27,23 +27,23 @@ inline std::string _iceberg_file_path(const std::string &pcap) { return dir + R"(/)" + name + ".icebergs"; } -std::unordered_map +std::unordered_map find_icebergs(const std::string &pcap, bool force_regen) { std::string path = _iceberg_file_path(pcap); // goes without saying: read_op and write_op must // agree with one another, wrt the sequence of fields - std::unordered_map dest; + std::unordered_map dest; auto read_op = [&](std::istream &in) -> std::istream & { auto ok = file::read_from_bin(in); auto total_qty = file::read_from_bin(in); - std::vector> show_quantities; + std::vector> show_quantities; for (auto num_states = file::read_from_bin(in); num_states > 0; num_states--) { size_t event_id = file::read_from_bin(in); auto show_qty = file::read_from_bin(in); - show_quantities.emplace_back(event_id, MDP3Quantity(show_qty)); + show_quantities.emplace_back(event_id, Quantity(show_qty)); } - std::vector> fill_quantities; + std::vector> fill_quantities; for (auto num_fill_events = file::read_from_bin(in); num_fill_events > 0; num_fill_events--) { size_t event_id = file::read_from_bin(in); @@ -51,9 +51,9 @@ find_icebergs(const std::string &pcap, bool force_regen) { fill_quantities.emplace_back(event_id, fill_qty); } dest.emplace( - MDP3OrderKey(ok), + OrderKey(ok), IcebergInput( - MDP3Quantity(total_qty), show_quantities, fill_quantities)); + Quantity(total_qty), show_quantities, fill_quantities)); return in; }; if (force_regen || @@ -62,7 +62,7 @@ find_icebergs(const std::string &pcap, bool force_regen) { dest = IcebergFinder::find_all(pcap); auto write_op = [](std::ostream &out, - const std::pair &p) -> std::ostream & { + const std::pair &p) -> std::ostream & { file::write_to_bin(out, p.first.value()); file::write_to_bin(out, p.second.total_qty().value()); file::write_to_bin( diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.h index 26255bc0d..01433202c 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/iceberg_file_cache.h @@ -9,6 +9,6 @@ namespace bts::spartan::mdp3::iceberg_file_cache { // If the file doesn't exist, the pcap is swept for icebergs, // and the results are written to the file .icebergs, // for faster retrieval on subsequent runs with the specified pcap. -std::unordered_map +std::unordered_map find_icebergs(const std::string &pcap, bool force_regen = false); -} // namespace bts::spartan::mdp3::iceberg_file_cache \ No newline at end of file +} // namespace bts::spartan::mdp3::iceberg_file_cache diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.cpp b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.cpp index 04d31772e..bd4b2998a 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.cpp @@ -72,7 +72,7 @@ void _sync_orders( size_t event_id, const InstrumentSnapshot &s, Orders &orders, - const std::unordered_map &icebergs) { + const std::unordered_map &icebergs) { // for (auto ch : s.order_changes()) { switch (ch.change) { @@ -153,7 +153,7 @@ inline bool match_fills( const FillDepot &fd, std::vector snaps, std::ostream &out = std::cout) { - std::unordered_map> fill_map; + std::unordered_map> fill_map; fd.copy_to(fill_map); bool errors = false; for (const auto *s : snaps) { @@ -205,23 +205,23 @@ struct _SecurityData { std::string symbol() const { return snapshot == nullptr ? "N/A" : snapshot->symbol(); } - MDP3SecurityID security_id() const { - return snapshot == nullptr ? MDP3SecurityID(0) : snapshot->security_id(); + SecurityID security_id() const { + return snapshot == nullptr ? SecurityID(0) : snapshot->security_id(); } }; struct MatcherValidationObserver::PImpl { PImpl() {} PImpl( - std::unordered_map icebergs, + std::unordered_map icebergs, flat_map interesting_event_ranges) : icebergs(icebergs), interesting_event_ranges(interesting_event_ranges) {} - flat_map security_cache; - std::unordered_map icebergs; + flat_map security_cache; + std::unordered_map icebergs; flat_map interesting_event_ranges; - flat_map interesting_orders; + flat_map interesting_orders; // number of 'interesting events' observed so far. uint32_t interesting_event_count = 0; @@ -304,11 +304,11 @@ struct MatcherValidationObserver::PImpl { // constructors /////////////////////// MatcherValidationObserver::MatcherValidationObserver( - std::unordered_map icebergs) + std::unordered_map icebergs) : MatcherValidationObserver(icebergs, flat_map{}) {} MatcherValidationObserver::MatcherValidationObserver( - std::unordered_map icebergs, + std::unordered_map icebergs, flat_map interesting_event_ranges) : _me(new MatcherValidationObserver::PImpl( icebergs, interesting_event_ranges)) {} @@ -426,7 +426,7 @@ void MatcherValidationObserver::on_real_time_event(MDP3Event const &ev) { // changes are processed to ensure the correct implied markets are used. // Fills are also indexed in this pass, so they can be added to the iceberg // qty - std::unordered_map fill_map; + std::unordered_map fill_map; for (const auto *s : sorted_secs) { accumulate_fills(s->fills().begin(), s->fills().end(), fill_map); _me->exch_matcher.add_security( diff --git a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.h b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.h index e1d38c8e2..e931c054f 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.h +++ b/src/server/sparkd/cmds/spartan/back_testing/matcher/validation/matcher_validation_observer.h @@ -12,13 +12,13 @@ namespace bts::spartan::mdp3 { struct MatcherValidationObserver : IChannelObserver { MatcherValidationObserver( - std::unordered_map icebergs); + std::unordered_map icebergs); // interesting_event_ranges: // - keys indicate the first event in an interesting range // - values indicate the number of events in the range (i.e., the range's // length). MatcherValidationObserver( - std::unordered_map icebergs, + std::unordered_map icebergs, boost::container::flat_map interesting_event_ranges); ~MatcherValidationObserver(); void on_recovery_complete(InitialSnapshot const &snap) override; diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/ISim.h b/src/server/sparkd/cmds/spartan/back_testing/sim/ISim.h index 13e39f4c1..b69733df1 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/ISim.h +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/ISim.h @@ -13,11 +13,11 @@ class ISim { // Queries virtual PolygonMap const &polygons() const = 0; virtual InstrumentMap const &instruments() const = 0; - virtual InstrumentDefinition const &get_sec(MDP3SecurityID id) const = 0; + virtual InstrumentDefinition const &get_sec(SecurityID id) const = 0; virtual TimeStamp time() const = 0; // Actions - virtual MDP3OrderKey send(SmallOrderChange const &, size_t delay_ns = 0) = 0; + virtual OrderKey send(SmallOrderChange const &, size_t delay_ns = 0) = 0; virtual void start_simulation() = 0; virtual void stop_simulation() = 0; virtual void log_pandl() const = 0; diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.cpp b/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.cpp index 1a34b7c3c..ae7ec6696 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.cpp @@ -43,14 +43,14 @@ struct Sim::Simulation { // which could lead to key colision if we used the cme key. For // this reason we must remap the CME keys to ones we know will be // unique during the entire simulation. - std::unordered_map cme_key_map; + std::unordered_map cme_key_map; // The matcher does not currently support non-trading security // states. For this reason we have to use this map to detect // changes of trading state in securities so that when a security // starts trading we can seed the matcher with existing orders and // when it stops trading we can remove its orders - std::unordered_set ready_secs; + std::unordered_set ready_secs; }; struct Sim::AlgoCBFilter : IAlgoModel { @@ -90,14 +90,14 @@ struct Sim::PImpl { PolygonMap const &polygons; PCapEventGenerator &event_generator; SimLogger logger; - std::unordered_map snapshots = {}; + std::unordered_map snapshots = {}; State state = State::REPLAY; TimeStamp transact_time = TimeStamp{0}; TimeStamp time = TimeStamp{0}; AlgoEventID event_id = {0, 0}; std::optional simulation = {}; - MDP3OrderKey last_order_key = - MDP3OrderKey{std::numeric_limits::max()}; + OrderKey last_order_key = + OrderKey{std::numeric_limits::max()}; std::vector my_fills = {}; PendingSimOP pending_sim_op = PendingSimOP::NONE; TimeStamp next_time_event = TimeStamp{0}; @@ -494,7 +494,7 @@ void Sim::match_and_send_effects( } void Sim::bootstrap_simulated_order_book( - TimeStamp transact_time, MDP3SecurityID sid) { + TimeStamp transact_time, SecurityID sid) { bts_assert(me->state == State::SIM); bts_assert(me->simulation); auto &simulation = *me->simulation; @@ -509,7 +509,7 @@ void Sim::bootstrap_simulated_order_book( } void Sim::clear_simulated_order_book( - TimeStamp transact_time, MDP3SecurityID sid) { + TimeStamp transact_time, SecurityID sid) { bts_assert(me->state == State::SIM); bts_assert(me->simulation); auto &simulation = *me->simulation; @@ -530,26 +530,26 @@ Sim::correct_pcap_order(OrderChange const &o, bool set_exact_ib_state) { auto &key_map = me->simulation->cme_key_map; bts_assert(o.order.key.value()); - MDP3OrderKey &our_key = key_map[o.order.key]; + OrderKey &our_key = key_map[o.order.key]; SmallOrderChange result(o); result.original_key = o.order.key; switch (o.change) { case OrderChange::added: { - our_key = MDP3OrderKey{me->next_mapped_key++}; + our_key = OrderKey{me->next_mapped_key++}; result.order.key = our_key; break; } case OrderChange::removed: { - bts_assert(our_key != MDP3OrderKey{}); + bts_assert(our_key != OrderKey{}); result.order.key = our_key; - our_key = MDP3OrderKey{}; + our_key = OrderKey{}; break; } case OrderChange::updated: case OrderChange::updated_price: { - bts_assert(our_key != MDP3OrderKey{}); + bts_assert(our_key != OrderKey{}); result.order.key = our_key; } } @@ -570,7 +570,7 @@ PolygonMap const &Sim::polygons() const { return me->polygons; } InstrumentMap const &Sim::instruments() const { return me->instruments; } -InstrumentDefinition const &Sim::get_sec(MDP3SecurityID id) const { +InstrumentDefinition const &Sim::get_sec(SecurityID id) const { auto it = me->instruments.find(id); bts_assert(it != me->instruments.end()); return *it->second; @@ -579,7 +579,7 @@ InstrumentDefinition const &Sim::get_sec(MDP3SecurityID id) const { TimeStamp Sim::time() const { return me->time; } double -Sim::price_at_market(MDP3SecurityID id, MDP3Quantity qty, api::Side s) const { +Sim::price_at_market(SecurityID id, Quantity qty, api::Side s) const { auto it = me->snapshots.find(id); bts_assert(it != me->snapshots.end()); @@ -605,7 +605,7 @@ Sim::price_at_market(MDP3SecurityID id, MDP3Quantity qty, api::Side s) const { } PandLSummary Sim::pnl() const { - auto mkt_pricer = [this](MDP3SecurityID id, MDP3Quantity qty, api::Side s) { + auto mkt_pricer = [this](SecurityID id, Quantity qty, api::Side s) { return price_at_market(id, qty, s); }; @@ -623,7 +623,7 @@ void Sim::log_pandl() const { log("pnl", pnl_summary.cash, pnl_summary.commission, pnl_summary.position); } -MDP3OrderKey +OrderKey Sim::send(SmallOrderChange const &change, size_t propagation_delay) { if (me->state == State::REPLAY) @@ -635,11 +635,11 @@ Sim::send(SmallOrderChange const &change, size_t propagation_delay) { if (change.change == OrderChange::added) { auto cpy = change; - cpy.order.key = MDP3OrderKey{me->last_order_key.value()--}; + cpy.order.key = OrderKey{me->last_order_key.value()--}; me->pending_algo_actions.push(AlgoAction{transact_time, cpy}); return cpy.order.key; } else { - bts_assert(change.order.key != MDP3OrderKey{}); + bts_assert(change.order.key != OrderKey{}); me->pending_algo_actions.push(AlgoAction{transact_time, change}); return change.order.key; } diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.h b/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.h index de67c4653..088b82891 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.h +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/Sim.h @@ -37,10 +37,10 @@ class Sim : ISim { // From ISim PolygonMap const &polygons() const override; InstrumentMap const &instruments() const override; - InstrumentDefinition const &get_sec(MDP3SecurityID id) const override; + InstrumentDefinition const &get_sec(SecurityID id) const override; TimeStamp time() const override; void log_pandl() const override; - MDP3OrderKey + OrderKey send(SmallOrderChange const &, size_t propagation_delay) override; void start_simulation() override; @@ -51,7 +51,7 @@ class Sim : ISim { // End ISim PandLSummary pnl() const; - double price_at_market(MDP3SecurityID, MDP3Quantity, api::Side) const; + double price_at_market(SecurityID, Quantity, api::Side) const; void next_event(); void on_pcap_event_during_replay(); @@ -60,8 +60,8 @@ class Sim : ISim { void on_time(); bool time_event_due_before(TimeStamp) const; void - bootstrap_simulated_order_book(TimeStamp transact_time, MDP3SecurityID); - void clear_simulated_order_book(TimeStamp transact_time, MDP3SecurityID); + bootstrap_simulated_order_book(TimeStamp transact_time, SecurityID); + void clear_simulated_order_book(TimeStamp transact_time, SecurityID); void match_and_send_effects( TimeStamp transact_time, SmallOrderChangeVec const &); SmallOrderChange correct_pcap_order( diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.cpp b/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.cpp index 1d4f392a7..a75e6ecc0 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.cpp @@ -83,17 +83,17 @@ double PandL::position_liquidation_value( mkt_action = api::SIDE_SELL; else mkt_action = api::SIDE_BUY; - auto cash_flow = me->pricer(id, MDP3Quantity{(int)this_pos}, mkt_action); + auto cash_flow = me->pricer(id, Quantity{(int)this_pos}, mkt_action); liquidation_proceeds += cash_flow; } return liquidation_proceeds; } -InstrumentDefinition const &PandL::get_sec(MDP3SecurityID id) const { +InstrumentDefinition const &PandL::get_sec(SecurityID id) const { return mdp3::get_sec(id, me->instruments); } -double PandL::price_to_cash(MDP3SecurityID id, double p) const { +double PandL::price_to_cash(SecurityID id, double p) const { return get_sec(id).to_cash(p); } diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.h b/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.h index 766e7f92e..87faff3cb 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.h +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/pandl/PandL.h @@ -17,7 +17,7 @@ namespace bts::spartan::mdp3 { class PandL { public: using SymbolNetCash = std::unordered_map; - using OutrightPosition = std::unordered_map; + using OutrightPosition = std::unordered_map; PandL( InstrumentMap const &, @@ -33,8 +33,8 @@ class PandL { private: struct PImpl; - InstrumentDefinition const &get_sec(MDP3SecurityID id) const; - double price_to_cash(MDP3SecurityID id, double p) const; + InstrumentDefinition const &get_sec(SecurityID id) const; + double price_to_cash(SecurityID id, double p) const; int mkt_to_cash_flow(api::Side s) const; int mkt_to_contract_flow(api::Side s) const; std::unique_ptr me; diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/sim_common.h b/src/server/sparkd/cmds/spartan/back_testing/sim/sim_common.h index 0579ca2a5..86e8fe22b 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/sim_common.h +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/sim_common.h @@ -20,7 +20,7 @@ struct AlgoAction { }; struct MBPUpdate { - MDP3SecurityID security_id; + SecurityID security_id; Book mbp_buy; Book mbp_sell; ImpliedBook implied_mbp_buy; @@ -40,12 +40,12 @@ struct MBPUpdate { }; struct OrderUpdate { - MDP3OrderKey key; + OrderKey key; enum Status { FILLED, PARTIALLY_FILLED, CANCELED }; Status status; - MDP3SecurityID security_id; + SecurityID security_id; api::Side side; - MDP3Quantity last_fills; + Quantity last_fills; md::IntPrice last_price; enum FillType { PASSIVE, AGGRESSIVE }; // non null when Status == FILLED or PARTIALLY_FILLED diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/AlgoServicesBridge.cpp b/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/AlgoServicesBridge.cpp index 62b6217c6..a36509694 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/AlgoServicesBridge.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/AlgoServicesBridge.cpp @@ -27,8 +27,8 @@ // BeforeLaunchBridge& bl_bridge; // IAlgoOrder& algo_order; // ISimServices& sim_services; -// std::unordered_map book_map; -// std::unordered_map order_map; +// std::unordered_map book_map; +// std::unordered_map order_map; // OrderDefinition order_def; // uint32_t running_ok = 0; @@ -189,7 +189,7 @@ // ord_def.side(), // MDP3OrderPriority{}, // md::IntPrice_from_double<7>(p.value()), -// MDP3Quantity(q.value()), +// Quantity(q.value()), // std::nullopt // }, // ChildState{ @@ -213,7 +213,7 @@ // auto it = me->order_map.find(sp_ord_key); // if(it != me->order_map.end()){ // OrderState& ord_state = it->second; -// ord_state.order.quantity = MDP3Quantity(u.quantity()); +// ord_state.order.quantity = Quantity(u.quantity()); // ord_state.order.price = md::IntPrice_from_double<7>(u.price()); // ord_state.child_state.price = Price(u.price()); // ord_state.child_state.quantity = Quantity(u.quantity()); diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BeforeLaunchBridge.cpp b/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BeforeLaunchBridge.cpp index 71992a805..c745229ee 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BeforeLaunchBridge.cpp +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BeforeLaunchBridge.cpp @@ -16,7 +16,7 @@ // struct BeforeLaunchBridge::PImpl { // OrderKey ok; -// MDP3SecurityID sec_id; +// SecurityID sec_id; // ISimServices& sim_services; // const api::orderman::OrderDefinition& order_def; // ChildTemplate* child_temp = nullptr; @@ -29,7 +29,7 @@ // PImpl( // OrderKey ok, -// MDP3SecurityID sec_id, +// SecurityID sec_id, // ISimServices& sim_services, // const api::orderman::OrderDefinition& order_def) // : @@ -49,7 +49,7 @@ // ISimServices& sim_services, // const api::orderman::OrderDefinition& order_def) // : -// me(new PImpl(OrderKey(0),MDP3SecurityID(0),sim_services,order_def)){ +// me(new PImpl(OrderKey(0),SecurityID(0),sim_services,order_def)){ // for (const auto& p : me->sim_services.instruments()){ // auto mdp3_sec_ptr = p.second; // api::Security sec = convert_to_spark_security( diff --git a/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BridgeCommon.h b/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BridgeCommon.h index 840f48666..ecfe339f6 100644 --- a/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BridgeCommon.h +++ b/src/server/sparkd/cmds/spartan/back_testing/sim/spark_bridge/BridgeCommon.h @@ -14,24 +14,24 @@ // namespace bts{ // namespace orderman{ -// inline OrderKey map_ord_key(bts::spartan::mdp3::MDP3OrderKey k){ +// inline OrderKey map_ord_key(bts::spartan::mdp3::OrderKey k){ // // uint64_t -> uint32_t // return OrderKey(static_cast(k.value())); // } -// inline bts::spartan::mdp3::MDP3OrderKey map_ord_key(OrderKey k){ +// inline bts::spartan::mdp3::OrderKey map_ord_key(OrderKey k){ // // uint32_t -> uint64_t -// return bts::spartan::mdp3::MDP3OrderKey(static_cast(k.value())); +// return bts::spartan::mdp3::OrderKey(static_cast(k.value())); // } -// inline SecurityKey map_sec_key(bts::spartan::mdp3::MDP3SecurityID k){ +// inline SecurityKey map_sec_key(bts::spartan::mdp3::SecurityID k){ // // int -> uint32_t // return SecurityKey(static_cast(k.value())); // } -// inline bts::spartan::mdp3::MDP3SecurityID map_sec_key(SecurityKey k){ +// inline bts::spartan::mdp3::SecurityID map_sec_key(SecurityKey k){ // // uint32_t -> int -// return bts::spartan::mdp3::MDP3SecurityID(static_cast(k.value())); +// return bts::spartan::mdp3::SecurityID(static_cast(k.value())); // } // inline void translate_book(const bts::spartan::mdp3::MBPUpdate& u_in, diff --git a/src/server/sparkd/cmds/spartan/common/OrderKey.cpp b/src/server/sparkd/cmds/spartan/common/OrderKey.cpp new file mode 100644 index 000000000..06b9cb790 --- /dev/null +++ b/src/server/sparkd/cmds/spartan/common/OrderKey.cpp @@ -0,0 +1 @@ +#include "OrderKey.h" diff --git a/src/server/sparkd/cmds/spartan/common/OrderKey.h b/src/server/sparkd/cmds/spartan/common/OrderKey.h new file mode 100644 index 000000000..13e828dd0 --- /dev/null +++ b/src/server/sparkd/cmds/spartan/common/OrderKey.h @@ -0,0 +1,10 @@ +#pragma once + +#include "lib/utils/ValueWrapper.h" +#include + +namespace bts::spartan::mdp3 { + +using OrderKey = utils::ValueWrapper; + +} diff --git a/src/server/sparkd/cmds/spartan/common/SecurityID.cpp b/src/server/sparkd/cmds/spartan/common/SecurityID.cpp new file mode 100644 index 000000000..a542c2098 --- /dev/null +++ b/src/server/sparkd/cmds/spartan/common/SecurityID.cpp @@ -0,0 +1 @@ +#include "SecurityID.h" diff --git a/src/server/sparkd/cmds/spartan/common/SecurityID.h b/src/server/sparkd/cmds/spartan/common/SecurityID.h new file mode 100644 index 000000000..69d6df31a --- /dev/null +++ b/src/server/sparkd/cmds/spartan/common/SecurityID.h @@ -0,0 +1,13 @@ +#pragma once + +#pragma once + +#include "lib/utils/ValueWrapper.h" +#include + +namespace bts::spartan::mdp3 { + +using SecurityID = + utils::ValueWrapper; + +} diff --git a/src/server/sparkd/cmds/spartan/common/TimeInterval.cpp b/src/server/sparkd/cmds/spartan/common/TimeInterval.cpp new file mode 100644 index 000000000..d94273f73 --- /dev/null +++ b/src/server/sparkd/cmds/spartan/common/TimeInterval.cpp @@ -0,0 +1 @@ +#include "TimeInterval.h" diff --git a/src/server/sparkd/cmds/spartan/common/TimeInterval.h b/src/server/sparkd/cmds/spartan/common/TimeInterval.h index d5d1d8771..eeb17f28d 100644 --- a/src/server/sparkd/cmds/spartan/common/TimeInterval.h +++ b/src/server/sparkd/cmds/spartan/common/TimeInterval.h @@ -1,5 +1,7 @@ #pragma once +#include + namespace bts::spartan::mdp3 { class TimeInterval { @@ -23,9 +25,9 @@ public: TimeInterval(const TimeInterval &) = default; TimeInterval& operator=(const TimeInterval &) = default; - int64_t nanoseconds() const {return _ns;} - int64_t microseconds() const {return _ns/1000;} - int64_t miliseconds() const {return _ns/1000/1000;} + int64_t nanos() const {return _ns;} + int64_t micros() const {return _ns/1000;} + int64_t millis() const {return _ns/1000/1000;} int64_t seconds() const {return _ns/1000/1000/1000;} private: diff --git a/src/server/sparkd/cmds/spartan/common/TimeStamp.h b/src/server/sparkd/cmds/spartan/common/TimeStamp.h index 1342bf4c4..4c53fcbf9 100644 --- a/src/server/sparkd/cmds/spartan/common/TimeStamp.h +++ b/src/server/sparkd/cmds/spartan/common/TimeStamp.h @@ -46,7 +46,7 @@ public: } void shift(TimeInterval i) { - _v += i.nanoseconds(); + _v += i.nanos(); } std::string to_time_string() const ; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.cpp index a686aa766..56f859bd0 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.cpp @@ -61,7 +61,7 @@ struct InstrumentDefinition::PImpl { std::string symbol; std::string security_group; std::string asset; - MDP3SecurityID security_id; + SecurityID security_id; std::string match_algorithm; md::IntPrice min_price_increment; double min_price_increment_ammount = 0; @@ -108,10 +108,10 @@ InstrumentDefinition::InstrumentDefinition( spread.noLotTypeRules().forEach([](auto const &) {}); spread.noLegs().forEach([this](auto const &l) { LegDef ll{ - MDP3SecurityID{l.legSecurityID()}, + SecurityID{l.legSecurityID()}, l.legSide() == ::mdp3::LegSide::BuySide ? api::SIDE_BUY : api::SIDE_SELL, - MDP3Quantity{l.legRatioQty()}}; + Quantity{l.legRatioQty()}}; me->legs.push_back(ll); }); } @@ -147,7 +147,7 @@ InstrumentDefinition::operator=(InstrumentDefinition const &other) { InstrumentDefinition::~InstrumentDefinition() {} -MDP3SecurityID InstrumentDefinition::security_id() const { +SecurityID InstrumentDefinition::security_id() const { return me->security_id; } diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h index b3ee8ed39..88767cb53 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentDefinition.h @@ -11,9 +11,9 @@ namespace bts::spartan::mdp3 { struct LegDef { - MDP3SecurityID security_id; + SecurityID security_id; api::Side side; - MDP3Quantity ratio; + Quantity ratio; }; class InstrumentDefinition { @@ -29,7 +29,7 @@ class InstrumentDefinition { InstrumentDefinition &operator=(InstrumentDefinition &&other); InstrumentDefinition &operator=(InstrumentDefinition const &other); - MDP3SecurityID security_id() const; + SecurityID security_id() const; std::string const &symbol() const; std::string const &security_group() const; std::string const &asset() const; @@ -60,6 +60,6 @@ class InstrumentDefinition { using MaybeInstrumentDefinition = std::optional; using InstrumentDefinitions = - std::unordered_map; + std::unordered_map; } // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentMap.h b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentMap.h index 3831ca138..d7e540766 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentMap.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentMap.h @@ -6,10 +6,10 @@ namespace bts::spartan::mdp3 { class InstrumentDefinition; using InstrumentMap = - std::unordered_map; + std::unordered_map; inline InstrumentDefinition const & -get_sec(MDP3SecurityID id, InstrumentMap const &m) { +get_sec(SecurityID id, InstrumentMap const &m) { auto it = m.find(id); bts_assert(it != m.end()); return *it->second; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.cpp index 60362c8fb..64e1378e4 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.cpp @@ -16,7 +16,7 @@ struct InstrumentSnapshot::PImpl { implied_matching_status(false) {} // Books - MDP3SecurityID security_id; + SecurityID security_id; std::array books; std::array implied_books; // Orders @@ -33,10 +33,10 @@ struct InstrumentSnapshot::PImpl { md::IntPrice high_limit_price; md::IntPrice low_limit_price; md::IntPrice max_price_variation; - MDP3Quantity cleared_volume; - MDP3Quantity electronic_volume; + Quantity cleared_volume; + Quantity electronic_volume; md::IntPrice fixing_price; - MDP3Quantity open_interest; + Quantity open_interest; md::IntPrice open_price; md::IntPrice high_bid; md::IntPrice low_offer; @@ -67,7 +67,7 @@ InstrumentSnapshot::InstrumentSnapshot(InstrumentDefinition &&def) InstrumentSnapshot::~InstrumentSnapshot() {} -MDP3SecurityID InstrumentSnapshot::security_id() const { +SecurityID InstrumentSnapshot::security_id() const { return me->security_id; } @@ -126,17 +126,17 @@ void InstrumentSnapshot::set_max_price_variation(md::IntPrice v) { me->max_price_variation = v; } -MDP3Quantity InstrumentSnapshot::cleared_volume() const { +Quantity InstrumentSnapshot::cleared_volume() const { return me->cleared_volume; } -void InstrumentSnapshot::set_cleared_volume(MDP3Quantity v) { +void InstrumentSnapshot::set_cleared_volume(Quantity v) { me->cleared_volume = v; } -MDP3Quantity InstrumentSnapshot::electronic_volume() const { +Quantity InstrumentSnapshot::electronic_volume() const { return me->electronic_volume; } -void InstrumentSnapshot::set_electronic_volume(MDP3Quantity v) { +void InstrumentSnapshot::set_electronic_volume(Quantity v) { me->electronic_volume = v; } @@ -147,10 +147,10 @@ void InstrumentSnapshot::set_fixing_price(md::IntPrice v) { me->fixing_price = v; } -MDP3Quantity InstrumentSnapshot::open_interest() const { +Quantity InstrumentSnapshot::open_interest() const { return me->open_interest; } -void InstrumentSnapshot::set_open_interest(MDP3Quantity v) { +void InstrumentSnapshot::set_open_interest(Quantity v) { me->open_interest = v; } @@ -348,11 +348,11 @@ void InstrumentSnapshot::update_order(MDP3Order const &order) { me->order_changes.emplace_back(change); } -void InstrumentSnapshot::remove_order(MDP3OrderKey id) { +void InstrumentSnapshot::remove_order(OrderKey id) { auto it = me->orders.find(id); bts_assert(it != me->orders.end()); auto removed = it->second; - removed.quantity = MDP3Quantity{0}; + removed.quantity = Quantity{0}; me->order_changes.emplace_back( OrderChange{it->second, removed, OrderChange::removed}); me->orders.erase(it); @@ -410,7 +410,7 @@ void InstrumentSnapshot::update_fill(MDP3Fill const &f) { } } -void InstrumentSnapshot::remove_fill(MDP3TradeEntryID tid, MDP3OrderKey oid) { +void InstrumentSnapshot::remove_fill(MDP3TradeEntryID tid, OrderKey oid) { auto it = std::find_if( me->fills.begin(), me->fills.end(), [tid, oid](auto const &f) { return f.key == oid && f.trade_entry_id == tid; @@ -446,14 +446,14 @@ OrderChanges InstrumentSnapshot::deduced_order_changes() const { return rv; } else { struct AggOrderRec { - MDP3OrderKey ok; + OrderKey ok; Fills fills; }; std::vector agg_orders; OrderChanges deduced_orders; // Return the AggOrderRec for a given order - auto get_agg_order = [&agg_orders](MDP3OrderKey ok) -> AggOrderRec & { + auto get_agg_order = [&agg_orders](OrderKey ok) -> AggOrderRec & { for (auto &agg_rec : agg_orders) if (agg_rec.ok == ok) return agg_rec; @@ -499,7 +499,7 @@ OrderChanges InstrumentSnapshot::deduced_order_changes() const { : api::SIDE_SELL; deduced_order.order.priority = {}; deduced_order.order.price = aggressor_fills[0].price; - deduced_order.order.quantity = MDP3Quantity{0}; + deduced_order.order.quantity = Quantity{0}; for (auto &f : aggressor_fills) { if (securities::is_worse( diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h index 375222f44..0e74edc2d 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/InstrumentSnapshot.h @@ -38,7 +38,7 @@ class InstrumentSnapshot { ~InstrumentSnapshot(); // Queries ------------------------------------------------------------ - MDP3SecurityID security_id() const; + SecurityID security_id() const; InstrumentDefinition const &definition() const; std::string const &symbol() const { return definition().symbol(); } ::mdp3::SecurityTradingStatus::Value trading_status() const; @@ -54,10 +54,10 @@ class InstrumentSnapshot { md::IntPrice high_limit_price() const; md::IntPrice low_limit_price() const; md::IntPrice max_price_variation() const; - MDP3Quantity electronic_volume() const; - MDP3Quantity cleared_volume() const; + Quantity electronic_volume() const; + Quantity cleared_volume() const; md::IntPrice fixing_price() const; - MDP3Quantity open_interest() const; + Quantity open_interest() const; md::IntPrice open_price() const; md::IntPrice high_bid() const; md::IntPrice low_offer() const; @@ -81,21 +81,21 @@ class InstrumentSnapshot { void clear_order_changes(); void insert_order(MDP3Order const &); void update_order(MDP3Order const &); - void remove_order(MDP3OrderKey); + void remove_order(OrderKey); Book build_book_from_orders(api::Side) const; void set_books_from_orders(); void reset_books(); void add_fill(MDP3Fill const &); void update_fill(MDP3Fill const &); - void remove_fill(MDP3TradeEntryID, MDP3OrderKey); + void remove_fill(MDP3TradeEntryID, OrderKey); void clear_fills(); void set_high_limit_price(md::IntPrice); void set_low_limit_price(md::IntPrice); void set_max_price_variation(md::IntPrice); - void set_cleared_volume(MDP3Quantity); - void set_electronic_volume(MDP3Quantity); + void set_cleared_volume(Quantity); + void set_electronic_volume(Quantity); void set_fixing_price(md::IntPrice); - void set_open_interest(MDP3Quantity); + void set_open_interest(Quantity); void set_open_price(md::IntPrice); void set_high_bid(md::IntPrice); void set_low_offer(md::IntPrice); @@ -115,7 +115,7 @@ class InstrumentSnapshot { }; using SnapshotMap = - std::unordered_map; + std::unordered_map; std::ostream &operator<<(std::ostream &, InstrumentSnapshot const &); } // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.cpp index f0f6e038e..01040df25 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.cpp @@ -10,19 +10,19 @@ bool is_better_or_equal(api::Side s, md::IntPrice p1, md::IntPrice p2) { return p1 <= p2; } -MDP3Quantity depth_at_price(api::Side s, Book const &book, md::IntPrice p) { +Quantity depth_at_price(api::Side s, Book const &book, md::IntPrice p) { int qty = 0; for (auto const &level : book) if (is_better_or_equal(s, level.price, p)) qty += level.quantity.value(); - return MDP3Quantity{qty}; + return Quantity{qty}; } -MDP3Quantity depth(Book const &book) { +Quantity depth(Book const &book) { int qty = 0; for (auto const &level : book) qty += level.quantity.value(); - return MDP3Quantity{qty}; + return Quantity{qty}; } void merge_books(api::Side s, Book const &b, ImpliedBook const &ib, Book *out) { diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h b/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h index aca02020c..c012c8d95 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_common.h @@ -6,6 +6,8 @@ #include "lib/utils/ValueWrapper.h" #include "lib/utils/overloaded.h" #include "server/sparkd/cmds/spartan/common/TimeStamp.h" +#include "server/sparkd/cmds/spartan/common/OrderKey.h" +#include "server/sparkd/cmds/spartan/common/SecurityID.h" #include #include @@ -13,10 +15,6 @@ namespace bts::spartan::mdp3 { -using MDP3OrderKey = utils::ValueWrapper; -using MDP3SecurityID = - utils::ValueWrapper; - class InstrumentSnapshot; using InstrumentSnapshotPtr = std::unique_ptr; @@ -55,9 +53,9 @@ inline std::ostream &operator<<(std::ostream &s, MDP3Event const &ev) { return s; } -using MDP3Quantity = utils::ValueWrapper; +using Quantity = utils::ValueWrapper; -using Pricer = std::function; +using Pricer = std::function; using MDP3OrderPriority = utils::ValueWrapper; @@ -65,7 +63,7 @@ using MDP3OrderPriority = class BookLevel { public: md::IntPrice price; - MDP3Quantity quantity = MDP3Quantity{0}; + Quantity quantity = Quantity{0}; int32_t n_orders = 0; bool operator==(BookLevel const &other) const { return price == other.price && @@ -82,11 +80,11 @@ inline std::ostream &operator<<(std::ostream &s, BookLevel const &l) { struct SmallBookLevel { SmallBookLevel() : price(md::INT_NAN), quantity(0) {} - SmallBookLevel(md::IntPrice price, MDP3Quantity quantity) + SmallBookLevel(md::IntPrice price, Quantity quantity) : price(price), quantity(quantity) {} md::IntPrice price; - MDP3Quantity quantity; + Quantity quantity; }; inline bool operator==(const SmallBookLevel &lhs, const SmallBookLevel &rhs) { @@ -103,8 +101,8 @@ inline std::ostream &operator<<(std::ostream &out, const SmallBookLevel &sbl) { } struct IcebergQuantity { - MDP3Quantity show; - MDP3Quantity total; + Quantity show; + Quantity total; }; inline std::ostream &operator<<(std::ostream &out, const IcebergQuantity &ibq) { @@ -125,14 +123,14 @@ struct MDP3Order { public: operator bool() const noexcept { return !empty(); } - bool empty() const noexcept { return key != MDP3OrderKey{0}; } + bool empty() const noexcept { return key != OrderKey{0}; } - MDP3OrderKey key = MDP3OrderKey{0}; - MDP3SecurityID security = MDP3SecurityID{0}; + OrderKey key = OrderKey{0}; + SecurityID security = SecurityID{0}; api::Side side = api::SIDE_UNDEFINED; MDP3OrderPriority priority = MDP3OrderPriority{0}; md::IntPrice price; - MDP3Quantity quantity = MDP3Quantity{0}; + Quantity quantity = Quantity{0}; std::optional iceberg_quantity; }; @@ -160,7 +158,7 @@ struct SmallOrderChange { MDP3Order order; OrderChange::ChangeType change; bool affect_book = true; - MDP3OrderKey original_key = MDP3OrderKey{0}; + OrderKey original_key = OrderKey{0}; }; using SmallOrderChangeVec = boost::container::small_vector; @@ -225,15 +223,15 @@ inline std::ostream &operator<<(std::ostream &s, OrderChanges const &changes) { return s; } -using Orders = std::unordered_map; +using Orders = std::unordered_map; using MDP3TradeEntryID = utils::ValueWrapper; struct MDP3Fill { - MDP3OrderKey key; + OrderKey key; md::IntPrice price; - MDP3Quantity quantity; - MDP3Quantity summary_quantity; + Quantity quantity; + Quantity summary_quantity; MDP3TradeEntryID trade_entry_id; enum Aggressor { THIS_BUY, THIS_SELL, OTHER, IMPLIED } aggressor; }; @@ -320,8 +318,8 @@ inline std::ostream &operator<<(std::ostream &s, ImpliedBook const &b) { } void merge_books(api::Side, Book const &, ImpliedBook const &, Book *out); -MDP3Quantity depth_at_price(api::Side, Book const &, md::IntPrice); -MDP3Quantity depth(Book const &); +Quantity depth_at_price(api::Side, Book const &, md::IntPrice); +Quantity depth(Book const &); inline std::string to_str(std::string const &s) { return s; } diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_quantity_operators.h b/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_quantity_operators.h index 7e5ceddb1..618ee2d5c 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_quantity_operators.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/mdp3_quantity_operators.h @@ -4,28 +4,28 @@ namespace bts::spartan::mdp3 { #define MDP3QTY_BIN_OP(op, result) \ inline result operator op( \ - const MDP3Quantity &lhs, const MDP3Quantity &rhs) { \ + const Quantity &lhs, const Quantity &rhs) { \ return result(lhs.value() op rhs.value()); \ } -#define MDP3QTY_ARITH_VAL_OP(op) MDP3QTY_BIN_OP(op, MDP3Quantity) +#define MDP3QTY_ARITH_VAL_OP(op) MDP3QTY_BIN_OP(op, Quantity) #define MDP3QTY_ARITH_REF_OP(op) \ - inline MDP3Quantity &operator op( \ - MDP3Quantity &lhs, const MDP3Quantity &rhs) { \ + inline Quantity &operator op( \ + Quantity &lhs, const Quantity &rhs) { \ lhs.value() op rhs.value(); \ return lhs; \ } #define MDP3QTY_INT_OPS(op) \ - inline MDP3Quantity operator op(const MDP3Quantity &lhs, const int &rhs) { \ - return MDP3Quantity(lhs.value() op rhs); \ + inline Quantity operator op(const Quantity &lhs, const int &rhs) { \ + return Quantity(lhs.value() op rhs); \ } \ - inline MDP3Quantity operator op(const int &lhs, const MDP3Quantity &rhs) { \ - return MDP3Quantity(lhs op rhs.value()); \ + inline Quantity operator op(const int &lhs, const Quantity &rhs) { \ + return Quantity(lhs op rhs.value()); \ } #define MDP3QTY_INT_BIN_OP(op) \ - inline bool operator op(const MDP3Quantity &lhs, const int &rhs) { \ + inline bool operator op(const Quantity &lhs, const int &rhs) { \ return lhs.value() op rhs; \ } \ - inline bool operator op(const int &rhs, const MDP3Quantity &lhs) { \ + inline bool operator op(const int &rhs, const Quantity &lhs) { \ return rhs op lhs.value(); \ } #define ICEBERG_QTY_COMP_OP(op) \ @@ -34,7 +34,7 @@ namespace bts::spartan::mdp3 { return lhs.show op rhs.show && lhs.total op rhs.total; \ } /////////////////////// -// MDP3Quantity +// Quantity /////////////////////// MDP3QTY_ARITH_VAL_OP(+) MDP3QTY_ARITH_REF_OP(+=) @@ -46,8 +46,8 @@ MDP3QTY_ARITH_VAL_OP(/) MDP3QTY_ARITH_REF_OP(/=) MDP3QTY_ARITH_VAL_OP(%) MDP3QTY_ARITH_REF_OP(%=) -inline MDP3Quantity operator-(const MDP3Quantity &qty) { - return MDP3Quantity(-qty.value()); +inline Quantity operator-(const Quantity &qty) { + return Quantity(-qty.value()); } MDP3QTY_BIN_OP(>=, bool) MDP3QTY_BIN_OP(<=, bool) @@ -64,8 +64,8 @@ MDP3QTY_INT_BIN_OP(>=) MDP3QTY_INT_BIN_OP(<=) // technically this isn't an 'operator,' but defining 'abs' here // because it's a simple, common numerical op. -inline MDP3Quantity abs(MDP3Quantity qty) { - return qty.value() < 0 ? MDP3Quantity(-qty.value()) : qty; +inline Quantity abs(Quantity qty) { + return qty.value() < 0 ? Quantity(-qty.value()) : qty; } /////////////////////// // IcebergQuantity @@ -104,4 +104,4 @@ inline bool operator!=( #undef MDP3QTY_ARITH_VAL_OP #undef MDP3QTY_BIN_OP #undef ICEBERG_QTY_COMP_OP -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/common/tests/book_merging_tests.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/common/tests/book_merging_tests.cpp index e6e7b3bf2..3381210cb 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/common/tests/book_merging_tests.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/common/tests/book_merging_tests.cpp @@ -13,7 +13,7 @@ TEST_CASE("spartan_books", "[book_merging]") { for (auto &l : out) REQUIRE(l.quantity.value() == 0); - b[0] = BookLevel{{1, 7}, MDP3Quantity{1}, 1}; + b[0] = BookLevel{{1, 7}, Quantity{1}, 1}; merge_books(api::SIDE_BUY, b, ib, &out); for (size_t i = 0; i < b.size(); i++) { @@ -26,8 +26,8 @@ TEST_CASE("spartan_books", "[book_merging]") { ImpliedBook ib; Book out; - b[0] = BookLevel{{2, 7}, MDP3Quantity{1}, 1}; - ib[0] = BookLevel{{1, 7}, MDP3Quantity{2}, 3}; + b[0] = BookLevel{{2, 7}, Quantity{1}, 1}; + ib[0] = BookLevel{{1, 7}, Quantity{2}, 3}; merge_books(api::SIDE_BUY, b, ib, &out); REQUIRE(out[0] == b[0]); @@ -40,9 +40,9 @@ TEST_CASE("spartan_books", "[book_merging]") { ImpliedBook ib; Book out; - b[0] = BookLevel{{4, 7}, MDP3Quantity{1}, 1}; - b[1] = BookLevel{{2, 7}, MDP3Quantity{1}, 3}; - ib[0] = BookLevel{{3, 7}, MDP3Quantity{2}, 2}; + b[0] = BookLevel{{4, 7}, Quantity{1}, 1}; + b[1] = BookLevel{{2, 7}, Quantity{1}, 3}; + ib[0] = BookLevel{{3, 7}, Quantity{2}, 2}; merge_books(api::SIDE_BUY, b, ib, &out); REQUIRE(out[0] == b[0]); @@ -56,13 +56,13 @@ TEST_CASE("spartan_books", "[book_merging]") { ImpliedBook ib; Book out; - b[0] = BookLevel{{4, 7}, MDP3Quantity{1}, 1}; - b[1] = BookLevel{{3, 7}, MDP3Quantity{1}, 3}; - ib[0] = BookLevel{{3, 7}, MDP3Quantity{2}, 2}; + b[0] = BookLevel{{4, 7}, Quantity{1}, 1}; + b[1] = BookLevel{{3, 7}, Quantity{1}, 3}; + ib[0] = BookLevel{{3, 7}, Quantity{2}, 2}; merge_books(api::SIDE_BUY, b, ib, &out); REQUIRE(out[0] == b[0]); - REQUIRE(out[1] == (BookLevel{{3, 7}, MDP3Quantity{3}, 5})); + REQUIRE(out[1] == (BookLevel{{3, 7}, Quantity{3}, 5})); REQUIRE(out[2].quantity.value() == 0); } @@ -71,8 +71,8 @@ TEST_CASE("spartan_books", "[book_merging]") { ImpliedBook ib; Book out; - b[0] = BookLevel{{2, 7}, MDP3Quantity{1}, 1}; - ib[0] = BookLevel{{4, 7}, MDP3Quantity{2}, 3}; + b[0] = BookLevel{{2, 7}, Quantity{1}, 1}; + ib[0] = BookLevel{{4, 7}, Quantity{2}, 3}; merge_books(api::SIDE_SELL, b, ib, &out); REQUIRE(out[0] == b[0]); @@ -85,9 +85,9 @@ TEST_CASE("spartan_books", "[book_merging]") { ImpliedBook ib; Book out; - b[0] = BookLevel{{2, 7}, MDP3Quantity{1}, 1}; - b[1] = BookLevel{{4, 7}, MDP3Quantity{1}, 3}; - ib[0] = BookLevel{{3, 7}, MDP3Quantity{2}, 2}; + b[0] = BookLevel{{2, 7}, Quantity{1}, 1}; + b[1] = BookLevel{{4, 7}, Quantity{1}, 3}; + ib[0] = BookLevel{{3, 7}, Quantity{2}, 2}; merge_books(api::SIDE_SELL, b, ib, &out); REQUIRE(out[0] == b[0]); @@ -101,12 +101,12 @@ TEST_CASE("spartan_books", "[book_merging]") { ImpliedBook ib; Book out; - b[0] = BookLevel{{3, 7}, MDP3Quantity{1}, 1}; - b[1] = BookLevel{{4, 7}, MDP3Quantity{1}, 3}; - ib[0] = BookLevel{{3, 7}, MDP3Quantity{2}, 2}; + b[0] = BookLevel{{3, 7}, Quantity{1}, 1}; + b[1] = BookLevel{{4, 7}, Quantity{1}, 3}; + ib[0] = BookLevel{{3, 7}, Quantity{2}, 2}; merge_books(api::SIDE_SELL, b, ib, &out); - REQUIRE(out[0] == (BookLevel{{3, 7}, MDP3Quantity{3}, 3})); + REQUIRE(out[0] == (BookLevel{{3, 7}, Quantity{3}, 3})); REQUIRE(out[1] == b[1]); REQUIRE(out[2].quantity.value() == 0); } diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.cpp index 30233c9af..da5af7f0b 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.cpp @@ -21,10 +21,10 @@ get_candidate_filter(bool is_spread) { /////////////////////// ImpliedContractData::ImpliedContractData() : _security_id(), _legs() {} -ImpliedContractData::ImpliedContractData(MDP3SecurityID security_id) +ImpliedContractData::ImpliedContractData(SecurityID security_id) : _security_id(security_id), _legs() {} -void ImpliedContractData::add_leg(MDP3SecurityID sec, MDP3Quantity qty) { +void ImpliedContractData::add_leg(SecurityID sec, Quantity qty) { if (qty.value() == 0) return; auto it = _legs.find(sec); @@ -36,11 +36,11 @@ void ImpliedContractData::add_leg(MDP3SecurityID sec, MDP3Quantity qty) { _legs.insert(std::make_pair(sec, qty)); } -void ImpliedContractData::remove_leg(MDP3SecurityID sec, MDP3Quantity qty) { +void ImpliedContractData::remove_leg(SecurityID sec, Quantity qty) { add_leg(sec, -qty); } -void ImpliedContractData::multiply_legs(MDP3Quantity multiplier) { +void ImpliedContractData::multiply_legs(Quantity multiplier) { if (multiplier.value() == 1) return; for (auto &l : _legs) @@ -53,7 +53,7 @@ void ImpliedContractData::print_legs(std::ostream &ostr) const { } void ImpliedContractData::merge( - const ImpliedContractData &other, MDP3Quantity multiplier) { + const ImpliedContractData &other, Quantity multiplier) { if (multiplier.value() != 0) for (auto l : other.legs()) add_leg(l.first, l.second * multiplier); @@ -63,7 +63,7 @@ void ImpliedContractData::merge( // ImpliedMarket /////////////////////// struct ImpliedMarket::PImpl { - std::map contracts; + std::map contracts; std::vector contracts_vect; }; @@ -77,14 +77,14 @@ ImpliedMarket::~ImpliedMarket() {} /////////////////////// // contract(s) accessors /////////////////////// -const std::map & +const std::map & ImpliedMarket::contracts() const { return _me->contracts; } // The returned ImpliedContractData& will not have any legs // (callers need to add them explicitly). -ImpliedContractData &ImpliedMarket::add_contract(MDP3SecurityID sec) { +ImpliedContractData &ImpliedMarket::add_contract(SecurityID sec) { auto it = _me->contracts.find(sec); if (it == _me->contracts.end()) { it = _me->contracts.emplace(sec, ImpliedContractData(sec)).first; @@ -93,7 +93,7 @@ ImpliedContractData &ImpliedMarket::add_contract(MDP3SecurityID sec) { return it->second; } -void ImpliedMarket::remove_contract(MDP3SecurityID sec) { +void ImpliedMarket::remove_contract(SecurityID sec) { _me->contracts.erase(sec); for (auto it = _me->contracts_vect.begin(); it != _me->contracts_vect.end(); it++) { @@ -131,7 +131,7 @@ void ImpliedMarket::_add_implied_combinations( continue; for (auto m : mults) { ImpliedContractData temp = implied_contract; - temp.merge(*_me->contracts_vect[leg_index], MDP3Quantity(m)); + temp.merge(*_me->contracts_vect[leg_index], Quantity(m)); auto mod_legs = impl_legs; mod_legs.insert(std::make_pair( _me->contracts_vect[leg_index]->security_id(), @@ -153,7 +153,7 @@ void ImpliedMarket::_add_implied_combinations( get_candidate_filter(contract.legs().size() > 1)); } -std::vector ImpliedMarket::implied_mkts(MDP3SecurityID sec) const { +std::vector ImpliedMarket::implied_mkts(SecurityID sec) const { auto cdata_it = _me->contracts.find(sec); std::vector rv; bts_assert(cdata_it != _me->contracts.end()); @@ -161,4 +161,4 @@ std::vector ImpliedMarket::implied_mkts(MDP3SecurityID sec) const { _add_implied_combinations(cdata_it->second, rv); return rv; } -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.h b/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.h index 8b1a42b48..b894c8ad4 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/implied/implied_market.h @@ -7,45 +7,45 @@ #include namespace bts::spartan::mdp3 { -using Legs = boost::container::flat_map; +using Legs = boost::container::flat_map; struct ImpliedContractData { ImpliedContractData(); - ImpliedContractData(MDP3SecurityID security_id); + ImpliedContractData(SecurityID security_id); - MDP3SecurityID security_id() const { return _security_id; } + SecurityID security_id() const { return _security_id; } const Legs &legs() const { return _legs; } - void add_leg(MDP3SecurityID sec, MDP3Quantity qty); - void remove_leg(MDP3SecurityID sec, MDP3Quantity qty); + void add_leg(SecurityID sec, Quantity qty); + void remove_leg(SecurityID sec, Quantity qty); void merge( const ImpliedContractData &other, - MDP3Quantity multiplier = MDP3Quantity(1)); - MDP3Quantity leg_size(MDP3SecurityID sec) const { + Quantity multiplier = Quantity(1)); + Quantity leg_size(SecurityID sec) const { auto it = _legs.find(sec); - return it == _legs.end() ? MDP3Quantity(0) : it->second; + return it == _legs.end() ? Quantity(0) : it->second; } - void multiply_legs(MDP3Quantity multiplier); - void negate() { multiply_legs(MDP3Quantity(-1)); } + void multiply_legs(Quantity multiplier); + void negate() { multiply_legs(Quantity(-1)); } void print_legs(std::ostream &ostr = std::cout) const; private: - MDP3SecurityID _security_id; + SecurityID _security_id; Legs _legs; }; using LegData = boost::container:: - flat_map>; + flat_map>; struct ImpliedMarket { ImpliedMarket(); ~ImpliedMarket(); - const std::map &contracts() const; + const std::map &contracts() const; // The returned ImpliedContractData& will not have any legs // (callers need to add them explicitly). - ImpliedContractData &add_contract(MDP3SecurityID sec); - void remove_contract(MDP3SecurityID sec); - std::vector implied_mkts(MDP3SecurityID sec) const; + ImpliedContractData &add_contract(SecurityID sec); + void remove_contract(SecurityID sec); + std::vector implied_mkts(SecurityID sec) const; private: struct PImpl; @@ -72,4 +72,4 @@ operator<<(std::ostream &out, const ImpliedContractData &i) { } return out; } -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.cpp index 3bc418978..200335c9a 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.cpp @@ -12,15 +12,15 @@ struct RealTimeHandler::TradeSummary { ::mdp3::MDUpdateAction::Value update_action; InstrumentSnapshot *security; md::IntPrice price; - MDP3Quantity quantity; + Quantity quantity; size_t n_orders; ::mdp3::AggressorSide::Value aggressor; MDP3TradeEntryID trade_entry_id; }; struct RealTimeHandler::TradeOrderDetail { - MDP3OrderKey order_id; - MDP3Quantity quantity; + OrderKey order_id; + Quantity quantity; }; struct RealTimeHandler::PImpl { @@ -30,7 +30,7 @@ struct RealTimeHandler::PImpl { current_packet_sn(0), current_event(), observer(o), pending_ts(), pending_trade_order_detail() {} - std::unordered_map> + std::unordered_map> instruments; TimeStamp current_packet_send_time; @@ -169,7 +169,7 @@ void RealTimeHandler::operator()(::mdp3::MDIncrementalRefreshBook46 &m) { EventGuard ev(*this, m); struct MDEntryCache { - MDP3SecurityID id; + SecurityID id; api::Side side; md::IntPrice price; }; @@ -177,7 +177,7 @@ void RealTimeHandler::operator()(::mdp3::MDIncrementalRefreshBook46 &m) { size_t cache_idx = 0; m.noMDEntries().forEach([&ev, this, &cache, &cache_idx](auto &md_entry) { - auto sid = MDP3SecurityID{md_entry.securityID()}; + auto sid = SecurityID{md_entry.securityID()}; auto iptr = find_instrument(sid); if (!iptr) { cache_idx++; @@ -189,7 +189,7 @@ void RealTimeHandler::operator()(::mdp3::MDIncrementalRefreshBook46 &m) { auto level = BookLevel{ md::IntPrice{ md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}, - MDP3Quantity{md_entry.mDEntrySize()}, + Quantity{md_entry.mDEntrySize()}, md_entry.numberOfOrders() != md_entry.numberOfOrdersNullValue() ? md_entry.numberOfOrders() : 1}; @@ -253,11 +253,11 @@ void RealTimeHandler::operator()(::mdp3::MDIncrementalRefreshBook46 &m) { if (!iptr) return; MDP3Order order; - order.key = MDP3OrderKey{order_id_entry.orderID()}; + order.key = OrderKey{order_id_entry.orderID()}; order.security = sid; order.side = md_entry.side; order.priority = MDP3OrderPriority{order_id_entry.mDOrderPriority()}; - order.quantity = MDP3Quantity{order_id_entry.mDDisplayQty()}; + order.quantity = Quantity{order_id_entry.mDDisplayQty()}; order.price = md_entry.price; switch (order_id_entry.orderUpdateAction()) { case ::mdp3::OrderUpdateAction::New: @@ -281,7 +281,7 @@ void RealTimeHandler::operator()( EventGuard ev(*this, m); m.noMDEntries().forEach([&ev, this](auto &md_entry) { - auto sid = MDP3SecurityID{md_entry.securityID()}; + auto sid = SecurityID{md_entry.securityID()}; auto iptr = find_instrument(sid); if (!iptr) return; @@ -289,14 +289,14 @@ void RealTimeHandler::operator()( switch (md_entry.mDEntryType()) { case ::mdp3::MDEntryTypeDailyStatistics::ClearedVolume: - iptr->set_cleared_volume(MDP3Quantity{md_entry.mDEntrySize()}); + iptr->set_cleared_volume(Quantity{md_entry.mDEntrySize()}); break; case ::mdp3::MDEntryTypeDailyStatistics::FixingPrice: iptr->set_fixing_price(md::IntPrice{ md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}); break; case ::mdp3::MDEntryTypeDailyStatistics::OpenInterest: - iptr->set_open_interest(MDP3Quantity{md_entry.mDEntrySize()}); + iptr->set_open_interest(Quantity{md_entry.mDEntrySize()}); break; case ::mdp3::MDEntryTypeDailyStatistics::SettlementPrice: iptr->set_settlement_price(md::IntPrice{ @@ -313,7 +313,7 @@ void RealTimeHandler::operator()( EventGuard ev(*this, m); m.noMDEntries().forEach([&ev, this](auto &md_entry) { - auto sid = MDP3SecurityID{md_entry.securityID()}; + auto sid = SecurityID{md_entry.securityID()}; auto iptr = find_instrument(sid); if (!iptr) return; @@ -334,18 +334,18 @@ void RealTimeHandler::operator()(::mdp3::MDIncrementalRefreshOrderBook47 &m) { EventGuard ev(*this, m); m.noMDEntries().forEach([&ev, this](auto &md_entry) { - auto sid = MDP3SecurityID{md_entry.securityID()}; + auto sid = SecurityID{md_entry.securityID()}; auto iptr = find_instrument(sid); if (!iptr) return; ev.record_security_change(iptr); MDP3Order order; - order.key = MDP3OrderKey{md_entry.orderID()}; + order.key = OrderKey{md_entry.orderID()}; order.security = sid; order.side = convert_side(md_entry.mDEntryType()); order.priority = MDP3OrderPriority{md_entry.mDOrderPriority()}; - order.quantity = MDP3Quantity{md_entry.mDDisplayQty()}; + order.quantity = Quantity{md_entry.mDDisplayQty()}; order.price = md::IntPrice{ md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}; switch (md_entry.mDUpdateAction()) { @@ -371,7 +371,7 @@ void RealTimeHandler::operator()( EventGuard ev(*this, m); m.noMDEntries().forEach([&ev, this](auto &md_entry) { - auto sid = MDP3SecurityID{md_entry.securityID()}; + auto sid = SecurityID{md_entry.securityID()}; auto iptr = find_instrument(sid); if (!iptr) return; @@ -433,7 +433,7 @@ void RealTimeHandler::operator()( EventGuard ev(*this, m); m.noMDEntries().forEach([&ev, this](auto &md_entry) { - auto sid = MDP3SecurityID{md_entry.securityID()}; + auto sid = SecurityID{md_entry.securityID()}; auto iptr = find_instrument(sid); if (!iptr) return; @@ -444,7 +444,7 @@ void RealTimeHandler::operator()( summary.security = iptr; summary.price = md::IntPrice{ md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}; - summary.quantity = MDP3Quantity{md_entry.mDEntrySize()}; + summary.quantity = Quantity{md_entry.mDEntrySize()}; summary.n_orders = md_entry.numberOfOrders(); summary.aggressor = md_entry.aggressorSide(); summary.trade_entry_id = MDP3TradeEntryID{md_entry.mDTradeEntryID()}; @@ -453,8 +453,8 @@ void RealTimeHandler::operator()( m.noOrderIDEntries().forEach([this](auto &order_id_entry) { TradeOrderDetail detail; - detail.order_id = MDP3OrderKey{order_id_entry.orderID()}; - detail.quantity = MDP3Quantity{order_id_entry.lastQty()}; + detail.order_id = OrderKey{order_id_entry.orderID()}; + detail.quantity = Quantity{order_id_entry.lastQty()}; me->pending_trade_order_detail.emplace_back(detail); }); } @@ -462,13 +462,13 @@ void RealTimeHandler::operator()( void RealTimeHandler::operator()(::mdp3::MDIncrementalRefreshVolume37 &m) { EventGuard ev(*this, m); m.noMDEntries().forEach([&ev, this](auto &md_entry) { - auto sid = MDP3SecurityID{md_entry.securityID()}; + auto sid = SecurityID{md_entry.securityID()}; auto iptr = find_instrument(sid); if (!iptr) return; ev.record_security_change(iptr); - iptr->set_electronic_volume(MDP3Quantity{md_entry.mDEntrySize()}); + iptr->set_electronic_volume(Quantity{md_entry.mDEntrySize()}); }); } @@ -478,7 +478,7 @@ template void RealTimeHandler::on_instrument_definition(DefM &d) { *this, TimeStamp{d.lastUpdateTime()}, d.matchEventIndicator().endOfEvent()); - auto sid = MDP3SecurityID{d.securityID()}; + auto sid = SecurityID{d.securityID()}; if (auto iptr = find_instrument(sid); !iptr) { // We only add instruments if we observe them being created // because otherwise we cannot guarantee that the incremental @@ -537,7 +537,7 @@ void RealTimeHandler::operator()(::mdp3::SecurityStatus30 &ss) { // This applies only to the security if (ss.securityID() != ss.securityIDNullValue()) { - auto sid = MDP3SecurityID{ss.securityID()}; + auto sid = SecurityID{ss.securityID()}; auto iptr = find_instrument(sid); if (!iptr) return; @@ -654,7 +654,7 @@ void RealTimeHandler::on_end_of_event() { } } -InstrumentSnapshot *RealTimeHandler::find_instrument(MDP3SecurityID id) { +InstrumentSnapshot *RealTimeHandler::find_instrument(SecurityID id) { auto it = me->instruments.find(id); if (it == me->instruments.end()) return nullptr; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.h b/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.h index e8535fec1..60c211590 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/realtime/RealTimeHandler.h @@ -95,7 +95,7 @@ class RealTimeHandler { struct TradeOrderDetail; std::unique_ptr me; - InstrumentSnapshot *find_instrument(MDP3SecurityID); + InstrumentSnapshot *find_instrument(SecurityID); void on_end_of_event(); template void on_instrument_definition(Def &); }; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/recovery/RecoveryHandler.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/recovery/RecoveryHandler.cpp index e68fa6d31..2d7b63610 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/recovery/RecoveryHandler.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/recovery/RecoveryHandler.cpp @@ -52,11 +52,11 @@ RecoveryHandler::MaybeSnapshot RecoveryHandler::try_build_snapshot_and_reset() { // Do we have definitions for every book? auto &books = me->book_snapshot.get_books(); auto &definitions_ref = me->definition_snapshot.get_definitions(); - std::unordered_set definition_ids; + std::unordered_set definition_ids; for (auto &d : definitions_ref) definition_ids.insert(d.security_id()); for (auto &b : books) - if (definition_ids.count(MDP3SecurityID{b.book->securityID()}) == 0) { + if (definition_ids.count(SecurityID{b.book->securityID()}) == 0) { // We are missing a definition for one of the books so we // need to start over and get a new round of definitions LOG(Spartan, Diag, @@ -118,9 +118,9 @@ RecoveryHandler::MaybeSnapshot RecoveryHandler::try_build_snapshot_and_reset() { auto book_snaps = me->book_snapshot.move_books_and_reset(); // Index books so we can join them with the definitions - std::unordered_map book_snaps_idx; + std::unordered_map book_snaps_idx; for (auto &bs : book_snaps) - book_snaps_idx[MDP3SecurityID{bs.book->securityID()}] = &bs; + book_snaps_idx[SecurityID{bs.book->securityID()}] = &bs; // Now iterate over all definitions, locate the corresponding book, // if any, and use both to build an InstrumentSnapshot instance. @@ -344,7 +344,7 @@ void RecoveryHandler::update_book_in_snapshot( md::IntPrice{ md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}, - MDP3Quantity{md_entry.mDEntrySize()}, + Quantity{md_entry.mDEntrySize()}, md_entry.numberOfOrders()}); break; case ::mdp3::MDEntryType::ImpliedBid: @@ -355,7 +355,7 @@ void RecoveryHandler::update_book_in_snapshot( md::IntPrice{ md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}, - MDP3Quantity{md_entry.mDEntrySize()}, + Quantity{md_entry.mDEntrySize()}, md_entry.numberOfOrders()}); break; case ::mdp3::MDEntryType::Trade: @@ -377,10 +377,10 @@ void RecoveryHandler::update_book_in_snapshot( md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}); break; case ::mdp3::MDEntryType::ClearedVolume: - snap.set_cleared_volume(MDP3Quantity{md_entry.mDEntrySize()}); + snap.set_cleared_volume(Quantity{md_entry.mDEntrySize()}); break; case ::mdp3::MDEntryType::OpenInterest: - snap.set_open_interest(MDP3Quantity{md_entry.mDEntrySize()}); + snap.set_open_interest(Quantity{md_entry.mDEntrySize()}); break; case ::mdp3::MDEntryType::BookReset: snap.reset_books(); @@ -398,7 +398,7 @@ void RecoveryHandler::update_book_in_snapshot( md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}); break; case ::mdp3::MDEntryType::ElectronicVolume: - snap.set_electronic_volume(MDP3Quantity{md_entry.mDEntrySize()}); + snap.set_electronic_volume(Quantity{md_entry.mDEntrySize()}); break; case ::mdp3::MDEntryType::ThresholdLimitsandPriceBandVariation: break; @@ -424,13 +424,13 @@ void RecoveryHandler::update_book_chunk_in_snapshot( InstrumentSnapshot &snap, ::mdp3::SnapshotFullRefreshOrderBook53 &fr) { fr.noMDEntries().forEach([&snap](auto &md_entry) { MDP3Order order; - order.key = MDP3OrderKey{md_entry.orderID()}; + order.key = OrderKey{md_entry.orderID()}; order.security = snap.security_id(); order.side = convert_side(md_entry.mDEntryType()); order.priority = MDP3OrderPriority{md_entry.mDOrderPriority()}; order.price = md::IntPrice{ md_entry.mDEntryPx().mantissa(), md_entry.mDEntryPx().exponent()}; - order.quantity = MDP3Quantity{md_entry.mDDisplayQty()}; + order.quantity = Quantity{md_entry.mDDisplayQty()}; snap.insert_order(order); }); } diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/tests/spartan_md_tests.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/tests/spartan_md_tests.cpp index c1521cf43..0ef8238e3 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/tests/spartan_md_tests.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/tests/spartan_md_tests.cpp @@ -49,7 +49,7 @@ TEST_CASE("spartan_md", "[spartan_md]") { SECTION("can_get_to_realtime") { struct Obs : IChannelObserver { bool real_time = false; - std::unordered_map + std::unordered_map instruments; void on_recovery_complete( std::vector const &snaps) override { diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp index 8b32920bf..817760cb5 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/book_utils.cpp @@ -7,11 +7,11 @@ namespace bts::spartan::mdp3::book_utils { template struct LegBookCursor { - LegBookCursor(const TBook *source, MDP3Quantity unit_qty) + LegBookCursor(const TBook *source, Quantity unit_qty) : _source(source), _unit_qty(unit_qty) {} // The qty (not in terms of leg 'units') at the current level. - MDP3Quantity curr_level_qty() const { + Quantity curr_level_qty() const { return (_source->begin() + _curr_level)->quantity - _curr_level_qty_used; } // The price of the current level. @@ -19,15 +19,15 @@ template struct LegBookCursor { return (_source->begin() + _curr_level)->price; } // The [signed] qty of this leg in its synthetic definition. - MDP3Quantity unit_qty() const { return _unit_qty; } + Quantity unit_qty() const { return _unit_qty; } // Counts the number of units available at the best price. As the // synthetic book is computed, the limiting factor of each price level // is equal to the 'units_at_best_price' minimum of all the legs. // Returns a tuple of the unit price, and the number of units available at // that price. - std::tuple units_at_best_price() const { + std::tuple units_at_best_price() const { if (_curr_level >= _source->size()) - return {md::INT_NAN, MDP3Quantity(0)}; + return {md::INT_NAN, Quantity(0)}; auto auq = abs(_unit_qty); if (curr_level_qty() >= auq) return { @@ -40,15 +40,15 @@ template struct LegBookCursor { return { (cost + it->price * auq.value()) * (_unit_qty / abs(_unit_qty)).value(), - MDP3Quantity(1)}; + Quantity(1)}; cost += it->price * it->quantity.value(); auq -= it->quantity; } - return {md::INT_NAN, MDP3Quantity(0)}; + return {md::INT_NAN, Quantity(0)}; } // Removes the specified qty from the top of the book, and returns the total // cost. - md::IntPrice remove(MDP3Quantity qty) { + md::IntPrice remove(Quantity qty) { if (_curr_level >= _source->size() || qty <= 0) return md::INT_NAN; if (curr_level_qty() <= qty) { @@ -64,15 +64,15 @@ template struct LegBookCursor { } // Removes the specified qty of units from the top of the book, and returns // the total cost. - md::IntPrice remove_units(MDP3Quantity qty) { + md::IntPrice remove_units(Quantity qty) { return remove(qty * abs(_unit_qty)); } private: const TBook *_source; - MDP3Quantity _unit_qty; + Quantity _unit_qty; uint32_t _curr_level = 0; - MDP3Quantity _curr_level_qty_used = MDP3Quantity(0); + Quantity _curr_level_qty_used = Quantity(0); }; std::ostream &fmt_ladder(const SmallBook &bs, std::ostream &output) { @@ -80,7 +80,7 @@ std::ostream &fmt_ladder(const SmallBook &bs, std::ostream &output) { return output; std::function get_price( [](const auto &sbl) { return sbl.price; }); - std::function get_qty( + std::function get_qty( [](const auto &sbl) { return sbl.quantity; }); if (bs.size() > 1 && bs.front().price > (bs.begin() + 1)->price) { // ask book @@ -126,7 +126,7 @@ inline void from_small_book( } } -bool remove_qty(SmallBook &book, MDP3Quantity qty) { +bool remove_qty(SmallBook &book, Quantity qty) { qty = abs(qty); for (auto it = book.begin(); it != book.end() && qty > 0; it = book.erase(it)) { @@ -139,18 +139,18 @@ bool remove_qty(SmallBook &book, MDP3Quantity qty) { return qty.value() == 0; } -MDP3Quantity volume(const SmallBook &book) { +Quantity volume(const SmallBook &book) { auto get_qty = [](const auto &bl) { return bl.quantity.value(); }; - return MDP3Quantity( + return Quantity( ranges::accumulate(book | ranges::views::transform(get_qty), 0)); } template inline void _compute_synthetic_book( TBook &dest, - const std::vector> &leg_mkts, + const std::vector> &leg_mkts, uint32_t max_depth, - std::optional max_qty = std::nullopt) { + std::optional max_qty = std::nullopt) { if (leg_mkts.empty()) return; @@ -160,7 +160,7 @@ inline void _compute_synthetic_book( } while (max_depth-- > 0 && (!max_qty.has_value() || max_qty.value() > 0)) { auto cost = md::INT_ZERO; - MDP3Quantity limiting_factor(std::numeric_limits::max()); + Quantity limiting_factor(std::numeric_limits::max()); for (const auto &l : leg_cursors) { auto [unit_price, qty_at_price] = l.units_at_best_price(); limiting_factor = std::min(limiting_factor, qty_at_price); @@ -180,7 +180,7 @@ inline void _compute_synthetic_book( void compute_synthetic_book( SmallBook &dest, - const std::vector> + const std::vector> &leg_mkts, uint32_t depth) { _compute_synthetic_book(dest, leg_mkts, depth); @@ -190,10 +190,10 @@ void compute_synthetic_books( SmallBook &bids_dest, SmallBook &asks_dest, const std::vector< - std::tuple> &leg_mkts, + std::tuple> &leg_mkts, uint32_t depth) { - std::vector> leg_bids; - std::vector> leg_asks; + std::vector> leg_bids; + std::vector> leg_asks; for (auto [qty, price_mult, bids, asks] : leg_mkts) { leg_bids.emplace_back(qty, price_mult, qty.value() > 0 ? bids : asks); leg_asks.emplace_back(qty, price_mult, qty.value() < 0 ? bids : asks); @@ -205,11 +205,11 @@ void compute_synthetic_books( void compute_synthetic_books( Book &bids_dest, Book &asks_dest, - const std::vector> + const std::vector> &leg_mkts, uint32_t depth) { SmallBook sb_bids_dest, sb_asks_dest; - std::vector> + std::vector> sb_leg_mkts; for (const auto &[qty, pr, bbook, abook] : leg_mkts) sb_leg_mkts.push_back( @@ -221,9 +221,9 @@ void compute_synthetic_books( void compute_synthetic_book( Book &book_out, - const std::vector> &leg_mkts, + const std::vector> &leg_mkts, uint32_t depth) { - std::vector> sleg_mkts; + std::vector> sleg_mkts; for (auto [qty, price, bk] : leg_mkts) sleg_mkts.emplace_back(qty, price, to_small_book(bk)); SmallBook sbook_out; 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 e019ffcd5..4312e48f1 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 @@ -11,31 +11,31 @@ namespace bts::spartan::mdp3::book_utils { inline std::ostream & -fmt_price_level(std::ostream &out, md::IntPrice price, MDP3Quantity qty) { +fmt_price_level(std::ostream &out, md::IntPrice price, Quantity qty) { out << qty << " @ " << price; return out; } inline std::ostream &fmt_price_level( - std::ostream &out, api::Side side, md::IntPrice price, MDP3Quantity qty) { + std::ostream &out, api::Side side, md::IntPrice price, Quantity qty) { out << side << " "; fmt_price_level(out, price, qty); return out; } -inline std::string fmt_price_level(md::IntPrice price, MDP3Quantity qty) { +inline std::string fmt_price_level(md::IntPrice price, Quantity qty) { std::stringstream out; fmt_price_level(out, price, qty); return out.str(); } inline std::string -fmt_price_level(const std::tuple &pl) { +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) { +fmt_price_level(api::Side side, md::IntPrice price, Quantity qty) { std::stringstream out; fmt_price_level(out, side, price, qty); return out.str(); @@ -48,7 +48,7 @@ inline std::string fmt_price_level(api::Side side, SmallBookLevel l) { } inline std::string fmt_price_level( - api::Side side, const std::tuple &pl) { + api::Side side, const std::tuple &pl) { return fmt_price_level(side, std::get<0>(pl), std::get<1>(pl)); } @@ -57,7 +57,7 @@ inline std::ostream &fmt_ladder( Iter first, Iter last, std::function get_price, - std::function get_qty, + std::function get_qty, std::ostream &output, bool reverse_incr = false) { // @@ -88,7 +88,7 @@ inline std::ostream &fmt_ladder( Iter first_ask, Iter last_ask, std::function get_price, - std::function get_qty, + std::function get_qty, std::ostream &output) { fmt_ladder(last_ask, first_ask, get_price, get_qty, output, true); if (first_bid != last_bid && get_qty(*first_bid).value() != 0) { @@ -105,7 +105,7 @@ template inline bool has_min_qty( Iter first, Iter last, - MDP3Quantity qty, + Quantity qty, md::IntPrice limit_price = md::INT_NAN, api::Side side = api::Side::SIDE_UNDEFINED) { if (qty.value() == 0) @@ -122,8 +122,8 @@ inline bool has_min_qty( return false; } -bool remove_qty(SmallBook &book, MDP3Quantity qty); -MDP3Quantity volume(const SmallBook &book); +bool remove_qty(SmallBook &book, Quantity qty); +Quantity volume(const SmallBook &book); // TIter should point to BookLevel items. template @@ -131,7 +131,7 @@ inline void change_unit_qty( TIter book_in_first, TIter book_in_last, SmallBook &book_out, - MDP3Quantity unit_qty) { + Quantity unit_qty) { // bts_assert(unit_qty.value() > 0); md::IntPrice running_cost = md::INT_ZERO; @@ -149,7 +149,7 @@ inline void change_unit_qty( auto qty_in_lev = it->quantity.value(); if (running_qty > 0) { running_cost += it->price * unit_remainder; - book_out.emplace_back(running_cost, MDP3Quantity(1)); + book_out.emplace_back(running_cost, Quantity(1)); qty_in_lev -= unit_remainder; running_cost = md::INT_ZERO; running_qty = 0; @@ -157,7 +157,7 @@ inline void change_unit_qty( auto unit_lev_remainder = qty_in_lev / unit_qty.value(); if (unit_lev_remainder > 0) book_out.emplace_back( - it->price * unit_qty.value(), MDP3Quantity(unit_lev_remainder)); + it->price * unit_qty.value(), Quantity(unit_lev_remainder)); running_cost = it->price * (qty_in_lev - unit_lev_remainder * unit_qty.value()); running_qty = qty_in_lev - unit_lev_remainder * unit_qty.value(); @@ -167,7 +167,7 @@ inline void change_unit_qty( void compute_synthetic_book( SmallBook &dest, - const std::vector> + const std::vector> &leg_mkts, uint32_t depth); @@ -175,18 +175,18 @@ void compute_synthetic_books( SmallBook &bids_dest, SmallBook &asks_dest, const std::vector< - std::tuple> &leg_mkts, + std::tuple> &leg_mkts, uint32_t depth); void compute_synthetic_books( Book &bids_dest, Book &asks_dest, - const std::vector> + const std::vector> &leg_mkts, uint32_t depth); void compute_synthetic_book( Book &book_out, - const std::vector> &leg_mkts, + const std::vector> &leg_mkts, uint32_t depth); } // namespace bts::spartan::mdp3::book_utils diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.cpp index 44144b8d6..e3499d94a 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/mdp3_utils.cpp @@ -499,7 +499,7 @@ struct CSVObs : IChannelObserver { std::ofstream books; std::ofstream packets; std::ofstream spread_legs; - std::unordered_set known_securities; + std::unordered_set known_securities; std::stringstream ts_buffer; template void print_book(B const &b) { @@ -739,7 +739,7 @@ int to_csv(std::string const &file) { return 0; } -std::unordered_map +std::unordered_map find_icebergs(std::string const &pcap) { return IcebergFinder::find_all(pcap); } 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 fcbdf955d..575e7cbb5 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 @@ -13,14 +13,14 @@ namespace bts::spartan::mdp3 { inline md::IntPrice -get_price(const std::tuple &price_level) { +get_price(const std::tuple &price_level) { return std::get<0>(price_level); } -inline MDP3Quantity -get_qty(const std::tuple &price_level) { +inline Quantity +get_qty(const std::tuple &price_level) { return std::get<1>(price_level); } -inline MDP3Quantity get_total_qty(const MDP3Order &order) { +inline Quantity get_total_qty(const MDP3Order &order) { return order.iceberg_quantity.has_value() ? order.iceberg_quantity.value().total : order.quantity; @@ -28,7 +28,7 @@ inline MDP3Quantity get_total_qty(const MDP3Order &order) { // all order quantity props should contain the original values (before // subtracting fills, or any other qty updates, etc.) inline void set_total_qty( - MDP3Order &order, MDP3Quantity total_qty, bool reset_show_qty = false) { + MDP3Order &order, Quantity total_qty, bool reset_show_qty = false) { // bool verbose = order.key.value() = 647354912656; bts_assert(total_qty.value() >= 0); if (order.iceberg_quantity.has_value()) { @@ -48,7 +48,7 @@ inline void set_total_qty( std::min(order.iceberg_quantity.value().show, total_qty); } else { order.quantity = order.iceberg_quantity.value().show < total_qty - ? (total_qty + MDP3Quantity(adj)) % + ? (total_qty + Quantity(adj)) % order.iceberg_quantity.value().show : total_qty; if (order.quantity.value() == 0) @@ -60,9 +60,9 @@ inline void set_total_qty( order.quantity = total_qty; } -inline MDP3Quantity book_volume(const SmallBook &book) { +inline Quantity book_volume(const SmallBook &book) { auto get_qty = [](const auto &bl) { return bl.quantity.value(); }; - return MDP3Quantity( + return Quantity( ranges::accumulate(book | ranges::views::transform(get_qty), 0)); } @@ -76,7 +76,7 @@ inline bool orders_equal(const MDP3Order &lhs, const MDP3Order &rhs) { } inline std::string fmt_order( - MDP3OrderKey key, api::Side side, md::IntPrice price, MDP3Quantity qty) { + OrderKey key, api::Side side, md::IntPrice price, Quantity qty) { std::stringstream str; str << "[" << key.value() << "] " << " " << (side == api::Side::SIDE_BUY ? "Buy" : "Sell") << " " @@ -88,7 +88,7 @@ template inline void accumulate_fills( TIter first, TIter last, - std::unordered_map &dest) { + std::unordered_map &dest) { while (first != last) { auto it = dest.find(first->key); if (it == dest.end()) @@ -101,14 +101,14 @@ inline void accumulate_fills( inline void accumulate_fills( const std::vector &fills, - std::unordered_map &dest) { + std::unordered_map &dest) { accumulate_fills(fills.begin(), fills.end(), dest); } -inline std::unordered_map +inline std::unordered_map accumulate_fills(const std::vector &fills) { - std::unordered_map rv; + std::unordered_map rv; accumulate_fills(fills.begin(), fills.end(), rv); return rv; } -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.cpp index eab5aa306..a3d31749a 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.cpp @@ -7,7 +7,7 @@ namespace bts::spartan::mdp3 { size_t gcd(InstrumentParts const &); PolyInstrument make_spread( - mdp3::MDP3SecurityID id, std::initializer_list legs) { + mdp3::SecurityID id, std::initializer_list legs) { PolyInstrument result; result.sec_id = id; for (auto l : legs) @@ -15,7 +15,7 @@ PolyInstrument make_spread( return result; } -PolyInstrument make_outright(mdp3::MDP3SecurityID id) { +PolyInstrument make_outright(mdp3::SecurityID id) { PolyInstrument result; result.sec_id = id; result.parts.push_back(InstrumentPart{id, 1}); @@ -23,7 +23,7 @@ PolyInstrument make_outright(mdp3::MDP3SecurityID id) { } const InstrumentDefinition & -find_instrument(const InstrumentMap &ins_map, MDP3SecurityID sec_id) { +find_instrument(const InstrumentMap &ins_map, SecurityID sec_id) { auto it = ins_map.find(sec_id); bts_assert(it != ins_map.end()); bts_assert(it->second); @@ -103,7 +103,7 @@ bool is_polygon( std::vector const &candidate) { bts_assert(candidate.size() == ratio_modifier.size()); InstrumentParts reduced_parts; - auto get_or_make_part = [&](mdp3::MDP3SecurityID id) -> InstrumentPart & { + auto get_or_make_part = [&](mdp3::SecurityID id) -> InstrumentPart & { for (auto &l : reduced_parts) if (l.sec_id == id) return l; @@ -236,7 +236,7 @@ std::vector find_polygons( } uint32_t abs_contracts(const Polygon &polygon, const InstrumentMap &ins_map) { - auto find_def = [&](MDP3SecurityID id) { + auto find_def = [&](SecurityID id) { auto it = ins_map.find(id); bts_assert(it != ins_map.end()); bts_assert(it->second); @@ -277,12 +277,12 @@ double tick_size(const Polygon &polygon, const InstrumentMap &ins_map) { } bool nets_to_0(Polygon const &p, std::vector const &universe) { - std::unordered_map + std::unordered_map universe_idx; for (auto &i : universe) universe_idx[i.sec_id] = &i; - std::unordered_map net; + std::unordered_map net; for (auto &polygon_point : p.parts) { auto &point_instrument = universe_idx[polygon_point.sec_id]; @@ -311,10 +311,10 @@ using InstrumentCluster = std::vector; std::vector clusterize(std::vector const &universe) { - std::unordered_map idx; + std::unordered_map idx; std::vector result; - Graph g; + Graph g; for (auto const &poly : universe) { idx[poly.sec_id] = poly; g.add_node(poly.sec_id); @@ -353,7 +353,7 @@ clusterize(std::vector const &universe) { std::string polygon_descriptor(Polygon const &p, InstrumentMap const &instruments) { - auto get_sec = [&instruments](MDP3SecurityID id) { + auto get_sec = [&instruments](SecurityID id) { auto it = instruments.find(id); bts_assert(it != instruments.end()); return *it->second; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h index 4e2d30594..a837326be 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/polygon_utils.h @@ -8,20 +8,20 @@ namespace bts::spartan::mdp3 { struct InstrumentPart { - mdp3::MDP3SecurityID sec_id = mdp3::MDP3SecurityID{0}; + mdp3::SecurityID sec_id = mdp3::SecurityID{0}; int ratio = 0; }; using InstrumentParts = boost::container::small_vector; struct PolyInstrument { - mdp3::MDP3SecurityID sec_id = mdp3::MDP3SecurityID{0}; + mdp3::SecurityID sec_id = mdp3::SecurityID{0}; InstrumentParts parts = {}; }; PolyInstrument -make_spread(mdp3::MDP3SecurityID, std::initializer_list legs); -PolyInstrument make_outright(mdp3::MDP3SecurityID); +make_spread(mdp3::SecurityID, std::initializer_list legs); +PolyInstrument make_outright(mdp3::SecurityID); const InstrumentDefinition & -find_instrument(const InstrumentMap &map, MDP3SecurityID sec_id); +find_instrument(const InstrumentMap &map, SecurityID sec_id); struct Polygon { InstrumentParts parts; }; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/DefinitionCollector.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/DefinitionCollector.h index ca38f6b85..4c466f06e 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/DefinitionCollector.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/DefinitionCollector.h @@ -11,8 +11,8 @@ namespace bts::spartan::mdp3 { // Find all security definitions in the pcap struct DefinitionCollector : IChannelObserver { - std::unordered_map result; - std::unordered_map ptr_result; + std::unordered_map result; + std::unordered_map ptr_result; void finit() override; void init() override; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.cpp index b873de450..0a6ac1275 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.cpp @@ -7,7 +7,7 @@ FillCounter::FillCounter() {} FillCounter::~FillCounter() {} struct FillCounter::PImpl { - std::map counts; + std::map counts; }; void FillCounter::init() { diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.h index 9391a7e4f..a20f58f63 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/FillCounter.h @@ -9,15 +9,15 @@ namespace bts::spartan::mdp3 { // count in descending order struct FillCount { - MDP3SecurityID sec_id; + SecurityID sec_id; std::string symbol; size_t fills; }; struct FillCounter : IChannelObserver { std::vector result; - std::unordered_map result_map() { - std::unordered_map result_idx; + std::unordered_map result_map() { + std::unordered_map result_idx; for (auto const &f : result) result_idx[f.sec_id] = f.fills; return result_idx; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.cpp index d4f20bbbf..acccc9fc8 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.cpp @@ -24,11 +24,11 @@ namespace bts::spartan::mdp3 { std::string _log_header() { return "IcebergFinder"; } struct FillInfo { - MDP3Quantity aggressive, passive; + Quantity aggressive, passive; FillInfo() : aggressive(0), passive(0) {} - MDP3Quantity total() const { return aggressive + passive; } + Quantity total() const { return aggressive + passive; } void on_fill(const MDP3Fill f) { if (f.aggressor != MDP3Fill::Aggressor::THIS_BUY && @@ -44,10 +44,10 @@ inline std::ostream &operator<<(std::ostream &out, const FillInfo &fi) { return out; } -MDP3Quantity _count_fills_by( +Quantity _count_fills_by( size_t event_id, - const std::vector> &fill_quantities) { - MDP3Quantity rv(0); + const std::vector> &fill_quantities) { + Quantity rv(0); for (auto [ev, fqty] : fill_quantities) { if (ev > event_id) break; @@ -56,48 +56,48 @@ MDP3Quantity _count_fills_by( return rv; } -std::tuple _show_qty_at( +std::tuple _show_qty_at( size_t event_id, - const std::vector> &show_quantities) { + const std::vector> &show_quantities) { if (show_quantities.empty()) - return {0, MDP3Quantity(0)}; + return {0, Quantity(0)}; // get show qty from latest event at or before the specified event. auto it = std::upper_bound( show_quantities.begin(), show_quantities.end(), - std::make_tuple(event_id, MDP3Quantity(0)), + std::make_tuple(event_id, Quantity(0)), [](const auto &a, const auto &b) { return std::get<0>(a) < std::get<0>(b); }); if (it == show_quantities.begin()) - return {0, MDP3Quantity(0)}; + return {0, Quantity(0)}; it--; return *it; } IcebergInput::IcebergInput( - MDP3Quantity total_qty, - std::vector> show_quantities, - std::vector> fill_quantities) + Quantity total_qty, + std::vector> show_quantities, + std::vector> fill_quantities) : _total_qty(total_qty), _show_quantities(show_quantities), _fill_quantities(fill_quantities) {} IcebergFinder::IcebergFinder() {} IcebergFinder::~IcebergFinder() {} -MDP3Quantity IcebergInput::count_fills_by(size_t event_id) const { +Quantity IcebergInput::count_fills_by(size_t event_id) const { return _count_fills_by(event_id, _fill_quantities); } -std::tuple +std::tuple IcebergInput::show_qty_at(size_t event_id) const { return _show_qty_at(event_id, _show_quantities); } void IcebergInputBuilder::on_change( size_t event_id, - MDP3Quantity qty, - MDP3Quantity pass_fills, - MDP3Quantity aggr_fills) { + Quantity qty, + Quantity pass_fills, + Quantity aggr_fills) { if (_show_quantities.empty() || _show_qty_realized) { _show_quantities.emplace_back(event_id, qty); _show_qty_realized = false; @@ -138,9 +138,9 @@ void IcebergInputBuilder::on_change( void IcebergInputBuilder::on_removed( size_t event_id, - MDP3Quantity qty, - MDP3Quantity pass_fills, - MDP3Quantity aggr_fills) { + Quantity qty, + Quantity pass_fills, + Quantity aggr_fills) { if (pass_fills.value() > 0 && aggr_fills.value() == 0) { if (!_is_iceberg) { _is_iceberg = (qty != _active_qty - pass_fills); @@ -160,8 +160,8 @@ void IcebergInputBuilder::on_removed( } struct IcebergFinder::PImpl { - std::unordered_map fills; - std::unordered_map builder; + std::unordered_map fills; + std::unordered_map builder; }; void IcebergFinder::init() { @@ -236,8 +236,8 @@ void IcebergFinder::_on_order_change( auto &od = bd.first->second; od.key(order.key); auto fit = me->fills.find(order.key); - MDP3Quantity pfills(0); - MDP3Quantity afills(0); + Quantity pfills(0); + Quantity afills(0); if (fit != me->fills.end()) { afills += fit->second.aggressive; pfills += fit->second.passive; @@ -256,7 +256,7 @@ void IcebergFinder::_on_order_change( me->fills.erase(order.key); } -std::unordered_map +std::unordered_map IcebergFinder::find_all(const std::string &pcap) { IcebergFinder ibf; observe_channel(pcap, ibf); diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.h index 172077475..f07dd5b53 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/IcebergFinder.h @@ -15,21 +15,21 @@ namespace bts::spartan::mdp3 { struct IcebergInput { IcebergInput( - MDP3Quantity total_qty, - std::vector> show_quantities, - std::vector> fill_quantities); + Quantity total_qty, + std::vector> show_quantities, + std::vector> fill_quantities); - MDP3Quantity total_qty() const { return _total_qty; } + Quantity total_qty() const { return _total_qty; } - const std::vector> show_quantities() const { + const std::vector> show_quantities() const { return _show_quantities; } - std::tuple show_qty_at(size_t event_id) const; + std::tuple show_qty_at(size_t event_id) const; - const std::vector> fill_quantities() const { + const std::vector> fill_quantities() const { return _fill_quantities; } - MDP3Quantity count_fills_by(size_t event_id) const; + Quantity count_fills_by(size_t event_id) const; std::set all_eids() { std::set result; @@ -41,33 +41,33 @@ struct IcebergInput { } private: - MDP3Quantity _total_qty = MDP3Quantity(0); - std::vector> _show_quantities; - std::vector> _fill_quantities; + Quantity _total_qty = Quantity(0); + std::vector> _show_quantities; + std::vector> _fill_quantities; }; -using IcebergMap = std::unordered_map; +using IcebergMap = std::unordered_map; std::ostream &operator<<(std::ostream &out, const IcebergInput &ib); struct IcebergInputBuilder { - MDP3Quantity total_qty() const { return _filled_qty + _active_qty; } - MDP3Quantity filled_qty() const { return _filled_qty; } - MDP3Quantity active_qty() const { return _active_qty; } + Quantity total_qty() const { return _filled_qty + _active_qty; } + Quantity filled_qty() const { return _filled_qty; } + Quantity active_qty() const { return _active_qty; } bool is_iceberg() const { return _is_iceberg; } - MDP3OrderKey key() const { return _key; } - void key(MDP3OrderKey k) { _key = k; } - MDP3Quantity count_fills_by(size_t event_id) const; + OrderKey key() const { return _key; } + void key(OrderKey k) { _key = k; } + Quantity count_fills_by(size_t event_id) const; void on_change( size_t event_id, - MDP3Quantity qty, - MDP3Quantity pass_fill_qty, - MDP3Quantity aggr_fill_qty); + Quantity qty, + Quantity pass_fill_qty, + Quantity aggr_fill_qty); void on_removed( size_t event_id, - MDP3Quantity qty, - MDP3Quantity pass_fill_qty, - MDP3Quantity aggr_fill_qty); + Quantity qty, + Quantity pass_fill_qty, + Quantity aggr_fill_qty); IcebergInput to_input() const { IcebergInput rv(total_qty(), _show_quantities, _fill_quantities); @@ -75,11 +75,11 @@ struct IcebergInputBuilder { } private: - MDP3OrderKey _key = MDP3OrderKey(0); - MDP3Quantity _filled_qty = MDP3Quantity(0); - MDP3Quantity _active_qty = MDP3Quantity(0); - std::vector> _show_quantities; - std::vector> _fill_quantities; + OrderKey _key = OrderKey(0); + Quantity _filled_qty = Quantity(0); + Quantity _active_qty = Quantity(0); + std::vector> _show_quantities; + std::vector> _fill_quantities; bool _is_iceberg = false; // when this is true, the subsequent show_qty change // will be applied to a new show qty @@ -89,15 +89,15 @@ struct IcebergInputBuilder { // since that show qty is locked in for a span of events. bool _show_qty_realized = false; - std::tuple _at_index(uint32_t i) const { + std::tuple _at_index(uint32_t i) const { if (i < _show_quantities.size()) return _show_quantities[i]; - return {0, MDP3Quantity(0)}; + return {0, Quantity(0)}; } }; struct IcebergFinder : IChannelObserver { - std::unordered_map result; + std::unordered_map result; IcebergFinder(); ~IcebergFinder(); @@ -106,7 +106,7 @@ struct IcebergFinder : IChannelObserver { void finit() override; void on_real_time_event(MDP3Event const &ev) override; - static std::unordered_map + static std::unordered_map find_all(const std::string &pcap); private: diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonFinder.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonFinder.cpp index db9c2282a..c5ef08155 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonFinder.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonFinder.cpp @@ -9,7 +9,7 @@ namespace bts::spartan::mdp3 { const InstrumentDefinition & -find_instr(DefinitionCollector &defs, MDP3SecurityID sec_id) { +find_instr(DefinitionCollector &defs, SecurityID sec_id) { auto it = defs.result.find(sec_id); bts_assert(it != defs.result.end()); return it->second; @@ -76,7 +76,7 @@ bool passes_exp_filter( case (bts::api::SecurityType::SECURITYTYPE_FUTURE): { auto now = TimeStamp::now(); bts_assert(instr.expiration().has_value()); - rv = (instr.expiration().value() - now).microseconds() <= thresh_us; + rv = (instr.expiration().value() - now).micros() <= thresh_us; break; } case (bts::api::SecurityType::SECURITYTYPE_SPREAD): @@ -145,7 +145,7 @@ void PolygonFinder::on_real_time_event(MDP3Event const &ev) { void PolygonFinder::finit() { me->fill_counter.finit(); me->def_collector.finit(); - std::unordered_map poly_universe; + std::unordered_map poly_universe; // add all securuties that passes the security filter (symbol, // exp withing n months and outrights being allowed or not) for (const auto &kv : me->def_collector.result) { @@ -174,7 +174,7 @@ void PolygonFinder::finit() { poly_universe[f.sec_id] = PolyInstrument{f.sec_id}; } // Now fill in the security legs - std::unordered_set all_legs; + std::unordered_set all_legs; for (auto &p : poly_universe) { auto &poly_instrument = p.second; auto it = me->def_collector.result.find(p.first); diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.cpp index 0a4e4859c..a779a86ee 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.cpp @@ -67,7 +67,7 @@ void single_pv_to_csv(std::ostream &out, const PolygonValuation &v) { // for each leg : sec_key, eid, side_used, bid_book, ask_book size_t max_n_legs = 5; for (size_t i = 0; i < max_n_legs; i++) { - MDP3SecurityID sid = MDP3SecurityID(0); + SecurityID sid = SecurityID(0); size_t eid = 0; std::string side_txt = "", bid_bk = "", ask_bk = ""; if (i < v.books_used.size()) { @@ -270,8 +270,8 @@ struct PolygonOpportunityFinder::PImpl { PolygonMap const &all_polygons; InstrumentMap const &imap; std::unordered_set active_polygons = {}; - std::unordered_map all_snapshots = {}; - std::unordered_map> dependencies = {}; + std::unordered_map all_snapshots = {}; + std::unordered_map> dependencies = {}; size_t last_opp_eid = 0; size_t running_opp_id = 0; }; @@ -300,7 +300,7 @@ double eval_poly(Polygon const &poly, Pricer const &price) { for (auto &l : poly.parts) { auto mkt_side = securities::other_side(side_from_ratio(l.ratio)); auto cash_price = - price(l.sec_id, MDP3Quantity{std::abs(l.ratio)}, mkt_side); + price(l.sec_id, Quantity{std::abs(l.ratio)}, mkt_side); value += -l.ratio * cash_price; } return value; @@ -319,7 +319,7 @@ void PolygonOpportunityFinder::on_real_time_event(MDP3Event const &ev) { } // gets the direct price in cash terms for the a sec, side auto direct_pricer = - [this](MDP3SecurityID sec_id, MDP3Quantity, api::Side side) { + [this](SecurityID sec_id, Quantity, api::Side side) { auto &mkt = me->all_snapshots[sec_id].snapshot->book(side)[0]; if (mkt.quantity.value() > 0) return get_sec(sec_id).to_cash(mkt.price.price()); @@ -328,7 +328,7 @@ void PolygonOpportunityFinder::on_real_time_event(MDP3Event const &ev) { }; auto merged_pricer = - [this](MDP3SecurityID sec_id, MDP3Quantity, api::Side side) { + [this](SecurityID sec_id, Quantity, api::Side side) { auto mkt = me->all_snapshots[sec_id].snapshot->merged_book(side)[0]; if (mkt.quantity.value() > 0) return get_sec(sec_id).to_cash(mkt.price.price()); @@ -337,10 +337,10 @@ void PolygonOpportunityFinder::on_real_time_event(MDP3Event const &ev) { }; auto compute_polygon_book = [](PolygonValuation &pv) { - std::vector> legs; + std::vector> legs; size_t i = 0; for (const auto &ip : pv.polygon.parts) { - auto leg_qty = MDP3Quantity(ip.ratio); + auto leg_qty = Quantity(ip.ratio); BookReference &bk_ref = pv.books_used[i++]; legs.push_back(std::make_tuple( leg_qty, md::IntPrice(), bk_ref.bid_book, bk_ref.ask_book)); @@ -456,7 +456,7 @@ Polygon const &PolygonOpportunityFinder::get_poly(size_t id) { } InstrumentDefinition const & -PolygonOpportunityFinder::get_sec(MDP3SecurityID id) { +PolygonOpportunityFinder::get_sec(SecurityID id) { auto it = me->all_snapshots.find(id); bts_assert(it != me->all_snapshots.end()); return it->second.snapshot->definition(); diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.h index e55ff4018..00b83d397 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/PolygonOpportunityFinder.h @@ -9,7 +9,7 @@ namespace bts::spartan::mdp3 { struct BookReference { - MDP3SecurityID sid; + SecurityID sid; api::Side side; size_t eid; Book bid_book, ask_book; @@ -29,10 +29,10 @@ struct PolygonValuation { size_t min_n_orders = std::numeric_limits::max(); double direct_value = 0; - MDP3Quantity direct_quantity = MDP3Quantity{0}; + Quantity direct_quantity = Quantity{0}; double merged_value = {0}; - MDP3Quantity merged_quantity = MDP3Quantity{0}; + Quantity merged_quantity = Quantity{0}; std::vector books_used = {}; Book poly_bid_book = Book(), poly_ask_book = Book(); @@ -51,10 +51,10 @@ struct PolygonOpportunity { size_t min_n_orders = std::numeric_limits::max(); double direct_value = 0; - MDP3Quantity direct_quantity = MDP3Quantity{0}; + Quantity direct_quantity = Quantity{0}; double merged_value = {0}; - MDP3Quantity merged_quantity = MDP3Quantity{0}; + Quantity merged_quantity = Quantity{0}; }; std::vector @@ -84,7 +84,7 @@ struct PolygonOpportunityFinder : IChannelObserver { void on_real_time_event(MDP3Event const &ev) override; Polygon const &get_poly(size_t); - InstrumentDefinition const &get_sec(MDP3SecurityID); + InstrumentDefinition const &get_sec(SecurityID); struct PImpl; struct SnapshotRec; std::unique_ptr me; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.cpp index 4dd456a80..369ac404d 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.cpp @@ -7,22 +7,22 @@ namespace bts::spartan::mdp3 { -using _LegDef = std::tuple; +using _LegDef = std::tuple; using SyntheticDefinitionMap = - std::unordered_map>; + std::unordered_map>; using ReverseLegMap = - std::unordered_map>; + std::unordered_map>; using BookMap = std:: - unordered_map>; + unordered_map>; // leg sec id, event id (last change), leg qty, leg price mult, bids, asks using LegBookVec = std::vector>; @@ -39,7 +39,7 @@ build_reverse_leg_map(const SyntheticDefinitionMap &synthetic_defs) { ReverseLegMap rlm; for (const auto &sd_p : synthetic_defs) { for (auto leg_tup : sd_p.second) { - rlm.emplace(std::get<0>(leg_tup), std::unordered_set()) + rlm.emplace(std::get<0>(leg_tup), std::unordered_set()) .first->second.insert(sd_p.first); } } @@ -47,7 +47,7 @@ build_reverse_leg_map(const SyntheticDefinitionMap &synthetic_defs) { } const std::vector<_LegDef> & -get_legs(MDP3SecurityID synth_id, const SyntheticDefinitionMap &synth_defs) { +get_legs(SecurityID synth_id, const SyntheticDefinitionMap &synth_defs) { auto it = synth_defs.find(synth_id); bts_assert(it != synth_defs.end()); return it->second; @@ -73,8 +73,8 @@ void update_books( } } -const std::unordered_set * -synthetic_owners(MDP3SecurityID leg_id, const ReverseLegMap &reverse_legs) { +const std::unordered_set * +synthetic_owners(SecurityID leg_id, const ReverseLegMap &reverse_legs) { auto it = reverse_legs.find(leg_id); if (it == reverse_legs.end()) return nullptr; @@ -82,9 +82,9 @@ synthetic_owners(MDP3SecurityID leg_id, const ReverseLegMap &reverse_legs) { } template -std::unordered_set +std::unordered_set synthetic_owners(TIter first, TIter last, const ReverseLegMap &reverse_legs) { - std::unordered_set all_owners; + std::unordered_set all_owners; while (first != last) { const auto *leg_owners = synthetic_owners(*first, reverse_legs); if (leg_owners != nullptr) { @@ -98,7 +98,7 @@ synthetic_owners(TIter first, TIter last, const ReverseLegMap &reverse_legs) { // returns tuple of bids, asks std::tuple -get_book_tuple(MDP3SecurityID id, const BookMap &books) { +get_book_tuple(SecurityID id, const BookMap &books) { auto bk_it = books.find(id); if (bk_it == books.end()) return {0, SmallBook(), SmallBook()}; @@ -117,8 +117,8 @@ get_leg_books(const std::vector<_LegDef> &leg_defs, const BookMap &books) { SyntheticMBPUpdate::SyntheticMBPUpdate() {} SyntheticMBPUpdate::SyntheticMBPUpdate( - MDP3SecurityID synthetic_id, - std::map leg_book_eids, + SecurityID synthetic_id, + std::map leg_book_eids, SmallBook bids, SmallBook asks) : synthetic_id(synthetic_id), leg_book_eids(leg_book_eids), bids(bids), @@ -178,7 +178,7 @@ void on_securities_changed( // ranges::views::transform(first, last, [](const InstrumentSnapshot* s) { // return s->security_id(); }); // oh well, just map the sec ids to a vector for now. - std::vector affected_sec_ids; + std::vector affected_sec_ids; while (first != last) { affected_sec_ids.emplace_back((*first)->security_id()); first++; @@ -192,9 +192,9 @@ void on_securities_changed( const auto &legs = get_legs(id, synth_defs); auto leg_books = get_leg_books(legs, books); SmallBook bids, asks; - std::vector> + std::vector> leg_books_no_eid; - std::map leg_book_eid_map; + std::map leg_book_eid_map; for (auto [eid, lsid, lqty, lprice, lbids, lasks] : leg_books) { // seems like there should be a clever way to remove 1 element from a // tuple. oh well, for now, this will have to do (drop element 0: event @@ -228,4 +228,4 @@ const std::map> & SyntheticBookRecorder::result() const { return _me->synthetic_book_history(); } -} // namespace bts::spartan::mdp3 \ No newline at end of file +} // namespace bts::spartan::mdp3 diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.h b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.h index b1b60e6ea..565b5119f 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.h +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/queries/SyntheticBookRecorder.h @@ -14,25 +14,25 @@ namespace bts::spartan::mdp3 { struct SyntheticMBPUpdate { SyntheticMBPUpdate(); SyntheticMBPUpdate( - MDP3SecurityID synthetic_id, - std::map leg_book_eids, + SecurityID synthetic_id, + std::map leg_book_eids, SmallBook bids, SmallBook asks); - MDP3SecurityID synthetic_id; + SecurityID synthetic_id; // Note: a map is used (instead of other containers like // unordered_map/vector etc.) to ensure a consistent order of legs, // and to reduce the risk of misuse that might accompany using a vector (like // accidentally adding a duplicate entry for one of the legs) - std::map leg_book_eids; + std::map leg_book_eids; SmallBook bids; SmallBook asks; }; struct SyntheticBookRecorder : IChannelObserver { SyntheticBookRecorder(std::unordered_map< - MDP3SecurityID, - std::vector>> + SecurityID, + std::vector>> synthetic_def); ~SyntheticBookRecorder(); void on_recovery_complete(InitialSnapshot const &snap) override; diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/synthetic_book_tests.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/synthetic_book_tests.cpp index f7cd955bb..a361d2994 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/synthetic_book_tests.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/synthetic_book_tests.cpp @@ -11,12 +11,12 @@ namespace bts::spartan::mdp3::tests { using LegMarkets = - std::vector>; + std::vector>; inline md::IntPrice int_price(int value) { return md::IntPrice(value, 0); } inline SmallBookLevel book_level(int price, int qty) { - return SmallBookLevel(int_price(price), MDP3Quantity(qty)); + return SmallBookLevel(int_price(price), Quantity(qty)); } // Determines whether or not the book is sorted by price. @@ -42,10 +42,10 @@ is_sorted(const SmallBook &book, api::Side side = api::Side::SIDE_UNDEFINED) { } // Computes the cost of the specified qty at the top price(s) in the book. -md::IntPrice qty_cost(const SmallBook &book, MDP3Quantity qty) { +md::IntPrice qty_cost(const SmallBook &book, Quantity qty) { // A qty of 0 is presumably a mistake on the caller's part, // and thus grounds to fail the test. - REQUIRE(qty != 0); + REQUIRE(qty.value() != 0); // Passing an empty book, however, is plausible, as synthetic leg(s) // with empty books are part of some of the test scenarios. if (book.empty()) @@ -152,7 +152,7 @@ void expected_synth_book(LegMarkets legs, SmallBook &dest) { } for (const auto &[qty, price_mult, bk] : legs) { bts_assert(price_mult.is_nan()); - REQUIRE(book_utils::volume(bk) >= limiting_factor * abs(qty)); + REQUIRE((book_utils::volume(bk) >= limiting_factor * abs(qty))); } auto unit_cost = md::INT_ZERO; @@ -161,7 +161,7 @@ void expected_synth_book(LegMarkets legs, SmallBook &dest) { unit_cost += qty_cost(bk, qty); REQUIRE(book_utils::remove_qty(bk, qty * limiting_factor)); } - dest.emplace_back(unit_cost, MDP3Quantity(limiting_factor)); + dest.emplace_back(unit_cost, Quantity(limiting_factor)); } } @@ -261,30 +261,30 @@ void five_legged(std::vector &synths) { { synths.emplace_back(); auto &legs = synths.back(); - legs.emplace_back(MDP3Quantity(-2), md::INT_NAN, leg1); - legs.emplace_back(MDP3Quantity(1), md::INT_NAN, leg2); - legs.emplace_back(MDP3Quantity(2), md::INT_NAN, leg3); - legs.emplace_back(MDP3Quantity(-1), md::INT_NAN, leg4); - legs.emplace_back(MDP3Quantity(1), md::INT_NAN, leg5); + legs.emplace_back(Quantity(-2), md::INT_NAN, leg1); + legs.emplace_back(Quantity(1), md::INT_NAN, leg2); + legs.emplace_back(Quantity(2), md::INT_NAN, leg3); + legs.emplace_back(Quantity(-1), md::INT_NAN, leg4); + legs.emplace_back(Quantity(1), md::INT_NAN, leg5); } { synths.emplace_back(); auto &legs = synths.back(); - legs.emplace_back(MDP3Quantity(-2), md::INT_NAN, leg1); - legs.emplace_back(MDP3Quantity(1), md::INT_NAN, leg2); - legs.emplace_back(MDP3Quantity(7), md::INT_NAN, leg3); - legs.emplace_back(MDP3Quantity(-1), md::INT_NAN, leg4); - legs.emplace_back(MDP3Quantity(1), md::INT_NAN, leg5); + legs.emplace_back(Quantity(-2), md::INT_NAN, leg1); + legs.emplace_back(Quantity(1), md::INT_NAN, leg2); + legs.emplace_back(Quantity(7), md::INT_NAN, leg3); + legs.emplace_back(Quantity(-1), md::INT_NAN, leg4); + legs.emplace_back(Quantity(1), md::INT_NAN, leg5); } { // sneak an empty book in there. synths.emplace_back(); auto &legs = synths.back(); - legs.emplace_back(MDP3Quantity(-2), md::INT_NAN, leg1); - legs.emplace_back(MDP3Quantity(1), md::INT_NAN, leg2); - legs.emplace_back(MDP3Quantity(7), md::INT_NAN, leg3); - legs.emplace_back(MDP3Quantity(-1), md::INT_NAN, SmallBook()); - legs.emplace_back(MDP3Quantity(1), md::INT_NAN, leg5); + legs.emplace_back(Quantity(-2), md::INT_NAN, leg1); + legs.emplace_back(Quantity(1), md::INT_NAN, leg2); + legs.emplace_back(Quantity(7), md::INT_NAN, leg3); + legs.emplace_back(Quantity(-1), md::INT_NAN, SmallBook()); + legs.emplace_back(Quantity(1), md::INT_NAN, leg5); } } @@ -307,21 +307,21 @@ void two_legged(std::vector &synths) { // * a negative quantity is sold to the bid market, // so its price levels are expected to be in descending order. synths.emplace_back(); - synths.back().emplace_back(MDP3Quantity(i), md::INT_NAN, leg1_vars[j]); + synths.back().emplace_back(Quantity(i), md::INT_NAN, leg1_vars[j]); synths.back().emplace_back( - MDP3Quantity(-i), md::INT_NAN, leg2_vars[j]); + Quantity(-i), md::INT_NAN, leg2_vars[j]); synths.emplace_back(); synths.back().emplace_back( - MDP3Quantity(2 * i - 1), md::INT_NAN, leg1_vars[j]); + Quantity(2 * i - 1), md::INT_NAN, leg1_vars[j]); synths.back().emplace_back( - MDP3Quantity(-(3 * i + 1)), md::INT_NAN, leg2_vars[j]); + Quantity(-(3 * i + 1)), md::INT_NAN, leg2_vars[j]); synths.emplace_back(); synths.back().emplace_back( - MDP3Quantity(3 * i + 1), md::INT_NAN, leg1_vars[j]); + Quantity(3 * i + 1), md::INT_NAN, leg1_vars[j]); synths.back().emplace_back( - MDP3Quantity(-(2 * i - 1)), md::INT_NAN, leg2_vars[j]); + Quantity(-(2 * i - 1)), md::INT_NAN, leg2_vars[j]); } } } @@ -340,19 +340,19 @@ void one_legged(std::vector &synths) { auto append_variations = [&](const SmallBook &b) { synths.emplace_back(); - synths.back().emplace_back(MDP3Quantity(i), md::INT_NAN, b); + synths.back().emplace_back(Quantity(i), md::INT_NAN, b); // synths.emplace_back(); synths.back().emplace_back( - MDP3Quantity(i), md::INT_NAN, flip_book(b, false, true)); + Quantity(i), md::INT_NAN, flip_book(b, false, true)); // synths.emplace_back(); synths.back().emplace_back( - MDP3Quantity(-i), md::INT_NAN, flip_book(b, true, false)); + Quantity(-i), md::INT_NAN, flip_book(b, true, false)); // synths.emplace_back(); synths.back().emplace_back( - MDP3Quantity(-i), md::INT_NAN, flip_book(b, true, true)); + Quantity(-i), md::INT_NAN, flip_book(b, true, true)); }; append_variations(leg1); append_variations(leg2); @@ -365,8 +365,8 @@ INIT_VECTOR_OVERLOAD(two_legged) INIT_VECTOR_OVERLOAD(one_legged) } // namespace synth_samples -MDP3Quantity expected_volume(const LegMarkets &synth) { - return MDP3Quantity( +Quantity expected_volume(const LegMarkets &synth) { + return Quantity( ranges::min(ranges::views::transform(synth, [](const auto &l) { return book_utils::volume(std::get<2>(l)).value() / abs(std::get<0>(l)).value(); @@ -426,4 +426,4 @@ TEST_CASE( REQUIRE(synth_book.empty()); } } -} // namespace bts::spartan::mdp3::tests \ No newline at end of file +} // namespace bts::spartan::mdp3::tests diff --git a/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/test_polygon_finder.cpp b/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/test_polygon_finder.cpp index 0b90d5a0b..8c6fa1d78 100644 --- a/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/test_polygon_finder.cpp +++ b/src/server/sparkd/cmds/spartan/md/mdp3/utils/tests/test_polygon_finder.cpp @@ -5,8 +5,8 @@ namespace bts::spartan::mdp3 { TEST_CASE("PolygonTests", "[gen_poly]") { SECTION("a-b,-a,b") { - InstrumentPart la{mdp3::MDP3SecurityID{1}, 1}; - InstrumentPart lb{mdp3::MDP3SecurityID{2}, -1}; + InstrumentPart la{mdp3::SecurityID{1}, 1}; + InstrumentPart lb{mdp3::SecurityID{2}, -1}; PolyInstrument a{la.sec_id}; a.parts.push_back(la); @@ -14,7 +14,7 @@ TEST_CASE("PolygonTests", "[gen_poly]") { PolyInstrument b{lb.sec_id}; b.parts.push_back(InstrumentPart{lb.sec_id, 1}); - PolyInstrument a_b{mdp3::MDP3SecurityID{3}}; + PolyInstrument a_b{mdp3::SecurityID{3}}; a_b.parts.push_back(la); a_b.parts.push_back(lb); auto universe = {a, b, a_b}; @@ -24,20 +24,20 @@ TEST_CASE("PolygonTests", "[gen_poly]") { } SECTION("BF:V0-X0-Z0") { - auto x = make_outright(mdp3::MDP3SecurityID{1}); - auto v = make_outright(mdp3::MDP3SecurityID{2}); - auto z = make_outright(mdp3::MDP3SecurityID{3}); + auto x = make_outright(mdp3::SecurityID{1}); + auto v = make_outright(mdp3::SecurityID{2}); + auto z = make_outright(mdp3::SecurityID{3}); auto xz = make_spread( - mdp3::MDP3SecurityID{4}, + mdp3::SecurityID{4}, {InstrumentPart{x.sec_id, 1}, InstrumentPart{z.sec_id, -1}}); auto vx = make_spread( - mdp3::MDP3SecurityID{5}, + mdp3::SecurityID{5}, {InstrumentPart{v.sec_id, 1}, InstrumentPart{x.sec_id, -1}}); auto bf = make_spread( - mdp3::MDP3SecurityID{6}, + mdp3::SecurityID{6}, {InstrumentPart{v.sec_id, 1}, InstrumentPart{x.sec_id, -2}, InstrumentPart{z.sec_id, 1}}); @@ -49,182 +49,182 @@ TEST_CASE("PolygonTests", "[gen_poly]") { } struct InputLeg { - mdp3::MDP3SecurityID sec_id; - mdp3::MDP3SecurityID leg = mdp3::MDP3SecurityID{0}; + mdp3::SecurityID sec_id; + mdp3::SecurityID leg = mdp3::SecurityID{0}; int ratio = 0; }; - std::map sec_name = { - {mdp3::MDP3SecurityID{85834}, "GCV0-GCG1"}, - {mdp3::MDP3SecurityID{11598}, "SILZ0-SILK1"}, - {mdp3::MDP3SecurityID{5029}, "HGH1-HGK1"}, - {mdp3::MDP3SecurityID{12732}, "SIN1-SIU1"}, - {mdp3::MDP3SecurityID{3468}, "HGK1"}, - {mdp3::MDP3SecurityID{1406}, "GCV1"}, - {mdp3::MDP3SecurityID{188775}, "SIZ0"}, - {mdp3::MDP3SecurityID{2733}, "GCX0"}, - {mdp3::MDP3SecurityID{51659}, "GCZ1"}, - {mdp3::MDP3SecurityID{17318}, "GCV0"}, - {mdp3::MDP3SecurityID{13775}, "QOV0"}, - {mdp3::MDP3SecurityID{20929}, "HGX0"}, - {mdp3::MDP3SecurityID{7378}, "HGK1-HGN1"}, - {mdp3::MDP3SecurityID{5936}, "MGCZ0-MGCJ1"}, - {mdp3::MDP3SecurityID{23759}, "GCZ0-GCZ1"}, - {mdp3::MDP3SecurityID{37283}, "GCZ0-GCM1"}, - {mdp3::MDP3SecurityID{47843}, "SIZ0-SIH1"}, - {mdp3::MDP3SecurityID{17853}, "SILV0-SILZ0"}, - {mdp3::MDP3SecurityID{85863}, "GCZ0-GCG1"}, - {mdp3::MDP3SecurityID{14587}, "GCG1-GCJ1"}, - {mdp3::MDP3SecurityID{89089}, "SIZ0-SIK1"}, - {mdp3::MDP3SecurityID{53777}, "GCV0-GCZ0"}, - {mdp3::MDP3SecurityID{89321}, "SIK1-SIN1"}, - {mdp3::MDP3SecurityID{10136}, "QOV0-QOZ0"}, - {mdp3::MDP3SecurityID{24376}, "SIZ1"}, - {mdp3::MDP3SecurityID{19224}, "MGCV0-MGCZ0"}, - {mdp3::MDP3SecurityID{62684}, "SIH1"}, - {mdp3::MDP3SecurityID{543}, "SILK1"}, - {mdp3::MDP3SecurityID{771}, "SIV0"}, - {mdp3::MDP3SecurityID{4353}, "HGZ0-HGH1"}, - {mdp3::MDP3SecurityID{422}, "GCZ0"}, - {mdp3::MDP3SecurityID{23860}, "QCZ0"}, - {mdp3::MDP3SecurityID{33889}, "SILZ0-SILH1"}, - {mdp3::MDP3SecurityID{14211}, "GCX0-GCZ0"}, - {mdp3::MDP3SecurityID{6181}, "HGN1"}, - {mdp3::MDP3SecurityID{14539}, "SIU1-SIZ1"}, - {mdp3::MDP3SecurityID{262483}, "HGH1"}, - {mdp3::MDP3SecurityID{224}, "MGCJ1"}, - {mdp3::MDP3SecurityID{1016}, "MGCZ0"}, - {mdp3::MDP3SecurityID{21779}, "HGX0-HGZ0"}, - {mdp3::MDP3SecurityID{85573}, "MGCZ0-MGCG1"}, - {mdp3::MDP3SecurityID{6466}, "GCG1"}, - {mdp3::MDP3SecurityID{39312}, "SILZ0"}, - {mdp3::MDP3SecurityID{220768}, "HGZ0"}, - {mdp3::MDP3SecurityID{14945}, "GCZ0-GCJ1"}, - {mdp3::MDP3SecurityID{30106}, "MGCQ1"}, - {mdp3::MDP3SecurityID{39581}, "SGCZ0"}, - {mdp3::MDP3SecurityID{31215}, "SIV0-SIZ0"}, - {mdp3::MDP3SecurityID{224307}, "SIZ0-SIZ1"}, - {mdp3::MDP3SecurityID{3067}, "GCJ1"}, - {mdp3::MDP3SecurityID{39415}, "SGUZ0"}, - {mdp3::MDP3SecurityID{63676}, "SIK1"}, - {mdp3::MDP3SecurityID{4221}, "SILH1"}, - {mdp3::MDP3SecurityID{78321}, "MGCZ0-MGCM1"}, - {mdp3::MDP3SecurityID{40584}, "QIZ0"}, - {mdp3::MDP3SecurityID{115482}, "MGCV0"}, - {mdp3::MDP3SecurityID{38472}, "QOZ0"}, - {mdp3::MDP3SecurityID{32490}, "SIN1"}, - {mdp3::MDP3SecurityID{89318}, "SIH1-SIK1"}, - {mdp3::MDP3SecurityID{100440}, "GCM1"}, - {mdp3::MDP3SecurityID{81409}, "MGCM1"}, - {mdp3::MDP3SecurityID{28092}, "SIU1"}, - {mdp3::MDP3SecurityID{42317}, "MGCG1"}, - {mdp3::MDP3SecurityID{7026}, "SIZ0-SIN1"}, - {mdp3::MDP3SecurityID{62679}, "QIH1"}, - {mdp3::MDP3SecurityID{23149}, "MGCZ0-MGCQ1"}, - {mdp3::MDP3SecurityID{840}, "SILV0"}, + std::map sec_name = { + {mdp3::SecurityID{85834}, "GCV0-GCG1"}, + {mdp3::SecurityID{11598}, "SILZ0-SILK1"}, + {mdp3::SecurityID{5029}, "HGH1-HGK1"}, + {mdp3::SecurityID{12732}, "SIN1-SIU1"}, + {mdp3::SecurityID{3468}, "HGK1"}, + {mdp3::SecurityID{1406}, "GCV1"}, + {mdp3::SecurityID{188775}, "SIZ0"}, + {mdp3::SecurityID{2733}, "GCX0"}, + {mdp3::SecurityID{51659}, "GCZ1"}, + {mdp3::SecurityID{17318}, "GCV0"}, + {mdp3::SecurityID{13775}, "QOV0"}, + {mdp3::SecurityID{20929}, "HGX0"}, + {mdp3::SecurityID{7378}, "HGK1-HGN1"}, + {mdp3::SecurityID{5936}, "MGCZ0-MGCJ1"}, + {mdp3::SecurityID{23759}, "GCZ0-GCZ1"}, + {mdp3::SecurityID{37283}, "GCZ0-GCM1"}, + {mdp3::SecurityID{47843}, "SIZ0-SIH1"}, + {mdp3::SecurityID{17853}, "SILV0-SILZ0"}, + {mdp3::SecurityID{85863}, "GCZ0-GCG1"}, + {mdp3::SecurityID{14587}, "GCG1-GCJ1"}, + {mdp3::SecurityID{89089}, "SIZ0-SIK1"}, + {mdp3::SecurityID{53777}, "GCV0-GCZ0"}, + {mdp3::SecurityID{89321}, "SIK1-SIN1"}, + {mdp3::SecurityID{10136}, "QOV0-QOZ0"}, + {mdp3::SecurityID{24376}, "SIZ1"}, + {mdp3::SecurityID{19224}, "MGCV0-MGCZ0"}, + {mdp3::SecurityID{62684}, "SIH1"}, + {mdp3::SecurityID{543}, "SILK1"}, + {mdp3::SecurityID{771}, "SIV0"}, + {mdp3::SecurityID{4353}, "HGZ0-HGH1"}, + {mdp3::SecurityID{422}, "GCZ0"}, + {mdp3::SecurityID{23860}, "QCZ0"}, + {mdp3::SecurityID{33889}, "SILZ0-SILH1"}, + {mdp3::SecurityID{14211}, "GCX0-GCZ0"}, + {mdp3::SecurityID{6181}, "HGN1"}, + {mdp3::SecurityID{14539}, "SIU1-SIZ1"}, + {mdp3::SecurityID{262483}, "HGH1"}, + {mdp3::SecurityID{224}, "MGCJ1"}, + {mdp3::SecurityID{1016}, "MGCZ0"}, + {mdp3::SecurityID{21779}, "HGX0-HGZ0"}, + {mdp3::SecurityID{85573}, "MGCZ0-MGCG1"}, + {mdp3::SecurityID{6466}, "GCG1"}, + {mdp3::SecurityID{39312}, "SILZ0"}, + {mdp3::SecurityID{220768}, "HGZ0"}, + {mdp3::SecurityID{14945}, "GCZ0-GCJ1"}, + {mdp3::SecurityID{30106}, "MGCQ1"}, + {mdp3::SecurityID{39581}, "SGCZ0"}, + {mdp3::SecurityID{31215}, "SIV0-SIZ0"}, + {mdp3::SecurityID{224307}, "SIZ0-SIZ1"}, + {mdp3::SecurityID{3067}, "GCJ1"}, + {mdp3::SecurityID{39415}, "SGUZ0"}, + {mdp3::SecurityID{63676}, "SIK1"}, + {mdp3::SecurityID{4221}, "SILH1"}, + {mdp3::SecurityID{78321}, "MGCZ0-MGCM1"}, + {mdp3::SecurityID{40584}, "QIZ0"}, + {mdp3::SecurityID{115482}, "MGCV0"}, + {mdp3::SecurityID{38472}, "QOZ0"}, + {mdp3::SecurityID{32490}, "SIN1"}, + {mdp3::SecurityID{89318}, "SIH1-SIK1"}, + {mdp3::SecurityID{100440}, "GCM1"}, + {mdp3::SecurityID{81409}, "MGCM1"}, + {mdp3::SecurityID{28092}, "SIU1"}, + {mdp3::SecurityID{42317}, "MGCG1"}, + {mdp3::SecurityID{7026}, "SIZ0-SIN1"}, + {mdp3::SecurityID{62679}, "QIH1"}, + {mdp3::SecurityID{23149}, "MGCZ0-MGCQ1"}, + {mdp3::SecurityID{840}, "SILV0"}, }; std::vector legs{ - {mdp3::MDP3SecurityID{224}}, - {mdp3::MDP3SecurityID{422}}, - {mdp3::MDP3SecurityID{543}}, - {mdp3::MDP3SecurityID{771}}, - {mdp3::MDP3SecurityID{840}}, - {mdp3::MDP3SecurityID{1016}}, - {mdp3::MDP3SecurityID{1406}}, - {mdp3::MDP3SecurityID{2733}}, - {mdp3::MDP3SecurityID{3067}}, - {mdp3::MDP3SecurityID{3468}}, - {mdp3::MDP3SecurityID{4221}}, - {mdp3::MDP3SecurityID{6181}}, - {mdp3::MDP3SecurityID{6466}}, - {mdp3::MDP3SecurityID{13775}}, - {mdp3::MDP3SecurityID{17318}}, - {mdp3::MDP3SecurityID{20929}}, - {mdp3::MDP3SecurityID{23860}}, - {mdp3::MDP3SecurityID{24376}}, - {mdp3::MDP3SecurityID{28092}}, - {mdp3::MDP3SecurityID{30106}}, - {mdp3::MDP3SecurityID{32490}}, - {mdp3::MDP3SecurityID{38472}}, - {mdp3::MDP3SecurityID{39312}}, - {mdp3::MDP3SecurityID{39415}}, - {mdp3::MDP3SecurityID{39581}}, - {mdp3::MDP3SecurityID{40584}}, - {mdp3::MDP3SecurityID{42317}}, - {mdp3::MDP3SecurityID{51659}}, - {mdp3::MDP3SecurityID{62679}}, - {mdp3::MDP3SecurityID{62684}}, - {mdp3::MDP3SecurityID{63676}}, - {mdp3::MDP3SecurityID{81409}}, - {mdp3::MDP3SecurityID{100440}}, - {mdp3::MDP3SecurityID{115482}}, - {mdp3::MDP3SecurityID{188775}}, - {mdp3::MDP3SecurityID{220768}}, - {mdp3::MDP3SecurityID{262483}}, - {mdp3::MDP3SecurityID{5936}, mdp3::MDP3SecurityID{224}, -1}, - {mdp3::MDP3SecurityID{14211}, mdp3::MDP3SecurityID{422}, -1}, - {mdp3::MDP3SecurityID{14945}, mdp3::MDP3SecurityID{422}, 1}, - {mdp3::MDP3SecurityID{23759}, mdp3::MDP3SecurityID{422}, 1}, - {mdp3::MDP3SecurityID{37283}, mdp3::MDP3SecurityID{422}, 1}, - {mdp3::MDP3SecurityID{53777}, mdp3::MDP3SecurityID{422}, -1}, - {mdp3::MDP3SecurityID{85863}, mdp3::MDP3SecurityID{422}, 1}, - {mdp3::MDP3SecurityID{11598}, mdp3::MDP3SecurityID{543}, -1}, - {mdp3::MDP3SecurityID{31215}, mdp3::MDP3SecurityID{771}, 1}, - {mdp3::MDP3SecurityID{17853}, mdp3::MDP3SecurityID{840}, 1}, - {mdp3::MDP3SecurityID{5936}, mdp3::MDP3SecurityID{1016}, 1}, - {mdp3::MDP3SecurityID{19224}, mdp3::MDP3SecurityID{1016}, -1}, - {mdp3::MDP3SecurityID{23149}, mdp3::MDP3SecurityID{1016}, 1}, - {mdp3::MDP3SecurityID{78321}, mdp3::MDP3SecurityID{1016}, 1}, - {mdp3::MDP3SecurityID{85573}, mdp3::MDP3SecurityID{1016}, 1}, - {mdp3::MDP3SecurityID{14211}, mdp3::MDP3SecurityID{2733}, 1}, - {mdp3::MDP3SecurityID{14587}, mdp3::MDP3SecurityID{3067}, -1}, - {mdp3::MDP3SecurityID{14945}, mdp3::MDP3SecurityID{3067}, -1}, - {mdp3::MDP3SecurityID{5029}, mdp3::MDP3SecurityID{3468}, -1}, - {mdp3::MDP3SecurityID{7378}, mdp3::MDP3SecurityID{3468}, 1}, - {mdp3::MDP3SecurityID{33889}, mdp3::MDP3SecurityID{4221}, -1}, - {mdp3::MDP3SecurityID{7378}, mdp3::MDP3SecurityID{6181}, -1}, - {mdp3::MDP3SecurityID{14587}, mdp3::MDP3SecurityID{6466}, 1}, - {mdp3::MDP3SecurityID{85834}, mdp3::MDP3SecurityID{6466}, -1}, - {mdp3::MDP3SecurityID{85863}, mdp3::MDP3SecurityID{6466}, -1}, - {mdp3::MDP3SecurityID{10136}, mdp3::MDP3SecurityID{13775}, 1}, - {mdp3::MDP3SecurityID{53777}, mdp3::MDP3SecurityID{17318}, 1}, - {mdp3::MDP3SecurityID{85834}, mdp3::MDP3SecurityID{17318}, 1}, - {mdp3::MDP3SecurityID{21779}, mdp3::MDP3SecurityID{20929}, 1}, - {mdp3::MDP3SecurityID{14539}, mdp3::MDP3SecurityID{24376}, -1}, - {mdp3::MDP3SecurityID{224307}, mdp3::MDP3SecurityID{24376}, -1}, - {mdp3::MDP3SecurityID{12732}, mdp3::MDP3SecurityID{28092}, -1}, - {mdp3::MDP3SecurityID{14539}, mdp3::MDP3SecurityID{28092}, 1}, - {mdp3::MDP3SecurityID{23149}, mdp3::MDP3SecurityID{30106}, -1}, - {mdp3::MDP3SecurityID{7026}, mdp3::MDP3SecurityID{32490}, -1}, - {mdp3::MDP3SecurityID{12732}, mdp3::MDP3SecurityID{32490}, 1}, - {mdp3::MDP3SecurityID{89321}, mdp3::MDP3SecurityID{32490}, -1}, - {mdp3::MDP3SecurityID{10136}, mdp3::MDP3SecurityID{38472}, -1}, - {mdp3::MDP3SecurityID{11598}, mdp3::MDP3SecurityID{39312}, 1}, - {mdp3::MDP3SecurityID{17853}, mdp3::MDP3SecurityID{39312}, -1}, - {mdp3::MDP3SecurityID{33889}, mdp3::MDP3SecurityID{39312}, 1}, - {mdp3::MDP3SecurityID{85573}, mdp3::MDP3SecurityID{42317}, -1}, - {mdp3::MDP3SecurityID{23759}, mdp3::MDP3SecurityID{51659}, -1}, - {mdp3::MDP3SecurityID{47843}, mdp3::MDP3SecurityID{62684}, -1}, - {mdp3::MDP3SecurityID{89318}, mdp3::MDP3SecurityID{62684}, 1}, - {mdp3::MDP3SecurityID{89089}, mdp3::MDP3SecurityID{63676}, -1}, - {mdp3::MDP3SecurityID{89318}, mdp3::MDP3SecurityID{63676}, -1}, - {mdp3::MDP3SecurityID{89321}, mdp3::MDP3SecurityID{63676}, 1}, - {mdp3::MDP3SecurityID{78321}, mdp3::MDP3SecurityID{81409}, -1}, - {mdp3::MDP3SecurityID{37283}, mdp3::MDP3SecurityID{100440}, -1}, - {mdp3::MDP3SecurityID{19224}, mdp3::MDP3SecurityID{115482}, 1}, - {mdp3::MDP3SecurityID{7026}, mdp3::MDP3SecurityID{188775}, 1}, - {mdp3::MDP3SecurityID{31215}, mdp3::MDP3SecurityID{188775}, -1}, - {mdp3::MDP3SecurityID{47843}, mdp3::MDP3SecurityID{188775}, 1}, - {mdp3::MDP3SecurityID{89089}, mdp3::MDP3SecurityID{188775}, 1}, - {mdp3::MDP3SecurityID{224307}, mdp3::MDP3SecurityID{188775}, 1}, - {mdp3::MDP3SecurityID{4353}, mdp3::MDP3SecurityID{220768}, 1}, - {mdp3::MDP3SecurityID{21779}, mdp3::MDP3SecurityID{220768}, -1}, - {mdp3::MDP3SecurityID{4353}, mdp3::MDP3SecurityID{262483}, -1}, - {mdp3::MDP3SecurityID{5029}, mdp3::MDP3SecurityID{262483}, 1}, + {mdp3::SecurityID{224}}, + {mdp3::SecurityID{422}}, + {mdp3::SecurityID{543}}, + {mdp3::SecurityID{771}}, + {mdp3::SecurityID{840}}, + {mdp3::SecurityID{1016}}, + {mdp3::SecurityID{1406}}, + {mdp3::SecurityID{2733}}, + {mdp3::SecurityID{3067}}, + {mdp3::SecurityID{3468}}, + {mdp3::SecurityID{4221}}, + {mdp3::SecurityID{6181}}, + {mdp3::SecurityID{6466}}, + {mdp3::SecurityID{13775}}, + {mdp3::SecurityID{17318}}, + {mdp3::SecurityID{20929}}, + {mdp3::SecurityID{23860}}, + {mdp3::SecurityID{24376}}, + {mdp3::SecurityID{28092}}, + {mdp3::SecurityID{30106}}, + {mdp3::SecurityID{32490}}, + {mdp3::SecurityID{38472}}, + {mdp3::SecurityID{39312}}, + {mdp3::SecurityID{39415}}, + {mdp3::SecurityID{39581}}, + {mdp3::SecurityID{40584}}, + {mdp3::SecurityID{42317}}, + {mdp3::SecurityID{51659}}, + {mdp3::SecurityID{62679}}, + {mdp3::SecurityID{62684}}, + {mdp3::SecurityID{63676}}, + {mdp3::SecurityID{81409}}, + {mdp3::SecurityID{100440}}, + {mdp3::SecurityID{115482}}, + {mdp3::SecurityID{188775}}, + {mdp3::SecurityID{220768}}, + {mdp3::SecurityID{262483}}, + {mdp3::SecurityID{5936}, mdp3::SecurityID{224}, -1}, + {mdp3::SecurityID{14211}, mdp3::SecurityID{422}, -1}, + {mdp3::SecurityID{14945}, mdp3::SecurityID{422}, 1}, + {mdp3::SecurityID{23759}, mdp3::SecurityID{422}, 1}, + {mdp3::SecurityID{37283}, mdp3::SecurityID{422}, 1}, + {mdp3::SecurityID{53777}, mdp3::SecurityID{422}, -1}, + {mdp3::SecurityID{85863}, mdp3::SecurityID{422}, 1}, + {mdp3::SecurityID{11598}, mdp3::SecurityID{543}, -1}, + {mdp3::SecurityID{31215}, mdp3::SecurityID{771}, 1}, + {mdp3::SecurityID{17853}, mdp3::SecurityID{840}, 1}, + {mdp3::SecurityID{5936}, mdp3::SecurityID{1016}, 1}, + {mdp3::SecurityID{19224}, mdp3::SecurityID{1016}, -1}, + {mdp3::SecurityID{23149}, mdp3::SecurityID{1016}, 1}, + {mdp3::SecurityID{78321}, mdp3::SecurityID{1016}, 1}, + {mdp3::SecurityID{85573}, mdp3::SecurityID{1016}, 1}, + {mdp3::SecurityID{14211}, mdp3::SecurityID{2733}, 1}, + {mdp3::SecurityID{14587}, mdp3::SecurityID{3067}, -1}, + {mdp3::SecurityID{14945}, mdp3::SecurityID{3067}, -1}, + {mdp3::SecurityID{5029}, mdp3::SecurityID{3468}, -1}, + {mdp3::SecurityID{7378}, mdp3::SecurityID{3468}, 1}, + {mdp3::SecurityID{33889}, mdp3::SecurityID{4221}, -1}, + {mdp3::SecurityID{7378}, mdp3::SecurityID{6181}, -1}, + {mdp3::SecurityID{14587}, mdp3::SecurityID{6466}, 1}, + {mdp3::SecurityID{85834}, mdp3::SecurityID{6466}, -1}, + {mdp3::SecurityID{85863}, mdp3::SecurityID{6466}, -1}, + {mdp3::SecurityID{10136}, mdp3::SecurityID{13775}, 1}, + {mdp3::SecurityID{53777}, mdp3::SecurityID{17318}, 1}, + {mdp3::SecurityID{85834}, mdp3::SecurityID{17318}, 1}, + {mdp3::SecurityID{21779}, mdp3::SecurityID{20929}, 1}, + {mdp3::SecurityID{14539}, mdp3::SecurityID{24376}, -1}, + {mdp3::SecurityID{224307}, mdp3::SecurityID{24376}, -1}, + {mdp3::SecurityID{12732}, mdp3::SecurityID{28092}, -1}, + {mdp3::SecurityID{14539}, mdp3::SecurityID{28092}, 1}, + {mdp3::SecurityID{23149}, mdp3::SecurityID{30106}, -1}, + {mdp3::SecurityID{7026}, mdp3::SecurityID{32490}, -1}, + {mdp3::SecurityID{12732}, mdp3::SecurityID{32490}, 1}, + {mdp3::SecurityID{89321}, mdp3::SecurityID{32490}, -1}, + {mdp3::SecurityID{10136}, mdp3::SecurityID{38472}, -1}, + {mdp3::SecurityID{11598}, mdp3::SecurityID{39312}, 1}, + {mdp3::SecurityID{17853}, mdp3::SecurityID{39312}, -1}, + {mdp3::SecurityID{33889}, mdp3::SecurityID{39312}, 1}, + {mdp3::SecurityID{85573}, mdp3::SecurityID{42317}, -1}, + {mdp3::SecurityID{23759}, mdp3::SecurityID{51659}, -1}, + {mdp3::SecurityID{47843}, mdp3::SecurityID{62684}, -1}, + {mdp3::SecurityID{89318}, mdp3::SecurityID{62684}, 1}, + {mdp3::SecurityID{89089}, mdp3::SecurityID{63676}, -1}, + {mdp3::SecurityID{89318}, mdp3::SecurityID{63676}, -1}, + {mdp3::SecurityID{89321}, mdp3::SecurityID{63676}, 1}, + {mdp3::SecurityID{78321}, mdp3::SecurityID{81409}, -1}, + {mdp3::SecurityID{37283}, mdp3::SecurityID{100440}, -1}, + {mdp3::SecurityID{19224}, mdp3::SecurityID{115482}, 1}, + {mdp3::SecurityID{7026}, mdp3::SecurityID{188775}, 1}, + {mdp3::SecurityID{31215}, mdp3::SecurityID{188775}, -1}, + {mdp3::SecurityID{47843}, mdp3::SecurityID{188775}, 1}, + {mdp3::SecurityID{89089}, mdp3::SecurityID{188775}, 1}, + {mdp3::SecurityID{224307}, mdp3::SecurityID{188775}, 1}, + {mdp3::SecurityID{4353}, mdp3::SecurityID{220768}, 1}, + {mdp3::SecurityID{21779}, mdp3::SecurityID{220768}, -1}, + {mdp3::SecurityID{4353}, mdp3::SecurityID{262483}, -1}, + {mdp3::SecurityID{5029}, mdp3::SecurityID{262483}, 1}, }; std::vector universe; - auto get_instrument = [&universe](mdp3::MDP3SecurityID key) { + auto get_instrument = [&universe](mdp3::SecurityID key) { for (auto &i : universe) if (i.sec_id == key) return &i; diff --git a/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.cpp b/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.cpp index 880db5cdb..945ca3361 100644 --- a/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.cpp +++ b/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.cpp @@ -17,8 +17,8 @@ using namespace bts::spartan::mdp3; namespace bts::spartan::sql::adapters::polygon_defs { using PolygonDefs = std::unordered_map< - MDP3SecurityID, - std::vector>>; + SecurityID, + std::vector>>; // assume there aren't negative ids, const int no_id = -1; const char *polygon_legs = "polygon_legs"; @@ -46,10 +46,10 @@ PolygonDefs read_sql(const char *db_path, const char *legs_query) { })}}; std::function on_row([&](auto &r) { res.emplace( - MDP3SecurityID(r.pid), - std::vector>()) + SecurityID(r.pid), + std::vector>()) .first->second.emplace_back( - MDP3SecurityID(r.lsid), MDP3Quantity(r.ratio)); + SecurityID(r.lsid), Quantity(r.ratio)); }); char *err = nullptr; if (synthesize_rows(db.get(), legs_query, cell_ops, on_row, err)) @@ -72,4 +72,4 @@ PolygonDefs read_sql(const char *db_path, const std::unordered_set &ids) { legs_query << " or " << pid_col << "=" << *id_it; return read_sql(db_path, legs_query.str().c_str()); } -} // namespace bts::spartan::sql::adapters::polygon_defs \ No newline at end of file +} // namespace bts::spartan::sql::adapters::polygon_defs diff --git a/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.h b/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.h index 043f5f054..2d2fbdd52 100644 --- a/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.h +++ b/src/server/sparkd/cmds/spartan/util/sql/adapters/polygon_defs.h @@ -7,12 +7,12 @@ namespace bts::spartan::sql::adapters::polygon_defs { std::unordered_map< - mdp3::MDP3SecurityID, - std::vector>> + mdp3::SecurityID, + std::vector>> read_sql(const char *db_path, const char *legs_query); std::unordered_map< - mdp3::MDP3SecurityID, - std::vector>> + mdp3::SecurityID, + std::vector>> read_sql(const char *db_path, const std::unordered_set &ids); -} // namespace bts::spartan::sql::adapters::polygon_defs \ No newline at end of file +} // namespace bts::spartan::sql::adapters::polygon_defs