9 #ifndef CPPTRADER_MATCHING_ORDER_BOOK_H
10 #define CPPTRADER_MATCHING_ORDER_BOOK_H
15 #include "memory/allocator_pool.h"
34 typedef CppCommon::BinTreeAVL<LevelNode, std::less<LevelNode>>
Levels;
45 explicit operator bool() const noexcept {
return !
empty(); }
51 size_t size() const noexcept {
return _bids.size() + _asks.size() + _buy_stop.size() + _sell_stop.size() + _trailing_buy_stop.size() + _trailing_sell_stop.size(); }
86 template <
class TOutputStream>
148 LevelUpdate ReduceOrder(
OrderNode* order_ptr, uint64_t quantity, uint64_t hidden, uint64_t visible);
164 void ReduceStopOrder(
OrderNode* order_ptr, uint64_t quantity, uint64_t hidden, uint64_t visible);
165 void DeleteStopOrder(
OrderNode* order_ptr);
170 Levels _trailing_buy_stop;
171 Levels _trailing_sell_stop;
179 void AddTrailingStopOrder(
OrderNode* order_ptr);
180 void ReduceTrailingStopOrder(
OrderNode* order_ptr, uint64_t quantity, uint64_t hidden, uint64_t visible);
181 void DeleteTrailingStopOrder(
OrderNode* order_ptr);
184 uint64_t CalculateTrailingStopPrice(
const Order& order)
const noexcept;
187 uint64_t _last_bid_price;
188 uint64_t _last_ask_price;
189 uint64_t _matching_bid_price;
190 uint64_t _matching_ask_price;
191 uint64_t _trailing_bid_price;
192 uint64_t _trailing_ask_price;
195 uint64_t GetMarketPriceBid() const noexcept;
196 uint64_t GetMarketPriceAsk() const noexcept;
197 uint64_t GetMarketTrailingStopPriceBid() const noexcept;
198 uint64_t GetMarketTrailingStopPriceAsk() const noexcept;
199 void UpdateLastPrice(const
Order& order, uint64_t price) noexcept;
200 void UpdateMatchingPrice(const
Order& order, uint64_t price) noexcept;
201 void ResetMatchingPrice() noexcept;
207 #include "order_book.inl"
const LevelNode * best_ask() const noexcept
Get the order book best ask price level.
const LevelNode * best_buy_stop() const noexcept
Get the order book best buy stop order price level.
const LevelNode * GetAsk(uint64_t price) const noexcept
Get the order book ask price level with the given price.
const LevelNode * best_bid() const noexcept
Get the order book best bid price level.
OrderBook(MarketManager &manager, const Symbol &symbol)
bool empty() const noexcept
Is the order book empty?
const Levels & trailing_buy_stop() const noexcept
Get the order book trailing buy stop orders container.
const Levels & asks() const noexcept
Get the order book asks container.
const Levels & bids() const noexcept
Get the order book bids container.
size_t size() const noexcept
Get the order book size.
OrderBook & operator=(const OrderBook &)=delete
OrderBook & operator=(OrderBook &&)=delete
const LevelNode * GetTrailingBuyStopLevel(uint64_t price) const noexcept
Get the order book trailing buy stop level with the given price.
const Levels & buy_stop() const noexcept
Get the order book buy stop orders container.
const LevelNode * GetBid(uint64_t price) const noexcept
Get the order book bid price level with the given price.
const LevelNode * GetSellStopLevel(uint64_t price) const noexcept
Get the order book sell stop level with the given price.
const Levels & trailing_sell_stop() const noexcept
Get the order book trailing sell stop orders container.
const Symbol & symbol() const noexcept
Get the order book symbol.
const LevelNode * GetTrailingSellStopLevel(uint64_t price) const noexcept
Get the order book trailing sell stop level with the given price.
const Levels & sell_stop() const noexcept
Get the order book sell stop orders container.
const LevelNode * best_sell_stop() const noexcept
Get the order book best sell stop order price level.
OrderBook(const OrderBook &)=delete
const LevelNode * GetBuyStopLevel(uint64_t price) const noexcept
Get the order book buy stop level with the given price.
const LevelNode * best_trailing_sell_stop() const noexcept
Get the order book best trailing sell stop order price level.
const LevelNode * best_trailing_buy_stop() const noexcept
Get the order book best trailing buy stop order price level.
OrderBook(OrderBook &&)=delete
CppCommon::BinTreeAVL< LevelNode, std::less< LevelNode > > Levels
Price level container.
friend TOutputStream & operator<<(TOutputStream &stream, const OrderBook &order_book)
C++ Trader project definitions.