ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
Loading...
Searching...
No Matches
b2bits::Aggregator< _Traits, _Side > Class Template Reference

Order book price level aggregator. More...

Detailed Description

template<typename _Traits, typename _Traits::SideType _Side>
class b2bits::Aggregator< _Traits, _Side >

Order book price level aggregator.

Maintains aggregated price levels for one side of an order book (buy or sell). The aggregator keeps the best N price levels (configured at construction) and tracks additional levels beyond that depth in a separate overflow set.

Key operations:

  • add_order: Add quantity at a price (creates level if needed)
  • reduce_qty: Remove quantity from a price (removes level if zero)
  • modify: Change order price and/or quantity atomically
  • play: Replay all current levels to a handler

The aggregator automatically:

  • Sorts levels by best price first
  • Promotes overflow levels when top levels are removed
  • Notifies handlers of all level changes
  • Maintains order counts at each level
Template Parameters
_TraitsBook traits defining types (PriceType, QtyType, etc.)
_SideSide character: 'B' for buy, 'S' for sell
Note
Non-copyable: Aggregator cannot be copied
Maximum depth is fixed at construction
Example:
using BookTraits = DefaultBookTraits;
// Buy side aggregator with depth=10
Aggregator<BookTraits, 'B'> buy_book(10);
// Add orders
buy_book.add_order([](auto ts, auto& update) {
std::cout << "Level " << update.index_
<< " @ " << update.price_
<< " = " << update.qty_ << "\n";
}, price, quantity, timestamp);
// Reduce quantity
buy_book.reduce_qty(handler, price, qty_to_remove, order_removed, ts);
Default traits for order book.
Definition Aggregator.h:83

#include <core/src/Aggregator.h>

Public Types

using Traits = _Traits
 Book traits type.
using PriceType = typename Traits::PriceType
 Price type.
using QtyType = typename Traits::QtyType
 Quantity type.
using CounterType = typename Traits::CounterType
 Order counter type.
using Timestamp = typename Traits::Timestamp
 Timestamp type.

Public Member Functions

 Aggregator (std::uint16_t depth=5)
 Construct aggregator with specified depth.
void clear ()
 Clear all price levels.
template<class Handler>
void play (Handler &&handler) const
 Replay all current levels to handler.
template<class Handler>
void add_order (Handler &&handler, PriceType price, QtyType qty, Timestamp timestamp=0)
 Add order quantity at a price.
template<class Handler>
void reduce_qty (Handler &&handler, PriceType price, QtyType qty, bool order_removed, Timestamp timestamp=0)
 Reduce quantity at a price.
template<class Handler>
void modify (Handler &&handler, PriceType old_price, PriceType new_price, QtyType old_qty, QtyType new_qty, Timestamp timestamp=0)
 Modify an order (change price and/or quantity).
void reset ()
 Reset aggregator to initial state.

Member Typedef Documentation

◆ CounterType

template<typename _Traits, typename _Traits::SideType _Side>
using b2bits::Aggregator< _Traits, _Side >::CounterType = typename Traits::CounterType

Order counter type.

◆ PriceType

template<typename _Traits, typename _Traits::SideType _Side>
using b2bits::Aggregator< _Traits, _Side >::PriceType = typename Traits::PriceType

Price type.

◆ QtyType

template<typename _Traits, typename _Traits::SideType _Side>
using b2bits::Aggregator< _Traits, _Side >::QtyType = typename Traits::QtyType

Quantity type.

◆ Timestamp

template<typename _Traits, typename _Traits::SideType _Side>
using b2bits::Aggregator< _Traits, _Side >::Timestamp = typename Traits::Timestamp

Timestamp type.

◆ Traits

template<typename _Traits, typename _Traits::SideType _Side>
using b2bits::Aggregator< _Traits, _Side >::Traits = _Traits

Book traits type.

Constructor & Destructor Documentation

◆ Aggregator()

template<typename _Traits, typename _Traits::SideType _Side>
b2bits::Aggregator< _Traits, _Side >::Aggregator ( std::uint16_t depth = 5)
inline

Construct aggregator with specified depth.

Creates an aggregator that maintains up to 'depth' price levels. Additional levels beyond this depth are tracked in overflow storage.

Parameters
depthMaximum number of price levels to maintain (default: 5)

Member Function Documentation

◆ add_order()

template<typename _Traits, typename _Traits::SideType _Side>
template<class Handler>
void b2bits::Aggregator< _Traits, _Side >::add_order ( Handler && handler,
PriceType price,
QtyType qty,
Timestamp timestamp = 0 )
inline

Add order quantity at a price.

Adds the specified quantity to the order book at the given price. If the price level exists, quantity and order count are incremented. If it's a new price, a level is created (potentially causing level shifts).

The handler is invoked for:

Template Parameters
HandlerHandler type: void(Timestamp, const LevelUpdateEvent&)
Parameters
handlerHandler to receive update events
pricePrice to add quantity at
qtyQuantity to add
timestampEvent timestamp (default: 0)
Note
If price is beyond max_depth, it's added to overflow storage
Handler is called for each level change (may be multiple calls)

References b2bits::LevelUpdateEvent< _Traits >::New, and b2bits::LevelUpdateEvent< _Traits >::Update.

Referenced by modify().

◆ clear()

template<typename _Traits, typename _Traits::SideType _Side>
void b2bits::Aggregator< _Traits, _Side >::clear ( )
inline

Clear all price levels.

Removes all levels and resets the aggregator to empty state.

◆ modify()

template<typename _Traits, typename _Traits::SideType _Side>
template<class Handler>
void b2bits::Aggregator< _Traits, _Side >::modify ( Handler && handler,
PriceType old_price,
PriceType new_price,
QtyType old_qty,
QtyType new_qty,
Timestamp timestamp = 0 )
inline

Modify an order (change price and/or quantity).

Atomically changes an order from old price/quantity to new price/quantity. If possible, the level is modified in-place. Otherwise, the old quantity is reduced and new quantity is added (equivalent to cancel + add).

Optimization: If only quantity changes (same price), performs efficient update.

Template Parameters
HandlerHandler type: void(Timestamp, const LevelUpdateEvent&)
Parameters
handlerHandler to receive update events
old_pricePrevious order price
new_priceNew order price
old_qtyPrevious order quantity
new_qtyNew order quantity
timestampEvent timestamp (default: 0)
Note
May result in reduce_qty + add_order if in-place modification impossible

References add_order(), reduce_qty(), and b2bits::LevelUpdateEvent< _Traits >::Update.

◆ play()

template<typename _Traits, typename _Traits::SideType _Side>
template<class Handler>
void b2bits::Aggregator< _Traits, _Side >::play ( Handler && handler) const
inline

Replay all current levels to handler.

Iterates through all active price levels (0 to depth-1) and invokes the handler with a "New" event for each level. Useful for snapshot generation or initial state transmission.

Template Parameters
HandlerHandler type: void(Timestamp, const LevelUpdateEvent&)
Parameters
handlerHandler to receive level events

◆ reduce_qty()

template<typename _Traits, typename _Traits::SideType _Side>
template<class Handler>
void b2bits::Aggregator< _Traits, _Side >::reduce_qty ( Handler && handler,
PriceType price,
QtyType qty,
bool order_removed,
Timestamp timestamp = 0 )
inline

Reduce quantity at a price.

Removes the specified quantity from the order book at the given price. If an order is removed (order_removed=true), the order count is decremented. If quantity reaches zero, the level is removed and overflow levels may be promoted.

The handler is invoked for:

Template Parameters
HandlerHandler type: void(Timestamp, const LevelUpdateEvent&)
Parameters
handlerHandler to receive update events
pricePrice to reduce quantity at
qtyQuantity to remove
order_removedIf true, decrement order count
timestampEvent timestamp (default: 0)
Note
Multiple handler calls may occur for level removal and promotion

References b2bits::LevelUpdateEvent< _Traits >::Remove, and b2bits::LevelUpdateEvent< _Traits >::Update.

Referenced by modify().

◆ reset()

template<typename _Traits, typename _Traits::SideType _Side>
void b2bits::Aggregator< _Traits, _Side >::reset ( )
inline

Reset aggregator to initial state.

Clears all levels and overflow storage, resetting depth to zero. Similar to clear() but reinitializes the levels vector.


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