From 61d1769b0fe799fc8606efdf9a0d6b8d2afa03a1 Mon Sep 17 00:00:00 2001 From: Steven Ewald Date: Thu, 9 Jan 2025 10:47:51 -0600 Subject: [PATCH] Add exchange_state --- exchange/src/exchange/exchange_state.hpp | 18 +++++ exchange/src/exchange/main.cpp | 22 ++--- .../matching_cycle/base/base_cycle.cpp | 10 +-- .../matching_cycle/base/base_cycle.hpp | 14 ++-- .../exchange/matching_cycle/dev/dev_cycle.hpp | 9 +-- .../matching_cycle/sandbox/sandbox_cycle.hpp | 7 +- .../src/exchange/orders/ticker_container.cpp | 2 +- exchange/test/src/integration/tests/basic.cpp | 80 ++++++++++--------- .../src/integration/tests/cancellation.cpp | 20 ++--- .../test/src/integration/tests/messaging.cpp | 13 +-- exchange/test/src/util/helpers/test_cycle.hpp | 5 +- 11 files changed, 113 insertions(+), 87 deletions(-) create mode 100644 exchange/src/exchange/exchange_state.hpp diff --git a/exchange/src/exchange/exchange_state.hpp b/exchange/src/exchange/exchange_state.hpp new file mode 100644 index 00000000..3fb82cca --- /dev/null +++ b/exchange/src/exchange/exchange_state.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include "exchange/config/dynamic/ticker_config.hpp" +#include "exchange/orders/ticker_container.hpp" +#include "exchange/traders/trader_container.hpp" + +namespace nutc::exchange { +struct exchange_state { + TraderContainer traders; + TickerContainer tickers; + + explicit exchange_state(const std::vector& configs) : + tickers{configs, traders} + {} + + exchange_state() : tickers{{}, traders} {} +}; +} // namespace nutc::exchange diff --git a/exchange/src/exchange/main.cpp b/exchange/src/exchange/main.cpp index eca1a3d9..724efb62 100644 --- a/exchange/src/exchange/main.cpp +++ b/exchange/src/exchange/main.cpp @@ -4,11 +4,11 @@ #include "exchange/algos/algo_manager.hpp" #include "exchange/config/dynamic/argparse.hpp" #include "exchange/config/dynamic/config.hpp" +#include "exchange/exchange_state.hpp" #include "exchange/matching_cycle/base/base_cycle.hpp" #include "exchange/matching_cycle/cycle_interface.hpp" #include "exchange/matching_cycle/dev/dev_cycle.hpp" #include "exchange/matching_cycle/sandbox/sandbox_cycle.hpp" -#include "exchange/traders/trader_container.hpp" #include @@ -18,27 +18,25 @@ namespace { using namespace nutc::exchange; // NOLINT std::unique_ptr -create_cycle(TraderContainer& traders, const auto& mode) +create_cycle(exchange_state& state, const auto& mode) { using nutc::common::Mode; - const auto& ticker_config = Config::get().get_tickers(); double order_fee = Config::get().constants().ORDER_FEE; - auto tickers = TickerContainer(ticker_config, traders); auto max_order_volume = Config::get().constants().MAX_CUMULATIVE_OPEN_ORDER_VOLUME; switch (mode) { case Mode::normal: return std::make_unique( - tickers, traders, order_fee, max_order_volume + state, order_fee, max_order_volume ); case Mode::sandbox: return std::make_unique( - tickers, traders, order_fee, max_order_volume + state, order_fee, max_order_volume ); case Mode::bots_only: case Mode::dev: return std::make_unique( - tickers, traders, order_fee, max_order_volume + state, order_fee, max_order_volume ); } @@ -64,10 +62,14 @@ main(int argc, const char** argv) std::signal(SIGPIPE, SIG_IGN); auto mode = process_arguments(argc, argv); - TraderContainer traders{}; - AlgoInitializer::get_algo_initializer(mode)->initialize_algo_management(traders); + const auto& ticker_config = Config::get().get_tickers(); + exchange_state state{ticker_config}; + + AlgoInitializer::get_algo_initializer(mode)->initialize_algo_management( + state.traders + ); - main_event_loop(create_cycle(traders, mode)); + main_event_loop(create_cycle(state, mode)); return 0; } diff --git a/exchange/src/exchange/matching_cycle/base/base_cycle.cpp b/exchange/src/exchange/matching_cycle/base/base_cycle.cpp index 41da2477..b1b48fa1 100644 --- a/exchange/src/exchange/matching_cycle/base/base_cycle.cpp +++ b/exchange/src/exchange/matching_cycle/base/base_cycle.cpp @@ -13,7 +13,7 @@ namespace nutc::exchange { void BaseMatchingCycle::before_cycle_(uint64_t) { - for (auto [symbol, ticker_data] : tickers_) { + for (auto [symbol, ticker_data] : state_.tickers) { ticker_data.generate_bot_orders(); } } @@ -47,7 +47,7 @@ BaseMatchingCycle::collect_orders(uint64_t) -> std::vector ); }; - std::for_each(traders_.begin(), traders_.end(), collect_orders); + std::for_each(state_.traders.begin(), state_.traders.end(), collect_orders); return orders; } @@ -58,7 +58,7 @@ BaseMatchingCycle::match_orders_(std::vector orders) std::vector matches; auto match_incoming_order = [&](OrderT& order) { - auto& ticker_data = tickers_[order.ticker]; + auto& ticker_data = state_.tickers[order.ticker]; auto& orderbook = ticker_data.get_orderbook(); if constexpr (std::is_same_v) { orderbook.remove_order(order.order_id); @@ -88,7 +88,7 @@ BaseMatchingCycle::get_orderbook_updates_() { std::vector ob_updates; - for (auto [symbol, info] : tickers_) { + for (auto [symbol, info] : state_.tickers) { auto tmp = info.get_orderbook().get_and_reset_updates(); std::ranges::copy(tmp, std::back_inserter(ob_updates)); } @@ -146,7 +146,7 @@ BaseMatchingCycle::send_market_updates_(const std::vector& matches } std::for_each( - traders_.begin(), traders_.end(), + state_.traders.begin(), state_.traders.end(), [&message = *update](GenericTrader& trader) { trader.send_message(message); } ); } diff --git a/exchange/src/exchange/matching_cycle/base/base_cycle.hpp b/exchange/src/exchange/matching_cycle/base/base_cycle.hpp index 0097f9b5..731bb166 100644 --- a/exchange/src/exchange/matching_cycle/base/base_cycle.hpp +++ b/exchange/src/exchange/matching_cycle/base/base_cycle.hpp @@ -1,4 +1,5 @@ #pragma once +#include "exchange/exchange_state.hpp" #include "exchange/matching_cycle/cycle_interface.hpp" #include "exchange/orders/ticker_container.hpp" #include "exchange/traders/trader_container.hpp" @@ -9,18 +10,17 @@ namespace nutc::exchange { * @brief Barebones matching cycle. Likely to be overridden for more logging */ class BaseMatchingCycle : public MatchingCycleInterface { - TickerContainer tickers_; - TraderContainer& traders_; + exchange_state& state_; common::decimal_price order_fee_; common::decimal_quantity max_cumulative_order_volume_; public: // Require transfer of ownership BaseMatchingCycle( - TickerContainer tickers, TraderContainer& traders, - common::decimal_price order_fee, common::decimal_quantity max_order_volume + exchange_state& state, common::decimal_price order_fee, + common::decimal_quantity max_order_volume ) : - tickers_(std::move(tickers)), traders_(traders), order_fee_(order_fee), + state_(state), order_fee_(order_fee), max_cumulative_order_volume_{max_order_volume} {} @@ -28,13 +28,13 @@ class BaseMatchingCycle : public MatchingCycleInterface { auto& get_tickers() { - return tickers_; + return state_.tickers; } TraderContainer& get_traders() { - return traders_; + return state_.traders; } void before_cycle_(uint64_t) override; diff --git a/exchange/src/exchange/matching_cycle/dev/dev_cycle.hpp b/exchange/src/exchange/matching_cycle/dev/dev_cycle.hpp index 2d8a9044..76dfbbc2 100644 --- a/exchange/src/exchange/matching_cycle/dev/dev_cycle.hpp +++ b/exchange/src/exchange/matching_cycle/dev/dev_cycle.hpp @@ -1,5 +1,6 @@ #pragma once +#include "exchange/exchange_state.hpp" #include "exchange/matching_cycle/base/base_cycle.hpp" #include "exchange/metrics/on_tick_metrics.hpp" #include "exchange/traders/trader_container.hpp" @@ -14,11 +15,9 @@ class DevMatchingCycle : public BaseMatchingCycle { public: DevMatchingCycle( - TickerContainer tickers, TraderContainer& traders, - common::decimal_price order_fee, common::decimal_quantity max_order_volume - ) : - BaseMatchingCycle(std::move(tickers), traders, order_fee, max_order_volume), - pusher(traders) + exchange_state& state, common::decimal_price order_fee, + common::decimal_quantity max_order_volume + ) : BaseMatchingCycle(state, order_fee, max_order_volume), pusher(state.traders) {} protected: diff --git a/exchange/src/exchange/matching_cycle/sandbox/sandbox_cycle.hpp b/exchange/src/exchange/matching_cycle/sandbox/sandbox_cycle.hpp index d9cea5ca..01e695db 100644 --- a/exchange/src/exchange/matching_cycle/sandbox/sandbox_cycle.hpp +++ b/exchange/src/exchange/matching_cycle/sandbox/sandbox_cycle.hpp @@ -1,5 +1,6 @@ #pragma once +#include "exchange/exchange_state.hpp" #include "exchange/matching_cycle/dev/dev_cycle.hpp" #include "exchange/sandbox_server/crow.hpp" #include "exchange/traders/trader_container.hpp" @@ -13,9 +14,9 @@ class SandboxMatchingCycle : public DevMatchingCycle { public: SandboxMatchingCycle( - TickerContainer tickers, TraderContainer& traders, - common::decimal_price order_fee, common::decimal_quantity max_order_volume - ) : DevMatchingCycle(std::move(tickers), traders, order_fee, max_order_volume) + exchange_state& state, common::decimal_price order_fee, + common::decimal_quantity max_order_volume + ) : DevMatchingCycle(state, order_fee, max_order_volume) {} private: diff --git a/exchange/src/exchange/orders/ticker_container.cpp b/exchange/src/exchange/orders/ticker_container.cpp index 6ff08805..45cd3d5a 100644 --- a/exchange/src/exchange/orders/ticker_container.cpp +++ b/exchange/src/exchange/orders/ticker_container.cpp @@ -101,7 +101,7 @@ std::vector TickerContainer::create_tickers() { std::vector result; - result.reserve(common::TICKERS.size()); + result.reserve(common::TICKERS.size()); for (std::size_t ticker = 0; ticker < common::TICKERS.size(); ticker++) { result.emplace_back(static_cast(ticker)); } diff --git a/exchange/test/src/integration/tests/basic.cpp b/exchange/test/src/integration/tests/basic.cpp index c9d901ae..a6153c66 100644 --- a/exchange/test/src/integration/tests/basic.cpp +++ b/exchange/test/src/integration/tests/basic.cpp @@ -1,5 +1,6 @@ #include "common/util.hpp" #include "config.hpp" +#include "exchange/exchange_state.hpp" #include "util/helpers/test_cycle.hpp" #include "util/helpers/test_trader.hpp" #include "util/macros.hpp" @@ -16,17 +17,17 @@ using common::Side::sell; class IntegrationBasicAlgo : public ::testing::TestWithParam { protected: - TraderContainer traders_; + exchange::exchange_state state_; }; TEST_P(IntegrationBasicAlgo, ConfirmOrderReceived) { - start_wrappers(traders_, GetParam(), "buy_tsla_at_100"); - auto trader2 = traders_.add_trader(0); + start_wrappers(state_.traders, GetParam(), "buy_tsla_at_100"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT trader2->add_order(limit_order{Ticker::ETH, sell, 100.0, 10.0}); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; cycle.wait_for_order(limit_order{Ticker::ETH, buy, 100.0, 10.0}); ASSERT_EQ( @@ -40,12 +41,12 @@ TEST_P(IntegrationBasicAlgo, ConfirmOrderReceived) TEST_P(IntegrationBasicAlgo, ConfirmOrderFeeApplied) { - start_wrappers(traders_, GetParam(), "buy_tsla_at_100"); - auto trader2 = traders_.add_trader(0); + start_wrappers(state_.traders, GetParam(), "buy_tsla_at_100"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT trader2->add_order(limit_order{Ticker::ETH, sell, 100.0, 10.0}); - TestMatchingCycle cycle{traders_, .5}; + TestMatchingCycle cycle{state_, .5}; cycle.wait_for_order(limit_order{Ticker::ETH, buy, 100.0, 10.0}); ASSERT_EQ( @@ -59,12 +60,12 @@ TEST_P(IntegrationBasicAlgo, ConfirmOrderFeeApplied) TEST_P(IntegrationBasicAlgo, RemoveIOCOrder) { - auto& trader1 = start_wrappers(traders_, GetParam(), "buy_tsla_at_100"); - auto trader2 = traders_.add_trader(0); + auto& trader1 = start_wrappers(state_.traders, GetParam(), "buy_tsla_at_100"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT trader2->add_order({Ticker::ETH, sell, 100.0, 100.0}); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; cycle.on_tick(0); usleep(500); @@ -78,37 +79,38 @@ TEST_P(IntegrationBasicAlgo, RemoveIOCOrder) TEST_P(IntegrationBasicAlgo, MarketOrderBuy) { - start_wrappers(traders_, GetParam(), "buy_market_order_1000"); - auto trader2 = traders_.add_trader(0); + start_wrappers(state_.traders, GetParam(), "buy_market_order_1000"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); trader2->add_order({Ticker::ETH, sell, 100.0, 100.0}); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; cycle.wait_for_order(limit_order{Ticker::BTC, buy, 1.0, 100.0}); } TEST_P(IntegrationBasicAlgo, MarketOrderSell) { - auto& trader1 = start_wrappers(traders_, GetParam(), "sell_market_order_1000"); - auto trader2 = traders_.add_trader(0); + auto& trader1 = + start_wrappers(state_.traders, GetParam(), "sell_market_order_1000"); + auto trader2 = state_.traders.add_trader(0); trader1.get_portfolio().modify_holdings(Ticker::ETH, 1000.0); trader2->add_order({Ticker::ETH, buy, 1.0, 100.0}); trader2->get_portfolio().modify_capital(1000.0); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; cycle.wait_for_order(limit_order{Ticker::BTC, buy, 1.0, 100.0}); } TEST_P(IntegrationBasicAlgo, ManyUpdates) { - start_wrappers(traders_, GetParam(), "confirm_1000"); - auto trader2 = traders_.add_trader(0); + start_wrappers(state_.traders, GetParam(), "confirm_1000"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 100000.0); // NOLINT - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; for (int i = 0; i < 10000; i++) { trader2->add_order({Ticker::ETH, sell, 1.0, static_cast(i)}); @@ -121,9 +123,9 @@ TEST_P(IntegrationBasicAlgo, ManyUpdates) TEST_P(IntegrationBasicAlgo, OrderVolumeLimitsPreventGoingAboveLimit) { - auto& trader1 = start_wrappers(traders_, GetParam(), "many_orders"); + auto& trader1 = start_wrappers(state_.traders, GetParam(), "many_orders"); - TestMatchingCycle cycle{traders_, 0.0, 10.0}; + TestMatchingCycle cycle{state_, 0.0, 10.0}; for (int i = 1; i < 21; i++) { cycle.wait_for_order(limit_order{Ticker::ETH, buy, 1.0, static_cast(i)} @@ -136,12 +138,12 @@ TEST_P(IntegrationBasicAlgo, OrderVolumeLimitsPreventGoingAboveLimit) TEST_P(IntegrationBasicAlgo, OnTradeUpdate) { - start_wrappers(traders_, GetParam(), "buy_tsla_on_trade"); + start_wrappers(state_.traders, GetParam(), "buy_tsla_on_trade"); - auto trader2 = traders_.add_trader(0); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 10000.0); // NOLINT - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; trader2->add_order({Ticker::ETH, sell, 100.0, 100.0}); @@ -153,12 +155,12 @@ TEST_P(IntegrationBasicAlgo, OnTradeUpdate) // Sanity check that it goes through the orderbook TEST_P(IntegrationBasicAlgo, MultipleLevelOrder) { - auto& trader1 = start_wrappers(traders_, GetParam(), "buy_tsla_at_100"); + auto& trader1 = start_wrappers(state_.traders, GetParam(), "buy_tsla_at_100"); - auto trader2 = traders_.add_trader(0); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; trader2->add_order({Ticker::ETH, sell, 55.0, 1.0}); trader2->add_order({Ticker::ETH, sell, 45.0, 1.0}); @@ -173,13 +175,13 @@ TEST_P(IntegrationBasicAlgo, MultipleLevelOrder) TEST_P(IntegrationBasicAlgo, OnAccountUpdateSell) { - auto& trader1 = start_wrappers(traders_, GetParam(), "sell_tsla_on_account"); + auto& trader1 = start_wrappers(state_.traders, GetParam(), "sell_tsla_on_account"); trader1.get_portfolio().modify_holdings(Ticker::ETH, 1000.0); - auto trader2 = traders_.add_trader(100000); + auto trader2 = state_.traders.add_trader(100000); trader2->add_order({Ticker::ETH, buy, 102.0, 102.0}); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; // obupdate triggers one user to place acommon::Side::buy order of 10 ABC at 102 cycle.wait_for_order(limit_order{Ticker::ETH, sell, 10.0, 100.0}); @@ -191,13 +193,13 @@ TEST_P(IntegrationBasicAlgo, OnAccountUpdateSell) TEST_P(IntegrationBasicAlgo, OnAccountUpdateBuy) { - start_wrappers(traders_, GetParam(), "buy_tsla_on_account"); + start_wrappers(state_.traders, GetParam(), "buy_tsla_on_account"); - auto trader2 = traders_.add_trader(0); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT trader2->add_order({Ticker::ETH, sell, 100.0, 100.0}); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; // obupdate triggers one user to place acommon::Side::buy order of 10 ABC at 102 cycle.wait_for_order(limit_order{Ticker::ETH, buy, 10.0, 102.0}); @@ -210,15 +212,15 @@ TEST_P(IntegrationBasicAlgo, AlgoStartDelay) { auto start = std::chrono::high_resolution_clock::now(); start_wrappers( - traders_, GetParam(), "buy_tsla_at_100", TEST_STARTING_CAPITAL, + state_.traders, GetParam(), "buy_tsla_at_100", TEST_STARTING_CAPITAL, TEST_CLIENT_WAIT_SECS ); - auto trader2 = traders_.add_trader(0); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT trader2->add_order({Ticker::ETH, sell, 100.0, 100.0}); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; cycle.wait_for_order(limit_order{Ticker::ETH, buy, 100.0, 10.0}); @@ -234,14 +236,14 @@ TEST_P(IntegrationBasicAlgo, AlgoStartDelay) // Disable trader and confirm it doesn't send any orders TEST_P(IntegrationBasicAlgo, DisableTrader) { - auto& trader1 = start_wrappers(traders_, GetParam(), "buy_tsla_at_100"); - auto trader2 = traders_.add_trader(0); + auto& trader1 = start_wrappers(state_.traders, GetParam(), "buy_tsla_at_100"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT trader2->add_order({Ticker::ETH, sell, 100.0, 100.0}); trader1.disable(); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; cycle.on_tick(0); sleep(1); diff --git a/exchange/test/src/integration/tests/cancellation.cpp b/exchange/test/src/integration/tests/cancellation.cpp index c225224c..c7b2b4b0 100644 --- a/exchange/test/src/integration/tests/cancellation.cpp +++ b/exchange/test/src/integration/tests/cancellation.cpp @@ -1,5 +1,6 @@ #include "common/types/messages/messages_wrapper_to_exchange.hpp" #include "common/util.hpp" +#include "exchange/exchange_state.hpp" #include "util/helpers/test_cycle.hpp" #include "util/helpers/test_trader.hpp" #include "util/macros.hpp" @@ -15,13 +16,13 @@ class IntegrationBasicCancellation : public ::testing::TestWithParam(0); + auto& trader1 = start_wrappers(state_.traders, GetParam(), "cancel_limit_order"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 100.0); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; auto order = cycle.wait_for_order(limit_order{Ticker::ETH, buy, 100.0, 10.0}); cycle.wait_for_order(common::cancel_order{common::Ticker::ETH, order.order_id}); @@ -47,10 +48,11 @@ TEST_P(IntegrationBasicCancellation, CancelMessagePreventsOrderFromExecuting) TEST_P(IntegrationBasicCancellation, OneOfTwoOrdersCancelledResultsInMatch) { - auto& trader1 = start_wrappers(traders_, GetParam(), "partial_cancel_limit_order"); - auto trader2 = traders_.add_trader(0); + auto& trader1 = + start_wrappers(state_.traders, GetParam(), "partial_cancel_limit_order"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 100.0); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; auto order = cycle.wait_for_order(limit_order{Ticker::ETH, buy, 100.0, 10.0}); // Assume non-cancelled order got through diff --git a/exchange/test/src/integration/tests/messaging.cpp b/exchange/test/src/integration/tests/messaging.cpp index 9b84678d..3676719c 100644 --- a/exchange/test/src/integration/tests/messaging.cpp +++ b/exchange/test/src/integration/tests/messaging.cpp @@ -1,4 +1,5 @@ #include "common/util.hpp" +#include "exchange/exchange_state.hpp" #include "util/helpers/test_cycle.hpp" #include "util/helpers/test_trader.hpp" #include "util/macros.hpp" @@ -12,17 +13,17 @@ using namespace nutc::common; class IntegrationMessaging : public ::testing::TestWithParam { protected: - TraderContainer traders_; + exchange::exchange_state state_; }; TEST_P(IntegrationMessaging, ConfirmGeneratedOrderIdIsNotSamePID) { - start_wrappers(traders_, GetParam(), "buy_tsla_at_100"); - auto trader2 = traders_.add_trader(0); + start_wrappers(state_.traders, GetParam(), "buy_tsla_at_100"); + auto trader2 = state_.traders.add_trader(0); trader2->get_portfolio().modify_holdings(Ticker::ETH, 1000.0); // NOLINT trader2->add_order(limit_order{Ticker::ETH, Side::sell, 100.0, 10.0}); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; auto order = cycle.wait_for_order(limit_order{Ticker::ETH, Side::buy, 100.0, 10.0}); @@ -35,13 +36,13 @@ TEST_P( IntegrationMessaging, ConfirmOrderTimestampIsNotOverwrittenByExchangeWhenReceived ) { - start_wrappers(traders_, GetParam(), "buy_eth"); + start_wrappers(state_.traders, GetParam(), "buy_eth"); usleep(50000); auto start = get_time(); - TestMatchingCycle cycle{traders_}; + TestMatchingCycle cycle{state_}; auto order = cycle.wait_for_order(limit_order{Ticker::ETH, Side::buy, 100.0, 10.0}); diff --git a/exchange/test/src/util/helpers/test_cycle.hpp b/exchange/test/src/util/helpers/test_cycle.hpp index dfc0b364..5ad3bd01 100644 --- a/exchange/test/src/util/helpers/test_cycle.hpp +++ b/exchange/test/src/util/helpers/test_cycle.hpp @@ -1,6 +1,7 @@ #pragma once #include "common/types/decimal.hpp" +#include "exchange/exchange_state.hpp" #include "exchange/matching_cycle/base/base_cycle.hpp" #include "exchange/traders/trader_container.hpp" #include "soft_equality.hpp" @@ -14,10 +15,10 @@ class TestMatchingCycle : public exchange::BaseMatchingCycle { public: TestMatchingCycle( - exchange::TraderContainer& traders, common::decimal_price order_fee = 0.0, + exchange::exchange_state& state, common::decimal_price order_fee = 0.0, common::decimal_quantity max_order_volume = std::numeric_limits::max() - ) : exchange::BaseMatchingCycle{{}, traders, order_fee, max_order_volume} + ) : exchange::BaseMatchingCycle{state, order_fee, max_order_volume} {} // Note: uses tick=0. If using something that relies on tick, it will not work