More refactoring.
This commit is contained in:
1 parent
e06ce66513
commit
7e13e8cb67
85 files changed
+990
-964
No files matched your search
@@ -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;positionLine truncated
|
||||
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/MoneyFileSLine truncated
|
||||
@@ -125,7 +125,7 @@ template <class B> void print_book(std::ostream &books, B const &b) {
|
||||
}
|
||||
|
||||
int icebergs_to_csv(
|
||||
const std::unordered_map<MDP3OrderKey, IcebergInput> &ibs,
|
||||
const std::unordered_map<OrderKey, IcebergInput> &ibs,
|
||||
const std::string &out_csv) {
|
||||
const char *ok_col = "ok";
|
||||
const char *eid_col = "eid";
|
||||
|
||||
@@ -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<std::unique_ptr<Target>> targets;
|
||||
std::optional<Opportunity> current_opportunity;
|
||||
std::unordered_map<MDP3SecurityID, MBPUpdate> books;
|
||||
std::unordered_map<SecurityID, MBPUpdate> 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();
|
||||
|
||||
@@ -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<MDP3OrderKey, WorkingOrder> working;
|
||||
std::unordered_map<OrderKey, WorkingOrder> 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<MDP3SecurityID, DependentTargets> books = {};
|
||||
std::unordered_map<SecurityID, DependentTargets> books = {};
|
||||
std::vector<std::unique_ptr<Target>> targets = {};
|
||||
std::optional<Shot> current_shot{};
|
||||
};
|
||||
@@ -337,12 +337,12 @@ void SniperModel::eval(std::vector<Target *> const &targets) {
|
||||
|
||||
bool SniperModel::within_safety_margin(Target const &t) const {
|
||||
Book synth_book;
|
||||
using LegInfo = std::tuple<MDP3Quantity, md::IntPrice, Book>;
|
||||
using LegInfo = std::tuple<Quantity, md::IntPrice, Book>;
|
||||
std::vector<LegInfo> 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);
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
// return nullptr;
|
||||
// }
|
||||
|
||||
// OrderTuple* find_ord(MDP3OrderKey key,
|
||||
// OrderTuple* find_ord(OrderKey key,
|
||||
// std::vector<OrderTuple>& 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<int>(skey.value())},
|
||||
// SecurityID{static_cast<int>(skey.value())},
|
||||
// side,
|
||||
// MDP3OrderPriority{},
|
||||
// md::IntPrice_from_double<7>(p.value()),
|
||||
// MDP3Quantity{static_cast<int>(q.value())},
|
||||
// Quantity{static_cast<int>(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<int>(q.value())};
|
||||
// ochange.order.quantity = Quantity{static_cast<int>(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()
|
||||
// });
|
||||
// }
|
||||
|
||||
@@ -28,11 +28,11 @@
|
||||
// }
|
||||
|
||||
// bool compare_keys (SecurityKey spark_k,
|
||||
// MDP3SecurityID spartan_k){
|
||||
// SecurityID spartan_k){
|
||||
// return static_cast<int>(spark_k.value()) == spartan_k.value();
|
||||
// }
|
||||
|
||||
// bts::orderman::Book* find_book(MDP3SecurityID id,
|
||||
// bts::orderman::Book* find_book(SecurityID id,
|
||||
// std::vector<bts::orderman::Book>& books){
|
||||
// for (auto& b : books)
|
||||
// if(compare_keys(b.security_key(),id))
|
||||
|
||||
+13
-13
@@ -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)
|
||||
// }
|
||||
// });
|
||||
|
||||
+16
-16
@@ -41,31 +41,31 @@
|
||||
SUMMARIZE_TRANSACTION_NAMED(name, _log_header(), FMT(__VA_ARGS__))
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
using _BookLevel = std::tuple<bts::md::IntPrice, MDP3Quantity>;
|
||||
using _BookLevel = std::tuple<bts::md::IntPrice, Quantity>;
|
||||
|
||||
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<MDP3SecurityID, std::tuple<FifoSecurityMatcher *, MDP3Quantity>>
|
||||
SecurityID security_id;
|
||||
std::map<SecurityID, std::tuple<FifoSecurityMatcher *, Quantity>>
|
||||
implied_mkt;
|
||||
// symbol/leg_symbols serve diagnostic purposes
|
||||
// (easier to read logs w/ actual symbols than sec ids)
|
||||
std::string symbol;
|
||||
std::map<MDP3SecurityID, std::string> leg_symbols;
|
||||
std::map<SecurityID, std::string> 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<std::tuple<MDP3Quantity, md::IntPrice, SmallBook>> im_vec;
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, SmallBook>> 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<MatchEffect> *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
|
||||
@@ -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<MatchEffect> *,
|
||||
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;
|
||||
|
||||
@@ -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<MDP3SecurityID, FifoMergedSecurityMatcher *> matchers;
|
||||
flat_map<MDP3SecurityID, std::string> symbols;
|
||||
flat_map<SecurityID, FifoMergedSecurityMatcher *> matchers;
|
||||
flat_map<SecurityID, std::string> 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<LegDef> &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<FifoPriceLevelMatcher *, MatcherOrder *>
|
||||
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<SmallOrderChange> &changes,
|
||||
std::vector<MatchEffect> *effects,
|
||||
FillDepot &fills) {
|
||||
@@ -204,7 +204,7 @@ void FifoMatcherContext::on_order_change(
|
||||
// diagnostic
|
||||
///////////////////////
|
||||
std::optional<std::string>
|
||||
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<BBORow> rows;
|
||||
|
||||
@@ -24,20 +24,20 @@ struct FifoMatcherContext {
|
||||
~FifoMatcherContext();
|
||||
|
||||
bool add_security(
|
||||
MDP3SecurityID sec_id,
|
||||
SecurityID sec_id,
|
||||
const std::string &symbol,
|
||||
const std::vector<LegDef> &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<SmallOrderChange> &changes,
|
||||
std::vector<MatchEffect> *effects,
|
||||
FillDepot &fills);
|
||||
@@ -46,22 +46,22 @@ struct FifoMatcherContext {
|
||||
std::vector<MatchEffect> *effects,
|
||||
FillDepot &fills);
|
||||
void print_all_bbos(std::ostream &out);
|
||||
std::optional<std::string> has_same_orders(MDP3SecurityID, const Orders &);
|
||||
std::optional<std::string> has_same_orders(SecurityID, const Orders &);
|
||||
std::tuple<FifoPriceLevelMatcher *, MatcherOrder *>
|
||||
find_order(MDP3SecurityID, MDP3OrderKey);
|
||||
find_order(SecurityID, OrderKey);
|
||||
|
||||
private:
|
||||
struct PImpl;
|
||||
std::shared_ptr<PImpl> _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 <class TIter>
|
||||
inline void reset(
|
||||
MDP3SecurityID sec_id,
|
||||
SecurityID sec_id,
|
||||
TIter first,
|
||||
TIter last,
|
||||
std::vector<MatchEffect> *effects = nullptr) {
|
||||
|
||||
@@ -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<uint32_t>(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<md::IntPrice, MDP3Quantity> t) {
|
||||
tuple_to_small_book_level(std::tuple<md::IntPrice, Quantity> 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<MatchEffect> *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());
|
||||
}
|
||||
|
||||
@@ -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<MatchEffect> *, FillDepot &);
|
||||
FifoImpliedSecurityMatcher *add_implied_matcher(MDP3SecurityID);
|
||||
FifoImpliedSecurityMatcher *add_implied_matcher(SecurityID);
|
||||
FifoSecurityMatcher *matcher();
|
||||
const FifoSecurityMatcher *matcheri() const;
|
||||
const std::vector<FifoImpliedSecurityMatcher *> &implied_matchers();
|
||||
@@ -47,11 +47,11 @@ struct FifoMergedSecurityMatcher {
|
||||
std::vector<MatchEffect> *,
|
||||
FillDepot &,
|
||||
bool reset_show_qty);
|
||||
MDP3Quantity _fill(
|
||||
MDP3OrderKey,
|
||||
Quantity _fill(
|
||||
OrderKey,
|
||||
api::Side,
|
||||
bts::md::IntPrice,
|
||||
MDP3Quantity,
|
||||
Quantity,
|
||||
std::vector<MatchEffect> *,
|
||||
FillDepot &);
|
||||
std::string _log_header() const;
|
||||
|
||||
@@ -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<MDP3Quantity, MDP3Quantity>
|
||||
std::tuple<Quantity, Quantity>
|
||||
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<MatchEffect> *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<int>(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<int>(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<MDP3OrderKey, MatcherOrder> &master_order_map,
|
||||
MDP3SecurityID sec,
|
||||
std::map<OrderKey, MatcherOrder> &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<MDP3Quantity, MDP3Quantity> FifoPriceLevelMatcher::on_new_opp_order(
|
||||
MDP3OrderKey opp_ord_key,
|
||||
MDP3Quantity cross_qty,
|
||||
std::tuple<Quantity, Quantity> FifoPriceLevelMatcher::on_new_opp_order(
|
||||
OrderKey opp_ord_key,
|
||||
Quantity cross_qty,
|
||||
bool add_agg_side_to_match_effect,
|
||||
std::vector<MatchEffect> *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<MatchEffect> *res) {
|
||||
OrderKey k, std::vector<MatchEffect> *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) {
|
||||
|
||||
@@ -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<MDP3OrderKey, MatcherOrder> *_master_order_map;
|
||||
MDP3SecurityID _sec;
|
||||
std::map<OrderKey, MatcherOrder> *_master_order_map;
|
||||
SecurityID _sec;
|
||||
md::IntPrice _price;
|
||||
api::Side _side;
|
||||
std::vector<MatcherOrder *> _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<MDP3Quantity, MDP3Quantity> _one_pass_cross_order(
|
||||
MDP3OrderKey cross_ord_key,
|
||||
MDP3Quantity cross_ord_qty,
|
||||
std::tuple<Quantity, Quantity> _one_pass_cross_order(
|
||||
OrderKey cross_ord_key,
|
||||
Quantity cross_ord_qty,
|
||||
bool add_agg_side_to_match_effect,
|
||||
std::vector<MatchEffect> *res);
|
||||
void _log_order(const MatcherOrder &ord, const std::string &msg);
|
||||
@@ -49,8 +49,8 @@ class FifoPriceLevelMatcher {
|
||||
// constructors ////////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
FifoPriceLevelMatcher(
|
||||
std::map<MDP3OrderKey, MatcherOrder> &,
|
||||
MDP3SecurityID sec,
|
||||
std::map<OrderKey, MatcherOrder> &,
|
||||
SecurityID sec,
|
||||
md::IntPrice price,
|
||||
api::Side side,
|
||||
const Trace &);
|
||||
@@ -72,18 +72,18 @@ class FifoPriceLevelMatcher {
|
||||
// simple accessors ////////////////////////////////////////////////////////
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
std::tuple<uint32_t, uint32_t> 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<int>(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<MDP3Quantity, MDP3Quantity> on_new_opp_order(
|
||||
MDP3OrderKey opp_ord_key,
|
||||
MDP3Quantity opp_ord_qty,
|
||||
std::tuple<Quantity, Quantity> on_new_opp_order(
|
||||
OrderKey opp_ord_key,
|
||||
Quantity opp_ord_qty,
|
||||
bool add_agg_side_to_match_effect,
|
||||
std::vector<MatchEffect> * = nullptr);
|
||||
void
|
||||
on_order_update(const MDP3Order &upd_ord, MatcherOrder *ord_hint = nullptr);
|
||||
void
|
||||
on_order_cancel(MatcherOrder &order, std::vector<MatchEffect> * = nullptr);
|
||||
void on_order_remove(MDP3OrderKey k, std::vector<MatchEffect> * = nullptr);
|
||||
void remove_from_price_level(MDP3OrderKey k);
|
||||
void on_order_remove(OrderKey k, std::vector<MatchEffect> * = nullptr);
|
||||
void remove_from_price_level(OrderKey k);
|
||||
void cleanup();
|
||||
std::string print_mbo(size_t n_orders) const;
|
||||
};
|
||||
|
||||
@@ -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<FifoPriceLevelMatcher *, MatcherOrder *>
|
||||
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<MatchEffect> *res) {
|
||||
OrderKey key, std::vector<MatchEffect> *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<md::IntPrice, MDP3Quantity>
|
||||
std::tuple<md::IntPrice, Quantity>
|
||||
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<MatchEffect> *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<MatchEffect> *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<std::string>
|
||||
@@ -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,
|
||||
|
||||
@@ -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<MDP3OrderKey, MatcherOrder> _order_map;
|
||||
std::map<OrderKey, MatcherOrder> _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<FifoPriceLevelMatcher *, MatcherOrder *>
|
||||
_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<MatchEffect> * = nullptr);
|
||||
void _on_order_remove(MDP3OrderKey, std::vector<MatchEffect> * = nullptr);
|
||||
void _on_order_remove(OrderKey, std::vector<MatchEffect> * = nullptr);
|
||||
void _on_order_not_affecting_books(
|
||||
const SmallOrderChange &o, std::vector<MatchEffect> *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<MatchEffect> *res,
|
||||
bool add_aggr_fill);
|
||||
std::tuple<md::IntPrice, MDP3Quantity>
|
||||
std::tuple<md::IntPrice, Quantity>
|
||||
book_level(api::Side side, size_t idx) const override;
|
||||
void on_order_change(
|
||||
SmallOrderChange const &, std::vector<MatchEffect> * = nullptr) override;
|
||||
void on_order_completed(MDP3OrderKey key);
|
||||
void on_order_completed(OrderKey key);
|
||||
// For testing
|
||||
std::optional<std::string> 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<FifoPriceLevelMatcher *, MatcherOrder *>
|
||||
find_order(MDP3OrderKey key) {
|
||||
find_order(OrderKey key) {
|
||||
return _find_order(key);
|
||||
}
|
||||
// debugging logging
|
||||
|
||||
@@ -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<md::IntPrice, MDP3Quantity> top_of_book(api::Side side) const;
|
||||
SecurityID security_id() const { return _security_id; }
|
||||
std::tuple<md::IntPrice, Quantity> top_of_book(api::Side side) const;
|
||||
|
||||
private:
|
||||
MDP3SecurityID _security_id;
|
||||
std::map<MDP3SecurityID, std::tuple<FifoSecurityMatcher *, MDP3Quantity>>
|
||||
SecurityID _security_id;
|
||||
std::map<SecurityID, std::tuple<FifoSecurityMatcher *, Quantity>>
|
||||
_implied_mkt;
|
||||
// hide copy ctr
|
||||
ImpliedFifoSecurityMatcher(const ImpliedFifoSecurityMatcher &);
|
||||
|
||||
void _book(
|
||||
api::Side side,
|
||||
std::vector<std::tuple<md::IntPrice, MDP3Quantity>> &dest) const;
|
||||
std::vector<std::tuple<md::IntPrice, Quantity>> &dest) const;
|
||||
uint32_t _fill_order(const MDP3Order &order);
|
||||
};
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -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<std::string, std::map<MDP3SecurityID, MBPSnapshot>> mbps;
|
||||
std::map<std::string, std::map<SecurityID, MBPSnapshot>> 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<MDP3SecurityID, MBPSnapshot>()).first;
|
||||
it = mbps.emplace(ass, std::map<SecurityID, MBPSnapshot>()).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<MDP3SecurityID> &inst_defs) {
|
||||
DirectMatcher::DirectMatcher(const std::vector<SecurityID> &inst_defs) {
|
||||
for (const auto &sec_id : inst_defs)
|
||||
_matcher_map.insert(std::pair<MDP3SecurityID, FifoSecurityMatcher>(
|
||||
_matcher_map.insert(std::pair<SecurityID, FifoSecurityMatcher>(
|
||||
sec_id, FifoSecurityMatcher(sec_id)));
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ void DirectMatcher::match(
|
||||
std::vector<MatchEffect> *res) {
|
||||
_match_count_this_per++;
|
||||
_match_count++;
|
||||
std::vector<std::pair<MDP3SecurityID, FifoSecurityMatcher *>> dirty;
|
||||
std::vector<std::pair<SecurityID, FifoSecurityMatcher *>> 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);
|
||||
|
||||
@@ -16,16 +16,16 @@ class InstrumentDefinition;
|
||||
|
||||
class MergedMatcher {
|
||||
private:
|
||||
std::unordered_set<MDP3OrderKey> _used_order_keys;
|
||||
std::map<MDP3SecurityID, std::string> _asset_map;
|
||||
std::unordered_set<OrderKey> _used_order_keys;
|
||||
std::map<SecurityID, std::string> _asset_map;
|
||||
std::map<std::string, FifoMatcherContext> _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<MatchEffect> *);
|
||||
|
||||
Book book(MDP3SecurityID, api::Side);
|
||||
ImpliedBook implied_book(MDP3SecurityID, api::Side);
|
||||
Book book(SecurityID, api::Side);
|
||||
ImpliedBook implied_book(SecurityID, api::Side);
|
||||
|
||||
template <class TIter> void init(TIter first, TIter last) {
|
||||
while (first != last) {
|
||||
@@ -51,7 +51,7 @@ class MergedMatcher {
|
||||
}
|
||||
|
||||
void reset(
|
||||
MDP3SecurityID sec,
|
||||
SecurityID sec,
|
||||
std::vector<MDP3Order> orders,
|
||||
std::vector<MatchEffect> *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<MDP3SecurityID, FifoSecurityMatcher> _matcher_map;
|
||||
std::map<SecurityID, FifoSecurityMatcher> _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<MDP3SecurityID> const &);
|
||||
DirectMatcher(std::vector<SecurityID> const &);
|
||||
DirectMatcher(DirectMatcher &&);
|
||||
DirectMatcher &operator=(DirectMatcher &&) { return *this; }
|
||||
|
||||
@@ -84,10 +84,10 @@ class DirectMatcher {
|
||||
void
|
||||
match(ChangeSrc, SmallOrderChangeVec const &, std::vector<MatchEffect> *);
|
||||
|
||||
Book book(MDP3SecurityID, api::Side);
|
||||
ImpliedBook implied_book(MDP3SecurityID, api::Side);
|
||||
Book book(SecurityID, api::Side);
|
||||
ImpliedBook implied_book(SecurityID, api::Side);
|
||||
|
||||
template <class Iter> void reset(MDP3SecurityID sec, Iter first, Iter last) {
|
||||
template <class Iter> void reset(SecurityID sec, Iter first, Iter last) {
|
||||
_matcher_map.try_emplace(sec).first->second.reset(first, last);
|
||||
}
|
||||
void clear();
|
||||
|
||||
@@ -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
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -10,11 +10,11 @@ namespace bts::spartan::mdp3 {
|
||||
|
||||
struct Trace {
|
||||
public:
|
||||
const std::map<MDP3OrderKey, bool> traced_orders = {
|
||||
{MDP3OrderKey(765164629193), true}};
|
||||
const std::map<OrderKey, bool> traced_orders = {
|
||||
{OrderKey(765164629193), true}};
|
||||
const std::map<size_t, bool> traced_events = {};
|
||||
const std::map<size_t, bool> 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<IcebergQuantity> 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<IcebergQuantity> 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<uint32_t, uint32_t, uint32_t> 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;
|
||||
|
||||
@@ -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<md::IntPrice, MDP3Quantity>
|
||||
virtual std::tuple<md::IntPrice, Quantity>
|
||||
book_level(api::Side, size_t level = 0) const = 0;
|
||||
// mutators
|
||||
virtual void on_order_change(
|
||||
|
||||
@@ -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<double, FillNode>>());
|
||||
OrderKey, std::unordered_map<double, FillNode>>());
|
||||
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<MDP3Fill> &dest) const {
|
||||
}
|
||||
|
||||
void FillDepot::copy_to(
|
||||
std::unordered_map<MDP3SecurityID, std::vector<MDP3Fill>> &dest) const {
|
||||
std::unordered_map<SecurityID, std::vector<MDP3Fill>> &dest) const {
|
||||
for (auto &sec_fills : _cache) {
|
||||
auto &fills =
|
||||
dest.emplace(sec_fills.first, std::vector<MDP3Fill>()).first->second;
|
||||
@@ -103,4 +103,4 @@ bool FillNode::match(const MDP3Fill &f) const {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace bts::spartan::mdp3
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -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<MDP3Fill> 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<MDP3Fill> &dest) const;
|
||||
void copy_to(
|
||||
std::unordered_map<MDP3SecurityID, std::vector<MDP3Fill>> &dest) const;
|
||||
std::unordered_map<SecurityID, std::vector<MDP3Fill>> &dest) const;
|
||||
|
||||
private:
|
||||
uint32_t _fill_count = 0;
|
||||
std::unordered_map<
|
||||
MDP3SecurityID,
|
||||
std::unordered_map<MDP3OrderKey, std::unordered_map<double, FillNode>>>
|
||||
SecurityID,
|
||||
std::unordered_map<OrderKey, std::unordered_map<double, FillNode>>>
|
||||
_cache;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const FillDepot &fd);
|
||||
} // namespace bts::spartan::mdp3
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -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
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -13,7 +13,7 @@ namespace bts::spartan::mdp3::iceberg_helper {
|
||||
void add_iceberg_annotation(
|
||||
MDP3Order &o,
|
||||
OrderChange::ChangeType change_type,
|
||||
const std::unordered_map<MDP3OrderKey, IcebergInput> &icebergs,
|
||||
const std::unordered_map<OrderKey, IcebergInput> &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)) -
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace bts::spartan::mdp3::iceberg_helper {
|
||||
void add_iceberg_annotation(
|
||||
MDP3Order &,
|
||||
OrderChange::ChangeType,
|
||||
const std::unordered_map<MDP3OrderKey, IcebergInput> &,
|
||||
const std::unordered_map<OrderKey, IcebergInput> &,
|
||||
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
|
||||
@@ -147,7 +147,7 @@ print_detailed_orders(TIter first, TIter last, std::ostream &out = std::cout) {
|
||||
std::vector<std::tuple<
|
||||
std::string, int,
|
||||
std::function<std::string(
|
||||
std::tuple<MDP3SecurityID, std::string, MDP3Order>)>>>{
|
||||
std::tuple<SecurityID, std::string, MDP3Order>)>>>{
|
||||
{" 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<
|
||||
std::string, int,
|
||||
std::function<std::string(
|
||||
std::tuple<MDP3SecurityID, std::string, OrderChange>)>>>{
|
||||
std::tuple<SecurityID, std::string, OrderChange>)>>>{
|
||||
{" 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(
|
||||
std::tuple<
|
||||
std::string, bts::md::IntPrice, MDP3Quantity,
|
||||
bts::md::IntPrice, MDP3Quantity>)>>>{
|
||||
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 <class TIter>
|
||||
inline void print_many_bbo(std::ostream &out, TIter first, TIter last) {
|
||||
std::vector<std::tuple<
|
||||
std::string, bts::md::IntPrice, MDP3Quantity, bts::md::IntPrice,
|
||||
MDP3Quantity>>
|
||||
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 <class TIter>
|
||||
inline void print_many_bbo_implied(std::ostream &out, TIter first, TIter last) {
|
||||
std::vector<std::tuple<
|
||||
std::string, bts::md::IntPrice, MDP3Quantity, bts::md::IntPrice,
|
||||
MDP3Quantity>>
|
||||
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::tuple<
|
||||
std::string, bts::md::IntPrice, MDP3Quantity, bts::md::IntPrice,
|
||||
MDP3Quantity, bts::md::IntPrice, MDP3Quantity, bts::md::IntPrice,
|
||||
MDP3Quantity>>
|
||||
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(
|
||||
std::tuple<
|
||||
std::string, bts::md::IntPrice, MDP3Quantity,
|
||||
bts::md::IntPrice, MDP3Quantity, bts::md::IntPrice,
|
||||
MDP3Quantity, bts::md::IntPrice, MDP3Quantity>)>>>{
|
||||
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
|
||||
} // namespace bts::spartan::mdp3::diagnostics
|
||||
@@ -40,12 +40,12 @@ MDP3Order create_order(
|
||||
uint32_t qty,
|
||||
std::optional<IcebergQuantity> 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<MDP3OrderKey, MatcherOrder> master_ord_map;
|
||||
std::map<OrderKey, MatcherOrder> 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<uint64_t>(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<OrderChange> &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<OrderChange> 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<OrderChange> 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<OrderChange> 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<OrderChange> 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<OrderChange> 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<OrderChange> 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<MatchEffect> 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;
|
||||
|
||||
+8
-8
@@ -27,23 +27,23 @@ inline std::string _iceberg_file_path(const std::string &pcap) {
|
||||
return dir + R"(/)" + name + ".icebergs";
|
||||
}
|
||||
|
||||
std::unordered_map<MDP3OrderKey, IcebergInput>
|
||||
std::unordered_map<OrderKey, IcebergInput>
|
||||
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<MDP3OrderKey, IcebergInput> dest;
|
||||
std::unordered_map<OrderKey, IcebergInput> dest;
|
||||
auto read_op = [&](std::istream &in) -> std::istream & {
|
||||
auto ok = file::read_from_bin<uint64_t>(in);
|
||||
auto total_qty = file::read_from_bin<int>(in);
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> show_quantities;
|
||||
std::vector<std::tuple<size_t, Quantity>> show_quantities;
|
||||
for (auto num_states = file::read_from_bin<ushort>(in); num_states > 0;
|
||||
num_states--) {
|
||||
size_t event_id = file::read_from_bin<size_t>(in);
|
||||
auto show_qty = file::read_from_bin<int>(in);
|
||||
show_quantities.emplace_back(event_id, MDP3Quantity(show_qty));
|
||||
show_quantities.emplace_back(event_id, Quantity(show_qty));
|
||||
}
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> fill_quantities;
|
||||
std::vector<std::tuple<size_t, Quantity>> fill_quantities;
|
||||
for (auto num_fill_events = file::read_from_bin<ushort>(in);
|
||||
num_fill_events > 0; num_fill_events--) {
|
||||
size_t event_id = file::read_from_bin<size_t>(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<MDP3OrderKey, IcebergInput> &p) -> std::ostream & {
|
||||
const std::pair<OrderKey, IcebergInput> &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(
|
||||
|
||||
@@ -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 <pcap>.icebergs,
|
||||
// for faster retrieval on subsequent runs with the specified pcap.
|
||||
std::unordered_map<MDP3OrderKey, IcebergInput>
|
||||
std::unordered_map<OrderKey, IcebergInput>
|
||||
find_icebergs(const std::string &pcap, bool force_regen = false);
|
||||
} // namespace bts::spartan::mdp3::iceberg_file_cache
|
||||
} // namespace bts::spartan::mdp3::iceberg_file_cache
|
||||
+11
-11
@@ -72,7 +72,7 @@ void _sync_orders(
|
||||
size_t event_id,
|
||||
const InstrumentSnapshot &s,
|
||||
Orders &orders,
|
||||
const std::unordered_map<MDP3OrderKey, IcebergInput> &icebergs) {
|
||||
const std::unordered_map<OrderKey, IcebergInput> &icebergs) {
|
||||
//
|
||||
for (auto ch : s.order_changes()) {
|
||||
switch (ch.change) {
|
||||
@@ -153,7 +153,7 @@ inline bool match_fills(
|
||||
const FillDepot &fd,
|
||||
std::vector<const InstrumentSnapshot *> snaps,
|
||||
std::ostream &out = std::cout) {
|
||||
std::unordered_map<MDP3SecurityID, std::vector<MDP3Fill>> fill_map;
|
||||
std::unordered_map<SecurityID, std::vector<MDP3Fill>> 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<MDP3OrderKey, IcebergInput> icebergs,
|
||||
std::unordered_map<OrderKey, IcebergInput> icebergs,
|
||||
flat_map<size_t, size_t> interesting_event_ranges)
|
||||
: icebergs(icebergs),
|
||||
interesting_event_ranges(interesting_event_ranges) {}
|
||||
|
||||
flat_map<MDP3SecurityID, _SecurityData> security_cache;
|
||||
std::unordered_map<MDP3OrderKey, IcebergInput> icebergs;
|
||||
flat_map<SecurityID, _SecurityData> security_cache;
|
||||
std::unordered_map<OrderKey, IcebergInput> icebergs;
|
||||
flat_map<size_t, size_t> interesting_event_ranges;
|
||||
flat_map<MDP3OrderKey, MDP3Order> interesting_orders;
|
||||
flat_map<OrderKey, MDP3Order> 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<MDP3OrderKey, IcebergInput> icebergs)
|
||||
std::unordered_map<OrderKey, IcebergInput> icebergs)
|
||||
: MatcherValidationObserver(icebergs, flat_map<size_t, size_t>{}) {}
|
||||
|
||||
MatcherValidationObserver::MatcherValidationObserver(
|
||||
std::unordered_map<MDP3OrderKey, IcebergInput> icebergs,
|
||||
std::unordered_map<OrderKey, IcebergInput> icebergs,
|
||||
flat_map<size_t, size_t> 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<MDP3OrderKey, MDP3Quantity> fill_map;
|
||||
std::unordered_map<OrderKey, Quantity> fill_map;
|
||||
for (const auto *s : sorted_secs) {
|
||||
accumulate_fills(s->fills().begin(), s->fills().end(), fill_map);
|
||||
_me->exch_matcher.add_security(
|
||||
|
||||
+2
-2
@@ -12,13 +12,13 @@
|
||||
namespace bts::spartan::mdp3 {
|
||||
struct MatcherValidationObserver : IChannelObserver {
|
||||
MatcherValidationObserver(
|
||||
std::unordered_map<MDP3OrderKey, IcebergInput> icebergs);
|
||||
std::unordered_map<OrderKey, IcebergInput> 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<MDP3OrderKey, IcebergInput> icebergs,
|
||||
std::unordered_map<OrderKey, IcebergInput> icebergs,
|
||||
boost::container::flat_map<size_t, size_t> interesting_event_ranges);
|
||||
~MatcherValidationObserver();
|
||||
void on_recovery_complete(InitialSnapshot const &snap) override;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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<MDP3OrderKey, MDP3OrderKey> cme_key_map;
|
||||
std::unordered_map<OrderKey, OrderKey> 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<MDP3SecurityID> ready_secs;
|
||||
std::unordered_set<SecurityID> ready_secs;
|
||||
};
|
||||
|
||||
struct Sim::AlgoCBFilter : IAlgoModel {
|
||||
@@ -90,14 +90,14 @@ struct Sim::PImpl {
|
||||
PolygonMap const &polygons;
|
||||
PCapEventGenerator &event_generator;
|
||||
SimLogger logger;
|
||||
std::unordered_map<MDP3SecurityID, InstrumentSnapshot> snapshots = {};
|
||||
std::unordered_map<SecurityID, InstrumentSnapshot> snapshots = {};
|
||||
State state = State::REPLAY;
|
||||
TimeStamp transact_time = TimeStamp{0};
|
||||
TimeStamp time = TimeStamp{0};
|
||||
AlgoEventID event_id = {0, 0};
|
||||
std::optional<Simulation> simulation = {};
|
||||
MDP3OrderKey last_order_key =
|
||||
MDP3OrderKey{std::numeric_limits<MDP3OrderKey::Value>::max()};
|
||||
OrderKey last_order_key =
|
||||
OrderKey{std::numeric_limits<OrderKey::Value>::max()};
|
||||
std::vector<OrderUpdate> 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;
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace bts::spartan::mdp3 {
|
||||
class PandL {
|
||||
public:
|
||||
using SymbolNetCash = std::unordered_map<std::string, double>;
|
||||
using OutrightPosition = std::unordered_map<MDP3SecurityID, int64_t>;
|
||||
using OutrightPosition = std::unordered_map<SecurityID, int64_t>;
|
||||
|
||||
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<PImpl> me;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -27,8 +27,8 @@
|
||||
// BeforeLaunchBridge& bl_bridge;
|
||||
// IAlgoOrder& algo_order;
|
||||
// ISimServices& sim_services;
|
||||
// std::unordered_map<MDP3SecurityID,Book> book_map;
|
||||
// std::unordered_map<MDP3OrderKey,OrderState> order_map;
|
||||
// std::unordered_map<SecurityID,Book> book_map;
|
||||
// std::unordered_map<OrderKey,OrderState> 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());
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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<uint32_t>(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<uint64_t>(k.value()));
|
||||
// return bts::spartan::mdp3::OrderKey(static_cast<uint64_t>(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<uint32_t>(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<int>(k.value()));
|
||||
// return bts::spartan::mdp3::SecurityID(static_cast<int>(k.value()));
|
||||
// }
|
||||
|
||||
// inline void translate_book(const bts::spartan::mdp3::MBPUpdate& u_in,
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
#include "OrderKey.h"
|
||||
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
using OrderKey = utils::ValueWrapper<struct OrderKeyTag, uint64_t>;
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#include "SecurityID.h"
|
||||
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lib/utils/ValueWrapper.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
using SecurityID =
|
||||
utils::ValueWrapper<struct SecurityIDTag, int32_t>;
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#include "TimeInterval.h"
|
||||
@@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
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:
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
}
|
||||
|
||||
void shift(TimeInterval i) {
|
||||
_v += i.nanoseconds();
|
||||
_v += i.nanos();
|
||||
}
|
||||
|
||||
std::string to_time_string() const ;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<InstrumentDefinition>;
|
||||
using InstrumentDefinitions =
|
||||
std::unordered_map<MDP3SecurityID, InstrumentDefinition const *>;
|
||||
std::unordered_map<SecurityID, InstrumentDefinition const *>;
|
||||
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -6,10 +6,10 @@
|
||||
namespace bts::spartan::mdp3 {
|
||||
class InstrumentDefinition;
|
||||
using InstrumentMap =
|
||||
std::unordered_map<MDP3SecurityID, InstrumentDefinition const *>;
|
||||
std::unordered_map<SecurityID, InstrumentDefinition const *>;
|
||||
|
||||
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;
|
||||
|
||||
@@ -16,7 +16,7 @@ struct InstrumentSnapshot::PImpl {
|
||||
implied_matching_status(false) {}
|
||||
|
||||
// Books
|
||||
MDP3SecurityID security_id;
|
||||
SecurityID security_id;
|
||||
std::array<Book, 2> books;
|
||||
std::array<ImpliedBook, 2> 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<AggOrderRec> 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(
|
||||
|
||||
@@ -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<MDP3SecurityID, InstrumentSnapshot const *>;
|
||||
std::unordered_map<SecurityID, InstrumentSnapshot const *>;
|
||||
std::ostream &operator<<(std::ostream &, InstrumentSnapshot const &);
|
||||
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 <boost/container/flat_set.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
@@ -13,10 +15,6 @@
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
using MDP3OrderKey = utils::ValueWrapper<struct ExchangeOrderKeyTag, uint64_t>;
|
||||
using MDP3SecurityID =
|
||||
utils::ValueWrapper<struct ExchangeSecurityIDTag, int32_t>;
|
||||
|
||||
class InstrumentSnapshot;
|
||||
using InstrumentSnapshotPtr = std::unique_ptr<InstrumentSnapshot>;
|
||||
|
||||
@@ -55,9 +53,9 @@ inline std::ostream &operator<<(std::ostream &s, MDP3Event const &ev) {
|
||||
return s;
|
||||
}
|
||||
|
||||
using MDP3Quantity = utils::ValueWrapper<struct MDP3QuantityTag, int32_t>;
|
||||
using Quantity = utils::ValueWrapper<struct QuantityTag, int32_t>;
|
||||
|
||||
using Pricer = std::function<double(MDP3SecurityID, MDP3Quantity, api::Side)>;
|
||||
using Pricer = std::function<double(SecurityID, Quantity, api::Side)>;
|
||||
|
||||
using MDP3OrderPriority =
|
||||
utils::ValueWrapper<struct MDP3OrderPriorityTag, uint64_t>;
|
||||
@@ -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<IcebergQuantity> 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<SmallOrderChange, 1>;
|
||||
|
||||
@@ -225,15 +223,15 @@ inline std::ostream &operator<<(std::ostream &s, OrderChanges const &changes) {
|
||||
return s;
|
||||
}
|
||||
|
||||
using Orders = std::unordered_map<MDP3OrderKey, MDP3Order>;
|
||||
using Orders = std::unordered_map<OrderKey, MDP3Order>;
|
||||
|
||||
using MDP3TradeEntryID =
|
||||
utils::ValueWrapper<struct MDP3TradeEntryIDTag, uint32_t>;
|
||||
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; }
|
||||
|
||||
|
||||
@@ -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
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<MDP3SecurityID, ImpliedContractData> contracts;
|
||||
std::map<SecurityID, ImpliedContractData> contracts;
|
||||
std::vector<const ImpliedContractData *> contracts_vect;
|
||||
};
|
||||
|
||||
@@ -77,14 +77,14 @@ ImpliedMarket::~ImpliedMarket() {}
|
||||
///////////////////////
|
||||
// contract(s) accessors
|
||||
///////////////////////
|
||||
const std::map<MDP3SecurityID, ImpliedContractData> &
|
||||
const std::map<SecurityID, ImpliedContractData> &
|
||||
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<LegData> ImpliedMarket::implied_mkts(MDP3SecurityID sec) const {
|
||||
std::vector<LegData> ImpliedMarket::implied_mkts(SecurityID sec) const {
|
||||
auto cdata_it = _me->contracts.find(sec);
|
||||
std::vector<LegData> rv;
|
||||
bts_assert(cdata_it != _me->contracts.end());
|
||||
@@ -161,4 +161,4 @@ std::vector<LegData> ImpliedMarket::implied_mkts(MDP3SecurityID sec) const {
|
||||
_add_implied_combinations(cdata_it->second, rv);
|
||||
return rv;
|
||||
}
|
||||
} // namespace bts::spartan::mdp3
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -7,45 +7,45 @@
|
||||
#include <vector>
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
using Legs = boost::container::flat_map<MDP3SecurityID, MDP3Quantity>;
|
||||
using Legs = boost::container::flat_map<SecurityID, Quantity>;
|
||||
|
||||
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<MDP3SecurityID, std::tuple<ImpliedContractData, MDP3Quantity>>;
|
||||
flat_map<SecurityID, std::tuple<ImpliedContractData, Quantity>>;
|
||||
|
||||
struct ImpliedMarket {
|
||||
ImpliedMarket();
|
||||
~ImpliedMarket();
|
||||
|
||||
const std::map<MDP3SecurityID, ImpliedContractData> &contracts() const;
|
||||
const std::map<SecurityID, ImpliedContractData> &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<LegData> implied_mkts(MDP3SecurityID sec) const;
|
||||
ImpliedContractData &add_contract(SecurityID sec);
|
||||
void remove_contract(SecurityID sec);
|
||||
std::vector<LegData> 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
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -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<MDP3SecurityID, std::unique_ptr<InstrumentSnapshot>>
|
||||
std::unordered_map<SecurityID, std::unique_ptr<InstrumentSnapshot>>
|
||||
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 <class DefM> 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;
|
||||
|
||||
@@ -95,7 +95,7 @@ class RealTimeHandler {
|
||||
struct TradeOrderDetail;
|
||||
std::unique_ptr<PImpl> me;
|
||||
|
||||
InstrumentSnapshot *find_instrument(MDP3SecurityID);
|
||||
InstrumentSnapshot *find_instrument(SecurityID);
|
||||
void on_end_of_event();
|
||||
template <class Def> void on_instrument_definition(Def &);
|
||||
};
|
||||
|
||||
@@ -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<MDP3SecurityID> definition_ids;
|
||||
std::unordered_set<SecurityID> 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<MDP3SecurityID, InstrumentBookSnapshot *> book_snaps_idx;
|
||||
std::unordered_map<SecurityID, InstrumentBookSnapshot *> 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);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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<MDP3SecurityID, InstrumentSnapshot const *>
|
||||
std::unordered_map<SecurityID, InstrumentSnapshot const *>
|
||||
instruments;
|
||||
void on_recovery_complete(
|
||||
std::vector<InstrumentSnapshot const *> const &snaps) override {
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
namespace bts::spartan::mdp3::book_utils {
|
||||
|
||||
template <class TBook> 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 <class TBook> 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<md::IntPrice, MDP3Quantity> units_at_best_price() const {
|
||||
std::tuple<md::IntPrice, Quantity> 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 <class TBook> 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 <class TBook> 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<md::IntPrice(const SmallBookLevel &)> get_price(
|
||||
[](const auto &sbl) { return sbl.price; });
|
||||
std::function<MDP3Quantity(const SmallBookLevel &)> get_qty(
|
||||
std::function<Quantity(const SmallBookLevel &)> 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 <class TBook>
|
||||
inline void _compute_synthetic_book(
|
||||
TBook &dest,
|
||||
const std::vector<std::tuple<MDP3Quantity, md::IntPrice, TBook>> &leg_mkts,
|
||||
const std::vector<std::tuple<Quantity, md::IntPrice, TBook>> &leg_mkts,
|
||||
uint32_t max_depth,
|
||||
std::optional<MDP3Quantity> max_qty = std::nullopt) {
|
||||
std::optional<Quantity> 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<int>::max());
|
||||
Quantity limiting_factor(std::numeric_limits<int>::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<std::tuple<MDP3Quantity, md::IntPrice, SmallBook>>
|
||||
const std::vector<std::tuple<Quantity, md::IntPrice, SmallBook>>
|
||||
&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<MDP3Quantity, md::IntPrice, SmallBook, SmallBook>> &leg_mkts,
|
||||
std::tuple<Quantity, md::IntPrice, SmallBook, SmallBook>> &leg_mkts,
|
||||
uint32_t depth) {
|
||||
std::vector<std::tuple<MDP3Quantity, md::IntPrice, SmallBook>> leg_bids;
|
||||
std::vector<std::tuple<MDP3Quantity, md::IntPrice, SmallBook>> leg_asks;
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, SmallBook>> leg_bids;
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, SmallBook>> 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<std::tuple<MDP3Quantity, md::IntPrice, Book, Book>>
|
||||
const std::vector<std::tuple<Quantity, md::IntPrice, Book, Book>>
|
||||
&leg_mkts,
|
||||
uint32_t depth) {
|
||||
SmallBook sb_bids_dest, sb_asks_dest;
|
||||
std::vector<std::tuple<MDP3Quantity, md::IntPrice, SmallBook, SmallBook>>
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, SmallBook, SmallBook>>
|
||||
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<std::tuple<MDP3Quantity, md::IntPrice, Book>> &leg_mkts,
|
||||
const std::vector<std::tuple<Quantity, md::IntPrice, Book>> &leg_mkts,
|
||||
uint32_t depth) {
|
||||
std::vector<std::tuple<MDP3Quantity, md::IntPrice, SmallBook>> sleg_mkts;
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, SmallBook>> sleg_mkts;
|
||||
for (auto [qty, price, bk] : leg_mkts)
|
||||
sleg_mkts.emplace_back(qty, price, to_small_book(bk));
|
||||
SmallBook sbook_out;
|
||||
|
||||
@@ -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<md::IntPrice, MDP3Quantity> &pl) {
|
||||
fmt_price_level(const std::tuple<md::IntPrice, Quantity> &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<md::IntPrice, MDP3Quantity> &pl) {
|
||||
api::Side side, const std::tuple<md::IntPrice, Quantity> &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<md::IntPrice(T)> get_price,
|
||||
std::function<MDP3Quantity(T)> get_qty,
|
||||
std::function<Quantity(T)> 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<md::IntPrice(T)> get_price,
|
||||
std::function<MDP3Quantity(T)> get_qty,
|
||||
std::function<Quantity(T)> 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 <class Iter>
|
||||
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 <class TIter>
|
||||
@@ -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<std::tuple<MDP3Quantity, md::IntPrice, SmallBook>>
|
||||
const std::vector<std::tuple<Quantity, md::IntPrice, SmallBook>>
|
||||
&leg_mkts,
|
||||
uint32_t depth);
|
||||
|
||||
@@ -175,18 +175,18 @@ void compute_synthetic_books(
|
||||
SmallBook &bids_dest,
|
||||
SmallBook &asks_dest,
|
||||
const std::vector<
|
||||
std::tuple<MDP3Quantity, md::IntPrice, SmallBook, SmallBook>> &leg_mkts,
|
||||
std::tuple<Quantity, md::IntPrice, SmallBook, SmallBook>> &leg_mkts,
|
||||
uint32_t depth);
|
||||
|
||||
void compute_synthetic_books(
|
||||
Book &bids_dest,
|
||||
Book &asks_dest,
|
||||
const std::vector<std::tuple<MDP3Quantity, md::IntPrice, Book, Book>>
|
||||
const std::vector<std::tuple<Quantity, md::IntPrice, Book, Book>>
|
||||
&leg_mkts,
|
||||
uint32_t depth);
|
||||
|
||||
void compute_synthetic_book(
|
||||
Book &book_out,
|
||||
const std::vector<std::tuple<MDP3Quantity, md::IntPrice, Book>> &leg_mkts,
|
||||
const std::vector<std::tuple<Quantity, md::IntPrice, Book>> &leg_mkts,
|
||||
uint32_t depth);
|
||||
} // namespace bts::spartan::mdp3::book_utils
|
||||
@@ -499,7 +499,7 @@ struct CSVObs : IChannelObserver {
|
||||
std::ofstream books;
|
||||
std::ofstream packets;
|
||||
std::ofstream spread_legs;
|
||||
std::unordered_set<MDP3SecurityID> known_securities;
|
||||
std::unordered_set<SecurityID> known_securities;
|
||||
std::stringstream ts_buffer;
|
||||
|
||||
template <class B> void print_book(B const &b) {
|
||||
@@ -739,7 +739,7 @@ int to_csv(std::string const &file) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::unordered_map<MDP3OrderKey, IcebergInput>
|
||||
std::unordered_map<OrderKey, IcebergInput>
|
||||
find_icebergs(std::string const &pcap) {
|
||||
return IcebergFinder::find_all(pcap);
|
||||
}
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
inline md::IntPrice
|
||||
get_price(const std::tuple<md::IntPrice, MDP3Quantity> &price_level) {
|
||||
get_price(const std::tuple<md::IntPrice, Quantity> &price_level) {
|
||||
return std::get<0>(price_level);
|
||||
}
|
||||
inline MDP3Quantity
|
||||
get_qty(const std::tuple<md::IntPrice, MDP3Quantity> &price_level) {
|
||||
inline Quantity
|
||||
get_qty(const std::tuple<md::IntPrice, Quantity> &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 <class TIter>
|
||||
inline void accumulate_fills(
|
||||
TIter first,
|
||||
TIter last,
|
||||
std::unordered_map<MDP3OrderKey, MDP3Quantity> &dest) {
|
||||
std::unordered_map<OrderKey, Quantity> &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<MDP3Fill> &fills,
|
||||
std::unordered_map<MDP3OrderKey, MDP3Quantity> &dest) {
|
||||
std::unordered_map<OrderKey, Quantity> &dest) {
|
||||
accumulate_fills(fills.begin(), fills.end(), dest);
|
||||
}
|
||||
|
||||
inline std::unordered_map<MDP3OrderKey, MDP3Quantity>
|
||||
inline std::unordered_map<OrderKey, Quantity>
|
||||
accumulate_fills(const std::vector<MDP3Fill> &fills) {
|
||||
std::unordered_map<MDP3OrderKey, MDP3Quantity> rv;
|
||||
std::unordered_map<OrderKey, Quantity> rv;
|
||||
accumulate_fills(fills.begin(), fills.end(), rv);
|
||||
return rv;
|
||||
}
|
||||
} // namespace bts::spartan::mdp3
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -7,7 +7,7 @@ namespace bts::spartan::mdp3 {
|
||||
size_t gcd(InstrumentParts const &);
|
||||
|
||||
PolyInstrument make_spread(
|
||||
mdp3::MDP3SecurityID id, std::initializer_list<InstrumentPart> legs) {
|
||||
mdp3::SecurityID id, std::initializer_list<InstrumentPart> 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<PolyInstrument const *> 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<Polygon> 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<PolyInstrument> const &universe) {
|
||||
std::unordered_map<mdp3::MDP3SecurityID, PolyInstrument const *>
|
||||
std::unordered_map<mdp3::SecurityID, PolyInstrument const *>
|
||||
universe_idx;
|
||||
for (auto &i : universe)
|
||||
universe_idx[i.sec_id] = &i;
|
||||
|
||||
std::unordered_map<mdp3::MDP3SecurityID, int> net;
|
||||
std::unordered_map<mdp3::SecurityID, int> net;
|
||||
|
||||
for (auto &polygon_point : p.parts) {
|
||||
auto &point_instrument = universe_idx[polygon_point.sec_id];
|
||||
@@ -311,10 +311,10 @@ using InstrumentCluster = std::vector<PolyInstrument>;
|
||||
std::vector<InstrumentCluster>
|
||||
clusterize(std::vector<PolyInstrument> const &universe) {
|
||||
|
||||
std::unordered_map<MDP3SecurityID, PolyInstrument> idx;
|
||||
std::unordered_map<SecurityID, PolyInstrument> idx;
|
||||
|
||||
std::vector<InstrumentCluster> result;
|
||||
Graph<MDP3SecurityID> g;
|
||||
Graph<SecurityID> g;
|
||||
for (auto const &poly : universe) {
|
||||
idx[poly.sec_id] = poly;
|
||||
g.add_node(poly.sec_id);
|
||||
@@ -353,7 +353,7 @@ clusterize(std::vector<PolyInstrument> 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;
|
||||
|
||||
@@ -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<InstrumentPart, 6>;
|
||||
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<InstrumentPart> legs);
|
||||
PolyInstrument make_outright(mdp3::MDP3SecurityID);
|
||||
make_spread(mdp3::SecurityID, std::initializer_list<InstrumentPart> 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;
|
||||
};
|
||||
|
||||
@@ -11,8 +11,8 @@ namespace bts::spartan::mdp3 {
|
||||
// Find all security definitions in the pcap
|
||||
|
||||
struct DefinitionCollector : IChannelObserver {
|
||||
std::unordered_map<MDP3SecurityID, InstrumentDefinition> result;
|
||||
std::unordered_map<MDP3SecurityID, InstrumentDefinition const *> ptr_result;
|
||||
std::unordered_map<SecurityID, InstrumentDefinition> result;
|
||||
std::unordered_map<SecurityID, InstrumentDefinition const *> ptr_result;
|
||||
|
||||
void finit() override;
|
||||
void init() override;
|
||||
|
||||
@@ -7,7 +7,7 @@ FillCounter::FillCounter() {}
|
||||
FillCounter::~FillCounter() {}
|
||||
|
||||
struct FillCounter::PImpl {
|
||||
std::map<MDP3SecurityID, FillCount> counts;
|
||||
std::map<SecurityID, FillCount> counts;
|
||||
};
|
||||
|
||||
void FillCounter::init() {
|
||||
|
||||
@@ -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<FillCount> result;
|
||||
std::unordered_map<MDP3SecurityID, size_t> result_map() {
|
||||
std::unordered_map<MDP3SecurityID, size_t> result_idx;
|
||||
std::unordered_map<SecurityID, size_t> result_map() {
|
||||
std::unordered_map<SecurityID, size_t> result_idx;
|
||||
for (auto const &f : result)
|
||||
result_idx[f.sec_id] = f.fills;
|
||||
return result_idx;
|
||||
|
||||
@@ -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<std::tuple<size_t, MDP3Quantity>> &fill_quantities) {
|
||||
MDP3Quantity rv(0);
|
||||
const std::vector<std::tuple<size_t, Quantity>> &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<size_t, MDP3Quantity> _show_qty_at(
|
||||
std::tuple<size_t, Quantity> _show_qty_at(
|
||||
size_t event_id,
|
||||
const std::vector<std::tuple<size_t, MDP3Quantity>> &show_quantities) {
|
||||
const std::vector<std::tuple<size_t, Quantity>> &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<std::tuple<size_t, MDP3Quantity>> show_quantities,
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> fill_quantities)
|
||||
Quantity total_qty,
|
||||
std::vector<std::tuple<size_t, Quantity>> show_quantities,
|
||||
std::vector<std::tuple<size_t, Quantity>> 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<size_t, MDP3Quantity>
|
||||
std::tuple<size_t, Quantity>
|
||||
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<MDP3OrderKey, FillInfo> fills;
|
||||
std::unordered_map<MDP3OrderKey, IcebergInputBuilder> builder;
|
||||
std::unordered_map<OrderKey, FillInfo> fills;
|
||||
std::unordered_map<OrderKey, IcebergInputBuilder> 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<MDP3OrderKey, IcebergInput>
|
||||
std::unordered_map<OrderKey, IcebergInput>
|
||||
IcebergFinder::find_all(const std::string &pcap) {
|
||||
IcebergFinder ibf;
|
||||
observe_channel(pcap, ibf);
|
||||
|
||||
@@ -15,21 +15,21 @@ namespace bts::spartan::mdp3 {
|
||||
|
||||
struct IcebergInput {
|
||||
IcebergInput(
|
||||
MDP3Quantity total_qty,
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> show_quantities,
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> fill_quantities);
|
||||
Quantity total_qty,
|
||||
std::vector<std::tuple<size_t, Quantity>> show_quantities,
|
||||
std::vector<std::tuple<size_t, Quantity>> fill_quantities);
|
||||
|
||||
MDP3Quantity total_qty() const { return _total_qty; }
|
||||
Quantity total_qty() const { return _total_qty; }
|
||||
|
||||
const std::vector<std::tuple<size_t, MDP3Quantity>> show_quantities() const {
|
||||
const std::vector<std::tuple<size_t, Quantity>> show_quantities() const {
|
||||
return _show_quantities;
|
||||
}
|
||||
std::tuple<size_t, MDP3Quantity> show_qty_at(size_t event_id) const;
|
||||
std::tuple<size_t, Quantity> show_qty_at(size_t event_id) const;
|
||||
|
||||
const std::vector<std::tuple<size_t, MDP3Quantity>> fill_quantities() const {
|
||||
const std::vector<std::tuple<size_t, Quantity>> 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<size_t> all_eids() {
|
||||
std::set<size_t> result;
|
||||
@@ -41,33 +41,33 @@ struct IcebergInput {
|
||||
}
|
||||
|
||||
private:
|
||||
MDP3Quantity _total_qty = MDP3Quantity(0);
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> _show_quantities;
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> _fill_quantities;
|
||||
Quantity _total_qty = Quantity(0);
|
||||
std::vector<std::tuple<size_t, Quantity>> _show_quantities;
|
||||
std::vector<std::tuple<size_t, Quantity>> _fill_quantities;
|
||||
};
|
||||
|
||||
using IcebergMap = std::unordered_map<MDP3OrderKey, IcebergInput>;
|
||||
using IcebergMap = std::unordered_map<OrderKey, IcebergInput>;
|
||||
|
||||
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<std::tuple<size_t, MDP3Quantity>> _show_quantities;
|
||||
std::vector<std::tuple<size_t, MDP3Quantity>> _fill_quantities;
|
||||
OrderKey _key = OrderKey(0);
|
||||
Quantity _filled_qty = Quantity(0);
|
||||
Quantity _active_qty = Quantity(0);
|
||||
std::vector<std::tuple<size_t, Quantity>> _show_quantities;
|
||||
std::vector<std::tuple<size_t, Quantity>> _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<size_t, MDP3Quantity> _at_index(uint32_t i) const {
|
||||
std::tuple<size_t, Quantity> _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<MDP3OrderKey, IcebergInput> result;
|
||||
std::unordered_map<OrderKey, IcebergInput> 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<MDP3OrderKey, IcebergInput>
|
||||
static std::unordered_map<OrderKey, IcebergInput>
|
||||
find_all(const std::string &pcap);
|
||||
|
||||
private:
|
||||
|
||||
@@ -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<MDP3SecurityID, PolyInstrument> poly_universe;
|
||||
std::unordered_map<SecurityID, PolyInstrument> 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<MDP3SecurityID> all_legs;
|
||||
std::unordered_set<SecurityID> all_legs;
|
||||
for (auto &p : poly_universe) {
|
||||
auto &poly_instrument = p.second;
|
||||
auto it = me->def_collector.result.find(p.first);
|
||||
|
||||
@@ -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<size_t> active_polygons = {};
|
||||
std::unordered_map<MDP3SecurityID, SnapshotRec> all_snapshots = {};
|
||||
std::unordered_map<MDP3SecurityID, std::vector<size_t>> dependencies = {};
|
||||
std::unordered_map<SecurityID, SnapshotRec> all_snapshots = {};
|
||||
std::unordered_map<SecurityID, std::vector<size_t>> 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<std::tuple<MDP3Quantity, md::IntPrice, Book, Book>> legs;
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, Book, Book>> 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();
|
||||
|
||||
@@ -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<size_t>::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<BookReference> 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<size_t>::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<PolygonOpportunity>
|
||||
@@ -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<PImpl> me;
|
||||
|
||||
@@ -7,22 +7,22 @@
|
||||
|
||||
namespace bts::spartan::mdp3 {
|
||||
|
||||
using _LegDef = std::tuple<MDP3SecurityID, MDP3Quantity>;
|
||||
using _LegDef = std::tuple<SecurityID, Quantity>;
|
||||
|
||||
using SyntheticDefinitionMap =
|
||||
std::unordered_map<MDP3SecurityID, std::vector<_LegDef>>;
|
||||
std::unordered_map<SecurityID, std::vector<_LegDef>>;
|
||||
|
||||
using ReverseLegMap =
|
||||
std::unordered_map<MDP3SecurityID, std::unordered_set<MDP3SecurityID>>;
|
||||
std::unordered_map<SecurityID, std::unordered_set<SecurityID>>;
|
||||
|
||||
using BookMap = std::
|
||||
unordered_map<MDP3SecurityID, std::tuple<size_t, SmallBook, SmallBook>>;
|
||||
unordered_map<SecurityID, std::tuple<size_t, SmallBook, SmallBook>>;
|
||||
|
||||
// leg sec id, event id (last change), leg qty, leg price mult, bids, asks
|
||||
using LegBookVec = std::vector<std::tuple<
|
||||
size_t,
|
||||
MDP3SecurityID,
|
||||
MDP3Quantity,
|
||||
SecurityID,
|
||||
Quantity,
|
||||
md::IntPrice,
|
||||
SmallBook,
|
||||
SmallBook>>;
|
||||
@@ -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<MDP3SecurityID>())
|
||||
rlm.emplace(std::get<0>(leg_tup), std::unordered_set<SecurityID>())
|
||||
.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<MDP3SecurityID> *
|
||||
synthetic_owners(MDP3SecurityID leg_id, const ReverseLegMap &reverse_legs) {
|
||||
const std::unordered_set<SecurityID> *
|
||||
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 <class TIter>
|
||||
std::unordered_set<MDP3SecurityID>
|
||||
std::unordered_set<SecurityID>
|
||||
synthetic_owners(TIter first, TIter last, const ReverseLegMap &reverse_legs) {
|
||||
std::unordered_set<MDP3SecurityID> all_owners;
|
||||
std::unordered_set<SecurityID> 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<size_t, SmallBook, SmallBook>
|
||||
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<MDP3SecurityID, size_t> leg_book_eids,
|
||||
SecurityID synthetic_id,
|
||||
std::map<SecurityID, size_t> 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<MDP3SecurityID> affected_sec_ids;
|
||||
std::vector<SecurityID> 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::tuple<MDP3Quantity, md::IntPrice, SmallBook, SmallBook>>
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, SmallBook, SmallBook>>
|
||||
leg_books_no_eid;
|
||||
std::map<MDP3SecurityID, size_t> leg_book_eid_map;
|
||||
std::map<SecurityID, size_t> 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<size_t, std::vector<SyntheticMBPUpdate>> &
|
||||
SyntheticBookRecorder::result() const {
|
||||
return _me->synthetic_book_history();
|
||||
}
|
||||
} // namespace bts::spartan::mdp3
|
||||
} // namespace bts::spartan::mdp3
|
||||
@@ -14,25 +14,25 @@ namespace bts::spartan::mdp3 {
|
||||
struct SyntheticMBPUpdate {
|
||||
SyntheticMBPUpdate();
|
||||
SyntheticMBPUpdate(
|
||||
MDP3SecurityID synthetic_id,
|
||||
std::map<MDP3SecurityID, size_t> leg_book_eids,
|
||||
SecurityID synthetic_id,
|
||||
std::map<SecurityID, size_t> 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<tuple> 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<MDP3SecurityID, size_t> leg_book_eids;
|
||||
std::map<SecurityID, size_t> leg_book_eids;
|
||||
SmallBook bids;
|
||||
SmallBook asks;
|
||||
};
|
||||
|
||||
struct SyntheticBookRecorder : IChannelObserver {
|
||||
SyntheticBookRecorder(std::unordered_map<
|
||||
MDP3SecurityID,
|
||||
std::vector<std::tuple<MDP3SecurityID, MDP3Quantity>>>
|
||||
SecurityID,
|
||||
std::vector<std::tuple<SecurityID, Quantity>>>
|
||||
synthetic_def);
|
||||
~SyntheticBookRecorder();
|
||||
void on_recovery_complete(InitialSnapshot const &snap) override;
|
||||
|
||||
@@ -11,12 +11,12 @@
|
||||
|
||||
namespace bts::spartan::mdp3::tests {
|
||||
using LegMarkets =
|
||||
std::vector<std::tuple<MDP3Quantity, md::IntPrice, SmallBook>>;
|
||||
std::vector<std::tuple<Quantity, md::IntPrice, SmallBook>>;
|
||||
|
||||
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<LegMarkets> &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<LegMarkets> &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<LegMarkets> &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
|
||||
} // namespace bts::spartan::mdp3::tests
|
||||
@@ -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<mdp3::MDP3SecurityID, std::string> 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<mdp3::SecurityID, std::string> 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<InputLeg> 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<PolyInstrument> 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;
|
||||
|
||||
@@ -17,8 +17,8 @@ using namespace bts::spartan::mdp3;
|
||||
namespace bts::spartan::sql::adapters::polygon_defs {
|
||||
|
||||
using PolygonDefs = std::unordered_map<
|
||||
MDP3SecurityID,
|
||||
std::vector<std::tuple<MDP3SecurityID, MDP3Quantity>>>;
|
||||
SecurityID,
|
||||
std::vector<std::tuple<SecurityID, Quantity>>>;
|
||||
// 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<void(Row &)> on_row([&](auto &r) {
|
||||
res.emplace(
|
||||
MDP3SecurityID(r.pid),
|
||||
std::vector<std::tuple<MDP3SecurityID, MDP3Quantity>>())
|
||||
SecurityID(r.pid),
|
||||
std::vector<std::tuple<SecurityID, Quantity>>())
|
||||
.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<int> &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
|
||||
} // namespace bts::spartan::sql::adapters::polygon_defs
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
namespace bts::spartan::sql::adapters::polygon_defs {
|
||||
std::unordered_map<
|
||||
mdp3::MDP3SecurityID,
|
||||
std::vector<std::tuple<mdp3::MDP3SecurityID, mdp3::MDP3Quantity>>>
|
||||
mdp3::SecurityID,
|
||||
std::vector<std::tuple<mdp3::SecurityID, mdp3::Quantity>>>
|
||||
read_sql(const char *db_path, const char *legs_query);
|
||||
|
||||
std::unordered_map<
|
||||
mdp3::MDP3SecurityID,
|
||||
std::vector<std::tuple<mdp3::MDP3SecurityID, mdp3::MDP3Quantity>>>
|
||||
mdp3::SecurityID,
|
||||
std::vector<std::tuple<mdp3::SecurityID, mdp3::Quantity>>>
|
||||
read_sql(const char *db_path, const std::unordered_set<int> &ids);
|
||||
} // namespace bts::spartan::sql::adapters::polygon_defs
|
||||
} // namespace bts::spartan::sql::adapters::polygon_defs
|
||||
Reference in new issue
Block a user