Skip to content

Commit

Permalink
Moved create_bots up in the stack
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenewald committed Jan 9, 2025
1 parent fb26f46 commit 416ae20
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion exchange/src/exchange/config/dynamic/ticker_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace nutc::exchange {

enum class BotType { market_maker = 0, retail = 1 };
enum class BotType : std::uint8_t { market_maker = 0, retail = 1 };

struct bot_config {
const BotType TYPE;
Expand Down
3 changes: 2 additions & 1 deletion exchange/src/exchange/orders/ticker_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,11 @@ TickerContainer::create_tickers(
// this is really bad. fix soon
std::unordered_map<std::size_t, TickerData> ticker_map;
for (const auto& config : configs) {
auto bots = create_bot_containers(traders, config.TICKER, config.BOTS);
ticker_map.emplace(
std::piecewise_construct,
std::forward_as_tuple(std::to_underlying(config.TICKER)),
std::forward_as_tuple(traders, config)
std::forward_as_tuple(config.TICKER, config.STARTING_PRICE, std::move(bots))
);
}
for (std::size_t ticker = 0; ticker < common::TICKERS.size(); ticker++) {
Expand Down
14 changes: 14 additions & 0 deletions exchange/src/exchange/orders/ticker_container.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ class TickerContainer {
static std::vector<TickerData> create_tickers();
static std::vector<TickerData>
create_tickers(const std::vector<ticker_config>& configs, TraderContainer& traders);

static std::vector<BotContainer>
create_bot_containers(
TraderContainer& trader_container, common::Ticker ticker,
const std::vector<bot_config>& configs
)
{
std::vector<BotContainer> bot_containers;
bot_containers.reserve(configs.size());
for (const bot_config& bot_config : configs) {
bot_containers.emplace_back(ticker, trader_container, bot_config);
}
return bot_containers;
}
};

} // namespace nutc::exchange
25 changes: 7 additions & 18 deletions exchange/src/exchange/orders/ticker_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ class TickerData {
std::vector<BotContainer> bot_containers_;

public:
explicit TickerData(TraderContainer& traders, const ticker_config& config) :
limit_orderbook_{config.TICKER}, theo_generator_{config.STARTING_PRICE},
bot_containers_{create_bot_containers(traders, config.TICKER, config.BOTS)}
explicit TickerData(
common::Ticker ticker, common::decimal_price starting_price,
std::vector<BotContainer> bots
) :
limit_orderbook_{ticker}, theo_generator_{starting_price},
bot_containers_{std::move(bots)}
{}

// TODO: check where this is used and if we can get rid of it
explicit TickerData(common::Ticker ticker) : limit_orderbook_{ticker} {}

CompositeOrderBook&
Expand Down Expand Up @@ -55,21 +59,6 @@ class TickerData {
{
return theo_generator_.get_magnitude();
}

private:
static std::vector<BotContainer>
create_bot_containers(
TraderContainer& trader_container, common::Ticker ticker,
const std::vector<bot_config>& configs
)
{
std::vector<BotContainer> bot_containers;
bot_containers.reserve(configs.size());
for (const bot_config& bot_config : configs) {
bot_containers.emplace_back(ticker, trader_container, bot_config);
}
return bot_containers;
}
};

} // namespace nutc::exchange
4 changes: 2 additions & 2 deletions exchange/src/linter/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
*/
template <class T, class M>
static inline constexpr ptrdiff_t
offset_of_impl(const M T::*member)
offset_of_impl(const M T::* member)
{
return reinterpret_cast<ptrdiff_t>(&(reinterpret_cast<T*>(0)->*member));
}

template <class T, class M>
static inline constexpr T*
container_of_impl(M* ptr, const M T::*member)
container_of_impl(M* ptr, const M T::* member)
{
return reinterpret_cast<T*>(
reinterpret_cast<intptr_t>(ptr) - offset_of_impl(member)
Expand Down

0 comments on commit 416ae20

Please sign in to comment.