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

Fluent interface wrapper for ITCH 5.0 Session event handling. More...

Detailed Description

Fluent interface wrapper for ITCH 5.0 Session event handling.

This class provides an object-oriented, type-safe, and fluent API for registering event handlers with an ITCH 5.0 Session. It simplifies the process of attaching listeners for various market data events such as orders, trades, and book updates.

The fluent interface allows method chaining, making it easy to register multiple handlers in a single expression. All handler methods return a reference to *this, enabling the builder pattern.

Note
This class is compatible with the Session's Delegate mechanism through its templated operator() which dispatches events to the appropriate registered handlers.
See also
Session
Instrument
Example:
Basic usage with multiple handlers
auto session = std::make_shared<b2bits::nasdaq::itch50::Session>(settings);
auto handlers = std::make_shared<b2bits::nasdaq::itch50::SessionHandlers>();
handlers->on_add_order([](auto* s, auto* i, auto sn, auto* msg) {
std::cout << "AddOrder: qty=" << msg->get_quantity()
<< " price=" << msg->get_price() << std::endl;
})
.on_order_replace([](auto* s, auto* i, auto sn, auto* msg, auto* order) {
std::cout << "OrderReplace: " << msg->get_original_order_reference_number()
<< " -> " << msg->get_new_order_reference_number() << std::endl;
})
.on_trade([](auto* s, auto* i, auto sn, auto* msg) {
std::cout << "Trade: qty=" << msg->get_executed_quantity()
<< " price=" << msg->get_trade_price() << std::endl;
})
.on_book_update([](auto* s, auto* i, auto ts, auto& update) {
std::cout << "Book: " << (char)update.side_
<< " L" << update.index_ + 1
<< " " << update.qty_ << "@" << update.price_ << std::endl;
})
.on_session_event([](auto* s, auto evt) {
std::cout << "Event: " << static_cast<int>(evt) << std::endl;
});
// Attach handlers to session
session->attach_listener([handlers](auto&&... args) {
(*handlers)(std::forward<decltype(args)>(args)...);
});
session->start();
session->run(); // Blocking call
SessionHandlers & on_book_update(BookLevelUpdateHandler handler)
Register a handler for aggregated order book level updates.
Definition SessionHandlers.h:320
SessionHandlers & on_order_replace(OrderReplaceHandler handler)
Register a handler for order replace messages (ITCH 5.0).
Definition SessionHandlers.h:247
SessionHandlers & on_trade(TradeHandler handler)
Register a handler for non-displayed trade messages.
Definition SessionHandlers.h:261
SessionHandlers & on_session_event(SessionEventHandler handler)
Register a handler for session lifecycle events.
Definition SessionHandlers.h:365

#include <nasdaq/itch50/SessionHandlers.h>

Public Types

using SystemEventHandler = std::function<void(Session*, const Instrument*, Seqnum, const SystemEvent*)>
 Handler for system event messages (trading hours, end of day, etc.).
using OrderBookStateHandler = std::function<void(Session*, const Instrument*, Seqnum, const OrderBookState*)>
 Handler for order book state changes (halt, resume, etc.).
using OrderbookDirectoryHandler = std::function<void(Session*, const Instrument*, Seqnum, const OrderbookDirectory*)>
 Handler for orderbook directory messages (instrument definitions).
using AddOrderHandler = std::function<void(Session*, const Instrument*, Seqnum, const AddOrder*)>
 Handler for new order additions to the order book.
using OrderExecutedHandler = std::function<void(Session*, const Instrument*, Seqnum, const OrderExecuted*, const Instrument::Order*)>
 Handler for order executions (with match price from original order).
using OrderExecutedWithPriceHandler = std::function<void(Session*, const Instrument*, Seqnum, const OrderExecutedWithPrice*, const Instrument::Order*)>
 Handler for order executions with explicit execution price.
using OrderCancelHandler = std::function<void(Session*, const Instrument*, Seqnum, const OrderCancelMessage*, const Instrument::Order*)>
 Handler for order cancellations.
using OrderReplaceHandler = std::function<void(Session*, const Instrument*, Seqnum, const OrderReplace*, const Instrument::Order*)>
 Handler for order replacements (ITCH 5.0 feature).
using TradeHandler = std::function<void(Session*, const Instrument*, Seqnum, const Trade*)>
 Handler for non-displayed trade executions.
using ExecutionDoneHandler = std::function<void(Session*, const Instrument*, Seqnum, const ExecutionDone*)>
 Handler for execution completion notifications.
using InformationHandler = std::function<void(Session*, const Instrument*, Seqnum, const Information*)>
 Handler for informational messages (prices, yields, etc.).
using BrokenTradeHandler = std::function<void(Session*, const Instrument*, Seqnum, const BrokenTrade*)>
 Handler for trade bust/cancellation messages.
using BookLevelUpdateHandler = std::function<void(Session*, const Instrument*, Session::Timestamp, const Instrument::BookLevelUpdate&)>
 Handler for aggregated order book level updates.
using EndOfPacketHandler = std::function<void(Session*)>
 Handler for end-of-packet notifications.
using DirectoryWithoutInstrumentHandler = std::function<void(Session*, Seqnum, const OrderbookDirectory*)>
 Handler for directory messages when no instrument is created.
using SessionEventHandler = std::function<void(Session*, Event)>
 Handler for session lifecycle events.

Public Member Functions

SessionHandlerson_system_event (SystemEventHandler handler)
 Register a handler for system event messages.
SessionHandlerson_order_book_state (OrderBookStateHandler handler)
 Register a handler for order book state messages.
SessionHandlerson_orderbook_directory (OrderbookDirectoryHandler handler)
 Register a handler for orderbook directory messages.
SessionHandlerson_add_order (AddOrderHandler handler)
 Register a handler for add order messages.
SessionHandlerson_order_executed (OrderExecutedHandler handler)
 Register a handler for order executed messages.
SessionHandlerson_order_executed_with_price (OrderExecutedWithPriceHandler handler)
 Register a handler for order executed with price messages.
SessionHandlerson_order_cancel (OrderCancelHandler handler)
 Register a handler for order cancel messages.
SessionHandlerson_order_replace (OrderReplaceHandler handler)
 Register a handler for order replace messages (ITCH 5.0).
SessionHandlerson_trade (TradeHandler handler)
 Register a handler for non-displayed trade messages.
SessionHandlerson_execution_done (ExecutionDoneHandler handler)
 Register a handler for execution done messages.
SessionHandlerson_information (InformationHandler handler)
 Register a handler for information messages.
SessionHandlerson_broken_trade (BrokenTradeHandler handler)
 Register a handler for broken trade messages.
SessionHandlerson_book_update (BookLevelUpdateHandler handler)
 Register a handler for aggregated order book level updates.
SessionHandlerson_end_of_packet (EndOfPacketHandler handler)
 Register a handler for end-of-packet notifications.
SessionHandlerson_directory_without_instrument (DirectoryWithoutInstrumentHandler handler)
 Register a handler for directory messages without instrument creation.
SessionHandlerson_session_event (SessionEventHandler handler)
 Register a handler for session lifecycle events.
template<typename... Args>
void operator() (Args &&... args)
 Function call operator for Delegate compatibility.

Member Typedef Documentation

◆ AddOrderHandler

Handler for new order additions to the order book.

◆ BookLevelUpdateHandler

Handler for aggregated order book level updates.

◆ BrokenTradeHandler

Handler for trade bust/cancellation messages.

◆ DirectoryWithoutInstrumentHandler

Handler for directory messages when no instrument is created.

◆ EndOfPacketHandler

Handler for end-of-packet notifications.

◆ ExecutionDoneHandler

Handler for execution completion notifications.

◆ InformationHandler

Handler for informational messages (prices, yields, etc.).

◆ OrderbookDirectoryHandler

Handler for orderbook directory messages (instrument definitions).

◆ OrderBookStateHandler

Handler for order book state changes (halt, resume, etc.).

◆ OrderCancelHandler

Handler for order cancellations.

◆ OrderExecutedHandler

Handler for order executions (with match price from original order).

◆ OrderExecutedWithPriceHandler

Handler for order executions with explicit execution price.

◆ OrderReplaceHandler

Handler for order replacements (ITCH 5.0 feature).

◆ SessionEventHandler

Handler for session lifecycle events.

◆ SystemEventHandler

Handler for system event messages (trading hours, end of day, etc.).

◆ TradeHandler

Handler for non-displayed trade executions.

Member Function Documentation

◆ on_add_order()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_add_order ( AddOrderHandler handler)
inline

Register a handler for add order messages.

Add order messages indicate new limit or market orders being added to the order book. Includes order reference number, side, quantity, price, and ITCH 5.0 attributes (order type, time-in-force).

Parameters
handlerCallback function to handle new orders
Returns
Reference to this object for method chaining

◆ on_book_update()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_book_update ( BookLevelUpdateHandler handler)
inline

Register a handler for aggregated order book level updates.

Book level update messages provide aggregated price level information for the order book. These are generated when aggregated mode is enabled and reflect changes to specific price levels (bid/ask depth).

Parameters
handlerCallback function to handle book updates
Returns
Reference to this object for method chaining
Note
Only called when session is in aggregated mode

◆ on_broken_trade()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_broken_trade ( BrokenTradeHandler handler)
inline

Register a handler for broken trade messages.

Broken trade messages indicate that a previously reported trade has been cancelled or busted. This typically occurs when a trade is determined to be erroneous.

Parameters
handlerCallback function to handle broken trades
Returns
Reference to this object for method chaining

◆ on_directory_without_instrument()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_directory_without_instrument ( DirectoryWithoutInstrumentHandler handler)
inline

Register a handler for directory messages without instrument creation.

Called when a directory message is received but no instrument object is created (typically due to filtering or configuration). Allows observing all instruments even if not actively tracking them.

Parameters
handlerCallback function to handle untracked directory messages
Returns
Reference to this object for method chaining

◆ on_end_of_packet()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_end_of_packet ( EndOfPacketHandler handler)
inline

Register a handler for end-of-packet notifications.

End-of-packet notifications mark the completion of processing a MoldUDP64 packet. Useful for batching operations or flushing buffers after processing a group of messages.

Parameters
handlerCallback function to handle end-of-packet events
Returns
Reference to this object for method chaining

◆ on_execution_done()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_execution_done ( ExecutionDoneHandler handler)
inline

Register a handler for execution done messages.

Execution done messages mark the completion of a trade execution, indicating that no further messages will be sent for this transaction ID.

Parameters
handlerCallback function to handle execution completions
Returns
Reference to this object for method chaining

◆ on_information()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_information ( InformationHandler handler)
inline

Register a handler for information messages.

Information messages provide supplementary data about instruments such as indicative prices, yields, or other market information.

Parameters
handlerCallback function to handle information messages
Returns
Reference to this object for method chaining

◆ on_order_book_state()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_order_book_state ( OrderBookStateHandler handler)
inline

Register a handler for order book state messages.

Order book state messages indicate halts, resumes, and other state changes for specific instruments.

Parameters
handlerCallback function to handle order book state changes
Returns
Reference to this object for method chaining

◆ on_order_cancel()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_order_cancel ( OrderCancelHandler handler)
inline

Register a handler for order cancel messages.

Order cancel messages indicate that an order has been partially or fully cancelled. The handler receives the updated order state after cancellation.

Parameters
handlerCallback function to handle order cancellations
Returns
Reference to this object for method chaining

◆ on_order_executed()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_order_executed ( OrderExecutedHandler handler)
inline

Register a handler for order executed messages.

Order executed messages indicate that an existing order has been executed. The execution price is the price from the original order. The handler also receives the updated order state.

Parameters
handlerCallback function to handle order executions
Returns
Reference to this object for method chaining

◆ on_order_executed_with_price()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_order_executed_with_price ( OrderExecutedWithPriceHandler handler)
inline

Register a handler for order executed with price messages.

Similar to order executed, but includes an explicit execution price that may differ from the original order price. Used for executions at prices other than the order's limit price.

Parameters
handlerCallback function to handle executions with explicit price
Returns
Reference to this object for method chaining

◆ on_order_replace()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_order_replace ( OrderReplaceHandler handler)
inline

Register a handler for order replace messages (ITCH 5.0).

Order replace messages indicate that an existing order has been replaced with a new order (different reference number). The old order is implicitly cancelled and a new order is created with potentially different price, quantity, and attributes.

Parameters
handlerCallback function to handle order replacements
Returns
Reference to this object for method chaining
Note
This is an ITCH 5.0 specific feature

◆ on_orderbook_directory()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_orderbook_directory ( OrderbookDirectoryHandler handler)
inline

Register a handler for orderbook directory messages.

Directory messages provide instrument definitions including symbol, CUSIP, product type, trading features, and other instrument characteristics.

Parameters
handlerCallback function to handle directory messages
Returns
Reference to this object for method chaining

◆ on_session_event()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_session_event ( SessionEventHandler handler)
inline

Register a handler for session lifecycle events.

Session events indicate changes in the session state such as connecting, connected, disconnecting, login accepted/rejected, recovery, etc.

Parameters
handlerCallback function to handle session events
Returns
Reference to this object for method chaining
See also
Event for the list of possible session events

◆ on_system_event()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_system_event ( SystemEventHandler handler)
inline

Register a handler for system event messages.

System events indicate changes in trading state such as start/end of trading hours, start/end of market maker trading, and end of day messages.

Parameters
handlerCallback function to handle system events
Returns
Reference to this object for method chaining
Note
The handler receives: session pointer, instrument, sequence number, and message

◆ on_trade()

SessionHandlers & b2bits::nasdaq::itch50::SessionHandlers::on_trade ( TradeHandler handler)
inline

Register a handler for non-displayed trade messages.

Trade messages indicate executions that are not associated with displayed orders in the order book. These are typically crosses or other non-displayed trading activity.

Parameters
handlerCallback function to handle trades
Returns
Reference to this object for method chaining

◆ operator()()

template<typename... Args>
void b2bits::nasdaq::itch50::SessionHandlers::operator() ( Args &&... args)
inline

Function call operator for Delegate compatibility.

This templated operator() enables the SessionHandlers object to be used as a listener with the Session's Delegate mechanism. It uses compile-time type matching to dispatch incoming events to the appropriate registered handler.

The dispatcher uses constexpr if to determine the argument types and route the call to the corresponding handler function. Only registered (non-null) handlers are invoked.

Template Parameters
ArgsVariadic template for event arguments
Parameters
argsPerfect-forwarded event arguments
Note
This method uses SFINAE and constexpr if for zero-overhead dispatch
If no handler is registered for a particular event type, the call is silently ignored

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