78 return compare_(a, b);
89 std::size_t interested_num_levels = 10,
90 std::size_t initial_order_capacity = 1024,
91 std::size_t initial_level_capacity = 32);
103 [[nodiscard]]
SymbolId symbol() const noexcept {
return symbol_; }
120 uint64_t seq_num = 0,
bool is_last_in_batch =
true);
135 Timestamp timestamp, uint64_t priority = 0, uint64_t seq_num = 0,
bool is_last_in_batch =
true);
151 Timestamp new_timestamp, uint64_t new_priority = 0,
152 uint64_t seq_num = 0,
bool is_last_in_batch =
true);
162 bool deleteOrder(
OrderId order_id,
Timestamp timestamp, uint64_t seq_num = 0,
bool is_last_in_batch =
true);
174 uint64_t seq_num = 0,
bool is_last_in_batch =
true);
189 [[nodiscard]] const detail::PriceLevelL3* getBestBid() const noexcept;
193 [[nodiscard]] const detail::PriceLevelL3* getBestAsk() const noexcept;
197 [[nodiscard]]
TopOfBook getTopOfBook() const noexcept;
205 return levels_[side];
213 [[nodiscard]] std::vector<detail::PriceLevelL2> getLevelsL2(
Side side, std::size_t depth = 0)
const;
220 [[nodiscard]] std::pair<const detail::PriceLevelL3*, uint16_t> getLevel(
Side side,
Price price)
const noexcept;
222 [[nodiscard]] std::pair<detail::PriceLevelL3*, uint16_t> getLevel(
Side side,
Price price)
noexcept;
233 [[nodiscard]] std::size_t levelCount(
Side side)
const noexcept;
237 [[nodiscard]] std::size_t
orderCount() const noexcept {
return order_map_.size(); }
242 [[nodiscard]] std::size_t orderCount(
Side side)
const noexcept;
247 [[nodiscard]]
bool isEmpty(
Side side)
const noexcept;
251 [[nodiscard]]
bool isEmpty() const noexcept;
267 observers_.addObserver(std::move(observer));
271 return observers_.removeObserver(observer);
275 observers_.clearObservers();
279 return observers_.observerCount();
285 return last_seq_num_;
296 std::tuple<detail::PriceLevelL3*, uint16_t, bool> getOrCreateLevel(
Side side,
Price price);
299 bool removeLevelIfEmpty(
Side side,
Price price)
noexcept;
302 void releaseSide(
Side side)
noexcept;
306 Timestamp timestamp, uint16_t level_index, uint8_t change_flags, uint64_t seq_num)
const;
309 void notifyOrderDelete(
const detail::Order* order,
Timestamp timestamp, uint16_t level_index, uint8_t change_flags, uint64_t seq_num)
const;
312 [[nodiscard]] uint16_t calculateLevelIndex(
Side side,
Price price)
const noexcept;
315 void notifyTrade(
OrderId passive_order_id,
OrderId aggressive_order_id,
319 void notifyPriceLevelUpdate(
Timestamp timestamp,
Side side,
Price price,
Quantity total_quantity,
size_t order_count, uint16_t level_index, uint8_t change_flags, uint64_t seq_num)
const;
324 void notifyTopOfBookIfChanged(
Timestamp timestamp);
352#ifdef SLICK_ORDERBOOK_HEADER_ONLY
Base interface for orderbook observers Observers receive callbacks for orderbook events.
Observer manager for notifying multiple observers Uses type erasure to support both concept-based and...
Level 3 OrderBook - Individual order tracking with price-time priority.
OrderBookL3(const OrderBookL3 &)=delete
detail::OrderMap order_map_
uint64_t getLastSeqNum() const noexcept
Get last processed sequence number.
detail::FlatMap< Price, detail::PriceLevelL3, PriceComparator > PriceLevelMap
std::size_t observerCount() const noexcept
std::size_t interested_num_levels_
detail::ObjectPool< detail::Order > order_pool_
OrderBookL3(OrderBookL3 &&) noexcept=default
void clearObservers() noexcept
std::array< PriceLevelMap, SideCount > levels_
ObserverManager observers_
const detail::PriceLevelL3 * getBestLevel() const noexcept
Get the best price level for a given side.
std::size_t orderCount() const noexcept
Get total number of orders.
bool removeObserver(const std::shared_ptr< IOrderBookObserver > &observer)
OrderBookL3 & operator=(const OrderBookL3 &)=delete
Object pool for zero-allocation management of frequently created/destroyed objects.
Hash table for fast OrderId -> Order* lookup Uses std::unordered_map for simplicity and performance P...
#define SLICK_NAMESPACE_END
#define SLICK_DLL_INTERFACE_WARNINGS_PUSH
#define SLICK_CACHE_ALIGNED
#define SLICK_NAMESPACE_BEGIN
#define SLICK_DLL_INTERFACE_WARNINGS_POP
#define SLICK_ASSERT(expr)
std::map< Key, Value, Compare > FlatMap
Cache-friendly sorted map.
int64_t Quantity
Quantity type - volume or size.
int64_t Price
Price type - fixed-point representation Example: For 4 decimal places, price = actual_price * 10000 T...
uint64_t OrderId
Unique order identifier.
Side
Order side - using enum for easy array indexing.
constexpr uint16_t INVALID_INDEX
uint16_t SymbolId
Symbol identifier - can be hash or sequential ID.
uint64_t Timestamp
Timestamp in nanoseconds since epoch.
bool operator()(Price a, Price b) const noexcept
PriceComparator(Side side)
std::function< bool(Price, Price)> Comparator
Top-of-book snapshot - best bid and ask.
Order structure for Level 3 orderbook Uses intrusive list design for zero-allocation order queues at ...
Price level for Level 3 orderbook (order-by-order) Maintains a queue of individual orders at this pri...