|
ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
|
Represents a single trading instrument and its order book. More...
Represents a single trading instrument and its order book.
The Instrument class maintains the complete state of an order book, including:
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.
#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 OrderbookDirectory * | get_orderbook_directory () const noexcept |
| Get instrument directory information. | |
| const SystemEvent * | get_system_event () const noexcept |
| Get most recent system event for this instrument. | |
| const OrderBookState * | get_order_book_state () const noexcept |
| Get most recent order book state for this instrument. | |
| const VolumeUpdate * | get_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) |
| 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). |
Type alias for aggregated book level updates.
| using b2bits::nasdaq::itch50::Instrument::OrderMap = std::unordered_map<std::uint32_t, Order> |
Map of order reference number to Order.
|
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.
| session_id | Session-local instrument identifier |
| directory | Instrument definition from directory message |
| market_depth | Maximum depth of aggregated book (number of price levels) |
| cookie | Optional user-defined data associated with this instrument |
|
inline |
Apply orderbook directory update.
| msg | Directory message with updated instrument information |
|
inline |
Apply order book state update.
| msg | Order book state message |
|
inline |
Apply system event update.
| msg | System event message |
|
inline |
Apply volume update.
| msg | Volume update message |
|
inline |
Clear all order book state.
Removes all orders and resets aggregated book levels. Typically called when starting recovery or during session reset.
|
inlinenoexcept |
Get user-defined cookie data.
Retrieves the user-defined data that was associated with this instrument during construction or via add_instrument().
| T | Type of the cookie (must not be a pointer type) |
|
inlinenoexcept |
Get session-local instrument ID.
|
inlinenoexcept |
Get most recent order book state for this instrument.
References b2bits::nasdaq::MessageHeader::get_type().
|
inlinenoexcept |
Get instrument directory information.
Referenced by get_orderbook_id().
|
inlinenoexcept |
Get NASDAQ orderbook ID.
References get_orderbook_directory(), and b2bits::nasdaq::itch50::OrderbookDirectory::get_orderbook_id().
Referenced by play_orders(), process(), process(), process(), and process_order_executed().
|
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).
|
inlinenoexcept |
Get most recent system event for this instrument.
References b2bits::nasdaq::MessageHeader::get_type().
|
inlinenoexcept |
Get most recent volume update for this instrument.
References b2bits::nasdaq::MessageHeader::get_type().
|
inlinenoexcept |
Check if Market Maker Mode (MMM) is enabled.
Market Maker Mode allows additional trading features for registered market makers.
References b2bits::nasdaq::itch50::MMMEnabled.
| 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.
| Handler | Type of the replay handler |
| handler | Handler to receive book level information |
| void b2bits::nasdaq::itch50::Instrument::play_orders | ( | Handler && | handler | ) |
Replay all active orders to a handler.
Iterates through all orders currently in the order book and invokes the handler for each one. Useful for snapshot generation or state reconstruction.
| Handler | Type of the replay handler |
| handler | Handler to receive order information |
References get_orderbook_id(), b2bits::nasdaq::itch50::AddOrder::set_order_reference_number(), b2bits::nasdaq::itch50::AddOrder::set_order_type(), b2bits::nasdaq::itch50::AddOrder::set_orderbook_id(), b2bits::nasdaq::itch50::AddOrder::set_price(), b2bits::nasdaq::itch50::AddOrder::set_quantity(), b2bits::nasdaq::itch50::AddOrder::set_side(), b2bits::nasdaq::itch50::AddOrder::set_time_in_force(), b2bits::nasdaq::itch50::AddOrder::set_timestamp(), b2bits::nasdaq::itch50::AddOrder::set_transaction_id(), and b2bits::nasdaq::itch50::AddOrder::set_yield().
| 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.
| Handler | Type of the event handler |
| h | Event handler to notify of changes |
| sn | Sequence number of the message |
| msg | Add order message |
| [parameter | description 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.
| 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.
| Handler | Type of the event handler |
| h | Event handler to notify of changes |
| sn | Sequence number of the message |
| msg | Order cancel message |
| [parameter | description 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.
| 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.
| Handler | Type of the event 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.
| Handler | Type of the event handler |
| void b2bits::nasdaq::itch50::Instrument::process | ( | Handler && | h, |
| std::uint64_t | sn, | ||
| const OrderReplace * | msg, | ||
| bool | mode_aggregated ) |
Process order replace message (ITCH 5.0).
Handles order replacement where the original order is cancelled and a new order (with different reference number) is created.
| Handler | Type of the event handler |
| h | Event handler to notify of changes |
| sn | Sequence number of the message |
| msg | Order replace message |
| [parameter | description for bool] |
References b2bits::nasdaq::itch50::OrderReplace::get_new_order_reference_number(), b2bits::nasdaq::itch50::OrderReplace::get_order_type(), get_orderbook_id(), b2bits::nasdaq::itch50::OrderReplace::get_original_order_reference_number(), b2bits::nasdaq::itch50::OrderReplace::get_price(), b2bits::nasdaq::itch50::OrderReplace::get_quantity(), b2bits::nasdaq::itch50::OrderReplace::get_side(), b2bits::nasdaq::itch50::OrderReplace::get_time_in_force(), b2bits::nasdaq::itch50::OrderReplace::get_timestamp(), b2bits::nasdaq::itch50::OrderReplace::get_transaction_id(), b2bits::nasdaq::itch50::OrderReplace::get_yield(), INSTRUMENT_LOG_ID, and b2bits::nasdaq::Sell.
| void b2bits::nasdaq::itch50::Instrument::process_order_executed | ( | Handler && | h, |
| std::uint64_t | sn, | ||
| const M * | msg, | ||
| bool | mode_aggregated ) |
References get_orderbook_id(), and INSTRUMENT_LOG_ID.