ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
Loading...
Searching...
No Matches
b2bits::nasdaq::itch50::Instrument Class Reference

Represents a single trading instrument and its order book. More...

Detailed Description

Represents a single trading instrument and its order book.

The Instrument class maintains the complete state of an order book, including:

  • All active orders (order-level detail)
  • Aggregated price levels (buy/sell sides)
  • Instrument metadata (directory, events, state)
  • System events and trading state

Supports both order-level and aggregated views of the market. In aggregated mode, the class maintains price-level quantities. In order-level mode, individual orders are tracked.

Note
Thread-safety: Not thread-safe. Must be accessed from single thread.
See also
Session
BookTraits

#include <nasdaq/itch50/Instrument.h>

Classes

struct  Order
 Represents a single order in the order book. More...

Public Types

using BookLevelUpdate = LevelUpdateEvent<BookTraits>
 Type alias for aggregated book level updates.
using OrderMap = std::unordered_map<std::uint32_t, Order>
 Map of order reference number to Order.

Public Member Functions

 Instrument (std::int32_t session_id, const OrderbookDirectory *directory, std::uint16_t market_depth, std::any &&cookie=std::any{})
 Construct a new Instrument.
std::int32_t get_id () const noexcept
 Get session-local instrument ID.
std::uint32_t get_qty_multiplier () const
 Get quantity multiplier for this instrument.
std::uint32_t get_orderbook_id () const noexcept
 Get NASDAQ orderbook ID.
const OrderbookDirectoryget_orderbook_directory () const noexcept
 Get instrument directory information.
const SystemEventget_system_event () const noexcept
 Get most recent system event for this instrument.
const OrderBookStateget_order_book_state () const noexcept
 Get most recent order book state for this instrument.
const VolumeUpdateget_volume_update () const noexcept
 Get most recent volume update for this instrument.
bool mmm_enabled () const noexcept
 Check if Market Maker Mode (MMM) is enabled.
template<class T>
T * get_cookie () const noexcept
 Get user-defined cookie data.
void apply (const OrderbookDirectory &msg)
 Apply orderbook directory update.
void apply (const SystemEvent &msg)
 Apply system event update.
void apply (const OrderBookState &msg)
 Apply order book state update.
void apply (const VolumeUpdate &msg)
 Apply volume update.
template<class Handler>
void process (Handler &&h, std::uint64_t sn, const AddOrder *msg, bool)
 Process add order message.
template<class Handler>
void process (Handler &&h, std::uint64_t sn, const OrderExecuted *msg, bool)
 Process order executed message.
template<class Handler>
void process (Handler &&h, std::uint64_t sn, const OrderExecutedWithPrice *msg, bool)
 Process order executed with price message.
template<class Handler>
void process (Handler &&h, std::uint64_t sn, const OrderCancelMessage *msg, bool)
 Process order cancel message.
template<class Handler>
void process (Handler &&h, std::uint64_t sn, const OrderReplace *msg, bool)
 Process order replace message (ITCH 5.0).
template<class Handler>
void play_orders (Handler &&handler)
 Replay all active orders to a handler.
template<class Handler>
void play_book (Handler &&handler)
 Replay aggregated book levels to a handler.
void clear ()
 Clear all order book state.
template<class Handler, class M>
void process_order_executed (Handler &&h, std::uint64_t sn, const M *msg, bool mode_aggregated)

Class Documentation

◆ b2bits::nasdaq::itch50::Instrument::Order

struct b2bits::nasdaq::itch50::Instrument::Order

Represents a single order in the order book.

Contains all ITCH 5.0 order attributes including price, quantity, side, timestamps, and order characteristics (type, time-in-force).

Class Members
OrderType order_type_ = OrderType::Limit Order type: Market, Limit, StopLimit (ITCH 5.0).
Price price_ = 0 Order limit price.
QtyType qty_ = 0 Remaining order quantity.
Side side_ Order side (Buy/Sell).
TimeInForce time_in_force_ = TimeInForce::Day Time-in-force: Day, GTC, IOC, FOK (ITCH 5.0).
Timestamp timestamp_ = 0 Order entry timestamp (nanoseconds).
uint32_t transaction_id_ Associated transaction ID.
uint32_t yield_ Yield (for fixed income instruments).

Member Typedef Documentation

◆ BookLevelUpdate

Type alias for aggregated book level updates.

◆ OrderMap

using b2bits::nasdaq::itch50::Instrument::OrderMap = std::unordered_map<std::uint32_t, Order>

Map of order reference number to Order.

Constructor & Destructor Documentation

◆ Instrument()

b2bits::nasdaq::itch50::Instrument::Instrument ( std::int32_t session_id,
const OrderbookDirectory * directory,
std::uint16_t market_depth,
std::any && cookie = std::any{} )
inline

Construct a new Instrument.

Initializes the instrument with the given directory information, configures the aggregated book depth, and optionally stores user-defined cookie data.

Parameters
session_idSession-local instrument identifier
directoryInstrument definition from directory message
market_depthMaximum depth of aggregated book (number of price levels)
cookieOptional user-defined data associated with this instrument

Member Function Documentation

◆ apply() [1/4]

void b2bits::nasdaq::itch50::Instrument::apply ( const OrderbookDirectory & msg)
inline

Apply orderbook directory update.

Parameters
msgDirectory message with updated instrument information

◆ apply() [2/4]

void b2bits::nasdaq::itch50::Instrument::apply ( const OrderBookState & msg)
inline

Apply order book state update.

Parameters
msgOrder book state message

◆ apply() [3/4]

void b2bits::nasdaq::itch50::Instrument::apply ( const SystemEvent & msg)
inline

Apply system event update.

Parameters
msgSystem event message

◆ apply() [4/4]

void b2bits::nasdaq::itch50::Instrument::apply ( const VolumeUpdate & msg)
inline

Apply volume update.

Parameters
msgVolume update message

◆ clear()

void b2bits::nasdaq::itch50::Instrument::clear ( )
inline

Clear all order book state.

Removes all orders and resets aggregated book levels. Typically called when starting recovery or during session reset.

◆ get_cookie()

template<class T>
T * b2bits::nasdaq::itch50::Instrument::get_cookie ( ) const
inlinenoexcept

Get user-defined cookie data.

Retrieves the user-defined data that was associated with this instrument during construction or via add_instrument().

Template Parameters
TType of the cookie (must not be a pointer type)
Returns
Pointer to cookie data, or nullptr if type mismatch
Note
The type T must match the type used when storing the cookie

◆ get_id()

std::int32_t b2bits::nasdaq::itch50::Instrument::get_id ( ) const
inlinenoexcept

Get session-local instrument ID.

Returns
Instrument identifier unique within this session

◆ get_order_book_state()

const OrderBookState * b2bits::nasdaq::itch50::Instrument::get_order_book_state ( ) const
inlinenoexcept

Get most recent order book state for this instrument.

Returns
Pointer to order book state message, or nullptr if no state received

References b2bits::nasdaq::MessageHeader::get_type().

◆ get_orderbook_directory()

const OrderbookDirectory * b2bits::nasdaq::itch50::Instrument::get_orderbook_directory ( ) const
inlinenoexcept

Get instrument directory information.

Returns
Pointer to orderbook directory message

Referenced by get_orderbook_id().

◆ get_orderbook_id()

std::uint32_t b2bits::nasdaq::itch50::Instrument::get_orderbook_id ( ) const
inlinenoexcept

Get NASDAQ orderbook ID.

Returns
Unique orderbook identifier assigned by NASDAQ

References get_orderbook_directory(), and b2bits::nasdaq::itch50::OrderbookDirectory::get_orderbook_id().

Referenced by play_orders(), process(), process(), process(), and process_order_executed().

◆ get_qty_multiplier()

std::uint32_t b2bits::nasdaq::itch50::Instrument::get_qty_multiplier ( ) const
inline

Get quantity multiplier for this instrument.

The quantity multiplier is used to convert displayed quantities to actual contract quantities (e.g., for bonds traded in lots).

Returns
Quantity multiplier from instrument directory

◆ get_system_event()

const SystemEvent * b2bits::nasdaq::itch50::Instrument::get_system_event ( ) const
inlinenoexcept

Get most recent system event for this instrument.

Returns
Pointer to system event message, or nullptr if no event received

References b2bits::nasdaq::MessageHeader::get_type().

◆ get_volume_update()

const VolumeUpdate * b2bits::nasdaq::itch50::Instrument::get_volume_update ( ) const
inlinenoexcept

Get most recent volume update for this instrument.

Returns
Pointer to volume update message, or nullptr if no update received

References b2bits::nasdaq::MessageHeader::get_type().

◆ mmm_enabled()

bool b2bits::nasdaq::itch50::Instrument::mmm_enabled ( ) const
inlinenoexcept

Check if Market Maker Mode (MMM) is enabled.

Market Maker Mode allows additional trading features for registered market makers.

Returns
true if MMM is enabled for this instrument

References b2bits::nasdaq::itch50::MMMEnabled.

◆ play_book()

template<class Handler>
void b2bits::nasdaq::itch50::Instrument::play_book ( Handler && handler)

Replay aggregated book levels to a handler.

Iterates through all price levels in the aggregated book (both buy and sell sides) and invokes the handler for each level.

Template Parameters
HandlerType of the replay handler
Parameters
handlerHandler to receive book level information

◆ play_orders()

template<class Handler>
void b2bits::nasdaq::itch50::Instrument::play_orders ( Handler && handler)

◆ process() [1/5]

template<class Handler>
void b2bits::nasdaq::itch50::Instrument::process ( Handler && h,
std::uint64_t sn,
const AddOrder * msg,
bool mode_aggregated )

Process add order message.

Adds a new order to the order book and updates aggregated levels if in aggregated mode.

Template Parameters
HandlerType of the event handler
Parameters
hEvent handler to notify of changes
snSequence number of the message
msgAdd order message
[parameterdescription for bool - typically aggregated mode flag]

References b2bits::nasdaq::itch50::AddOrder::get_order_reference_number(), b2bits::nasdaq::itch50::AddOrder::get_order_type(), get_orderbook_id(), b2bits::nasdaq::itch50::AddOrder::get_price(), b2bits::nasdaq::itch50::AddOrder::get_quantity(), b2bits::nasdaq::itch50::AddOrder::get_side(), b2bits::nasdaq::itch50::AddOrder::get_time_in_force(), b2bits::nasdaq::itch50::AddOrder::get_timestamp(), b2bits::nasdaq::itch50::AddOrder::get_transaction_id(), b2bits::nasdaq::itch50::AddOrder::get_yield(), INSTRUMENT_LOG_ID, and b2bits::nasdaq::Sell.

◆ process() [2/5]

template<class Handler>
void b2bits::nasdaq::itch50::Instrument::process ( Handler && h,
std::uint64_t sn,
const OrderCancelMessage * msg,
bool mode_aggregated )

Process order cancel message.

Reduces or removes an order from the book and updates aggregated levels.

Template Parameters
HandlerType of the event handler
Parameters
hEvent handler to notify of changes
snSequence number of the message
msgOrder cancel message
[parameterdescription for bool]

References b2bits::nasdaq::itch50::OrderCancelMessage::get_canceled_quantity(), b2bits::nasdaq::itch50::OrderCancelMessage::get_order_reference_number(), get_orderbook_id(), b2bits::nasdaq::itch50::OrderCancelMessage::get_timestamp(), and INSTRUMENT_LOG_ID.

◆ process() [3/5]

template<class Handler>
void b2bits::nasdaq::itch50::Instrument::process ( Handler && h,
std::uint64_t sn,
const OrderExecuted * msg,
bool mode_aggregated )

Process order executed message.

Updates the order quantity and aggregated book levels based on the execution.

Template Parameters
HandlerType of the event handler
Parameters
hEvent handler to notify of changes
snSequence number of the message
msgOrder executed message
[parameterdescription for bool]

◆ process() [4/5]

template<class Handler>
void b2bits::nasdaq::itch50::Instrument::process ( Handler && h,
std::uint64_t sn,
const OrderExecutedWithPrice * msg,
bool mode_aggregated )

Process order executed with price message.

Similar to process(OrderExecuted*) but includes explicit execution price.

Template Parameters
HandlerType of the event handler
Parameters
hEvent handler to notify of changes
snSequence number of the message
msgOrder executed with price message
[parameterdescription for bool]

◆ process() [5/5]

template<class Handler>
void b2bits::nasdaq::itch50::Instrument::process ( Handler && h,
std::uint64_t sn,
const OrderReplace * msg,
bool mode_aggregated )

◆ process_order_executed()

template<class Handler, class M>
void b2bits::nasdaq::itch50::Instrument::process_order_executed ( Handler && h,
std::uint64_t sn,
const M * msg,
bool mode_aggregated )

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