ITCHCPP 1.6.0
High-Performance NASDAQ TotalView-ITCH 5.0 Parser & Market-Data Platform
Loading...
Searching...
No Matches
itch::book::L3Book Class Reference

A single-symbol, order-level (L3) limit order book with allocation-light internals. More...

#include <l3_book.hpp>

Public Member Functions

 L3Book (std::string symbol={})
 Constructs a book, optionally tagged with its stock symbol.
 
auto set_symbol (std::string symbol) -> void
 Sets the stock symbol associated with this book.
 
auto symbol () const noexcept -> const std::string &
 The stock symbol associated with this book (may be empty).
 
auto add_order (std::uint64_t reference_number, Side side, std::uint32_t shares, std::uint32_t price) -> void
 Adds a new resting order to the book (ITCH A/F).
 
auto execute_order (std::uint64_t reference_number, std::uint32_t shares) -> std::uint32_t
 Removes shares from an order on execution (ITCH E/C), deleting it when fully filled.
 
auto reduce_order (std::uint64_t reference_number, std::uint32_t shares) -> std::uint32_t
 Removes shares from an order on a partial cancel (ITCH X), deleting it when it reaches zero.
 
auto delete_order (std::uint64_t reference_number) -> void
 Deletes an order in its entirety (ITCH D).
 
auto replace_order (std::uint64_t old_reference_number, std::uint64_t new_reference_number, std::uint32_t shares, std::uint32_t price) -> void
 Replaces an order with a new reference number, size, and price on the same side (ITCH U).
 
auto contains (std::uint64_t reference_number) const -> bool
 Whether an order with the given reference number is resting.
 
auto order_price (std::uint64_t reference_number) const -> std::optional< std::uint32_t >
 The raw limit price of a resting order, if present.
 
auto order_side (std::uint64_t reference_number) const -> std::optional< Side >
 The side of a resting order, if present.
 
auto bbo () const -> Bbo
 The current best bid and offer.
 
auto depth (Side side, std::size_t max_levels=0) const -> std::vector< DepthLevel >
 Aggregated L2 depth for a side, best level first.
 
auto orders_at (Side side, std::uint32_t price) const -> std::vector< OrderView >
 The resting orders at a given price on a side, in time priority.
 
auto level_count (Side side) const noexcept -> std::size_t
 The number of active price levels on a side.
 
auto empty () const noexcept -> bool
 Whether the book has no resting orders on either side.
 

Detailed Description

A single-symbol, order-level (L3) limit order book with allocation-light internals.

Unlike the original LimitOrderBook, which stored each order in a std::shared_ptr inside a std::list and each price level in a std::map, this engine holds orders in a reusable object pool (a flat vector with a free list) linked into intrusive FIFO queues, and keeps each side's price levels in a flat, sorted vector. There is no per-order heap allocation, no atomic refcount, and no per-level node allocation on the hot path; order lookup by reference number is O(1) and the best bid/offer is the front of a ladder.

Definition at line 72 of file l3_book.hpp.

Constructor & Destructor Documentation

◆ L3Book()

itch::book::L3Book::L3Book ( std::string  symbol = {})
explicit

Constructs a book, optionally tagged with its stock symbol.

Parameters
symbolThe ticker symbol to associate with the book (may be empty).

Definition at line 8 of file l3_book.cpp.

Member Function Documentation

◆ set_symbol()

auto itch::book::L3Book::set_symbol ( std::string  symbol) -> void
inline

Sets the stock symbol associated with this book.

Parameters
symbolThe ticker symbol to associate with the book.

Definition at line 81 of file l3_book.hpp.

References symbol().

◆ symbol()

auto itch::book::L3Book::symbol ( ) const -> const std::string&
inlinenoexcept

The stock symbol associated with this book (may be empty).

Returns
Const reference to the associated ticker symbol.

Definition at line 85 of file l3_book.hpp.

Referenced by set_symbol(), and itch::book::BookManager::symbol_for_locate().

◆ add_order()

auto itch::book::L3Book::add_order ( std::uint64_t  reference_number,
Side  side,
std::uint32_t  shares,
std::uint32_t  price 
) -> void

Adds a new resting order to the book (ITCH A/F).

Parameters
reference_numberExchange order reference number identifying the new order.
sideThe side of the book the order rests on.
sharesThe number of shares in the new order.
priceThe raw (unscaled) limit price of the new order.

Definition at line 93 of file l3_book.cpp.

References itch::book::OrderIndex::NPOS, price, reference_number, shares, and side.

◆ execute_order()

auto itch::book::L3Book::execute_order ( std::uint64_t  reference_number,
std::uint32_t  shares 
) -> std::uint32_t

Removes shares from an order on execution (ITCH E/C), deleting it when fully filled.

Returns the shares actually removed.

Parameters
reference_numberExchange order reference number of the order being executed against.
sharesThe number of shares to remove from the order.
Returns
The number of shares actually removed (may be less than shares if the order does not have that many resting).

Definition at line 150 of file l3_book.cpp.

References itch::book::OrderIndex::NPOS, reference_number, and shares.

◆ reduce_order()

auto itch::book::L3Book::reduce_order ( std::uint64_t  reference_number,
std::uint32_t  shares 
) -> std::uint32_t

Removes shares from an order on a partial cancel (ITCH X), deleting it when it reaches zero.

Returns the shares actually removed.

Parameters
reference_numberExchange order reference number of the order being reduced.
sharesThe number of shares to remove from the order.
Returns
The number of shares actually removed (may be less than shares if the order does not have that many resting).

Definition at line 173 of file l3_book.cpp.

References reference_number, and shares.

◆ delete_order()

auto itch::book::L3Book::delete_order ( std::uint64_t  reference_number) -> void

Deletes an order in its entirety (ITCH D).

Parameters
reference_numberExchange order reference number of the order to delete.

Definition at line 178 of file l3_book.cpp.

References itch::book::OrderIndex::NPOS, and reference_number.

◆ replace_order()

auto itch::book::L3Book::replace_order ( std::uint64_t  old_reference_number,
std::uint64_t  new_reference_number,
std::uint32_t  shares,
std::uint32_t  price 
) -> void

Replaces an order with a new reference number, size, and price on the same side (ITCH U).

Parameters
old_reference_numberExchange order reference number of the order being replaced.
new_reference_numberExchange order reference number assigned to the replacement order.
sharesThe number of shares in the replacement order.
priceThe raw (unscaled) limit price of the replacement order.

Definition at line 188 of file l3_book.cpp.

References itch::book::OrderIndex::NPOS, price, shares, and side.

◆ contains()

auto itch::book::L3Book::contains ( std::uint64_t  reference_number) const -> bool

Whether an order with the given reference number is resting.

Parameters
reference_numberExchange order reference number to look up.
Returns
True if an order with reference_number is resting, false otherwise.

Definition at line 203 of file l3_book.cpp.

References reference_number.

◆ order_price()

auto itch::book::L3Book::order_price ( std::uint64_t  reference_number) const -> std::optional<std::uint32_t>

The raw limit price of a resting order, if present.

Parameters
reference_numberExchange order reference number to look up.
Returns
The order's raw limit price, or std::nullopt if no such order is resting.

Definition at line 207 of file l3_book.cpp.

References itch::book::OrderIndex::NPOS, and reference_number.

◆ order_side()

auto itch::book::L3Book::order_side ( std::uint64_t  reference_number) const -> std::optional<Side>

The side of a resting order, if present.

Parameters
reference_numberExchange order reference number to look up.
Returns
The order's side, or std::nullopt if no such order is resting.

Definition at line 215 of file l3_book.cpp.

References itch::book::OrderIndex::NPOS, and reference_number.

◆ bbo()

auto itch::book::L3Book::bbo ( ) const -> Bbo

The current best bid and offer.

Returns
The book's current best bid and offer snapshot.

Definition at line 223 of file l3_book.cpp.

References itch::book::Bbo::has_bid.

◆ depth()

auto itch::book::L3Book::depth ( Side  side,
std::size_t  max_levels = 0 
) const -> std::vector<DepthLevel>

Aggregated L2 depth for a side, best level first.

Parameters
sideThe side to report.
max_levelsThe maximum number of levels to return (0 == all).
Returns
The requested side's price levels, best (top of book) first.

Definition at line 238 of file l3_book.cpp.

References itch::book::DepthLevel::price, and side.

◆ orders_at()

auto itch::book::L3Book::orders_at ( Side  side,
std::uint32_t  price 
) const -> std::vector<OrderView>

The resting orders at a given price on a side, in time priority.

Parameters
sideThe side to query.
priceThe raw (unscaled) limit price to query.
Returns
The resting orders at price on side, oldest first.

Definition at line 253 of file l3_book.cpp.

References price, itch::book::OrderView::reference_number, and side.

◆ level_count()

auto itch::book::L3Book::level_count ( Side  side) const -> std::size_t
noexcept

The number of active price levels on a side.

Parameters
sideThe side to query.
Returns
The count of active price levels on side.

Definition at line 273 of file l3_book.cpp.

References side.

◆ empty()

auto itch::book::L3Book::empty ( ) const -> bool
inlinenoexcept

Whether the book has no resting orders on either side.

Returns
True if no orders are resting on either side, false otherwise.

Definition at line 179 of file l3_book.hpp.

References itch::book::OrderIndex::empty().


The documentation for this class was generated from the following files: