|
ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
|
ITCH 5.0 Market Data Session. More...
ITCH 5.0 Market Data Session.
This class implements a complete ITCH 5.0 market data feed handler, providing:
The Session maintains a collection of Instrument objects representing tracked order books. It processes incoming ITCH messages, updates the order books accordingly, and notifies registered listeners of events.
#include <nasdaq/itch50/Session.h>
Classes | |
| class | EOP |
| End-of-packet marker type. More... | |
Public Types | |
| using | Timestamp = BookTraits::Timestamp |
| Timestamp type for book updates (nanoseconds since epoch). | |
| using | ListenerType |
| Listener delegate type. | |
| Public Types inherited from b2bits::nasdaq::moldudp64::Session | |
| enum class | State { InSync , Recovering , OutOfSync } |
| Session synchronization state. More... | |
| enum class | Source { Realtime , Snapshot , Cache } |
| Message source indicator. More... | |
| enum class | Event { LinkUp , LinkDown , EndOfSession , RecoveryStarted , RecoveryStopped , RecoveryFailed , SecdefsAvailable } |
| Session lifecycle and recovery events. More... | |
| using | error_code = std::error_code |
| Error code type alias. | |
| using | Seqnum = decltype(std::declval<UDPPacket>().get_sn()) |
| Sequence number type. | |
Public Member Functions | |
| Session (Settings s) | |
| Construct a new ITCH 5.0 Session. | |
| ~Session () | |
| Destructor. | |
| bool | aggregated_mode () const |
| Check if session is in aggregated mode. | |
| template<typename Handler> | |
| void | attach_listener (Handler &&h) |
| Attach a listener for market data events. | |
| void | detach_listener () |
| Detach the current listener. | |
| void | add_instrument (const OrderbookDirectory *info, std::any &&cookie=std::any{}) |
| Manually add an instrument to track. | |
| const std::unordered_map< OrderbookID, std::unique_ptr< Instrument > > & | get_instruments () const noexcept |
| Get all tracked instruments. | |
| void | operator() (Instrument *, Seqnum sn, const AddOrder *) |
| Handle add order update for an instrument. | |
| template<class T> | |
| void | operator() (Instrument *, Seqnum sn, const T *, const Instrument::Order *) |
| Handle generic order update (executed, cancel, replace). | |
| void | operator() (Instrument *, Timestamp timestamp, const Instrument::BookLevelUpdate &update) |
| Handle aggregated book level update. | |
| Public Member Functions inherited from b2bits::nasdaq::moldudp64::Session | |
| Session (std::shared_ptr< b2bits::IOContext > ctx, Settings s, const char *log_pfx=nullptr) | |
| Construct a MoldUDP64 session. | |
| ~Session () | |
| Destructor. | |
| bool | is_started () const |
| Check if session is started. | |
| State | get_state () const |
| Get current session state. | |
| const std::string & | get_session () const |
| Get active MoldUDP64 session name. | |
| std::int64_t | get_msg_recv_time () const |
| Get timestamp of last received message. | |
| auto | get_packet_recv_time () |
| Get timestamp of last received packet. | |
| void | start () |
| Start the session. | |
| void | run () |
| Run the session (blocking). | |
| void | stop () |
| Stop the session (synchronous). | |
| template<typename Handler> | |
| void | async_stop (Handler &&h) |
| Stop the session asynchronously. | |
| void | pause_udp () |
| Pause UDP multicast reception. | |
| void | resume_udp () |
| Resume UDP multicast reception. | |
| void | operator() (Sequencer &, std::uint64_t sn, std::int64_t timestamp, const MessageBlock *h) |
| Handle in-sequence message from sequencer. | |
| void | operator() (Sequencer &, Sequencer::ResetEvent) |
| Handle sequencer reset event. | |
| void | operator() (Sequencer &, Sequencer::ReplayEvent) |
| Handle sequencer replay event. | |
Additional Inherited Members | |
| Protected Member Functions inherited from b2bits::nasdaq::moldudp64::Session | |
| std::shared_ptr< b2bits::AsyncSentry > | get_sentry () |
| Get the async operation sentry. | |
| void | set_session (const std::string &s) |
| Set the active session name. | |
| void | set_msg_recv_time (std::int64_t val) |
| Set the message receive timestamp. | |
| void | on_recovery_finished (Seqnum next_sn, const error_code &ec) |
| Notify recovery completion. | |
| Protected Attributes inherited from b2bits::nasdaq::moldudp64::Session | |
| const std::string | log_prefix_ |
| Prefix for log messages. | |
| const Settings | settings_ |
| Session configuration. | |
| const std::int32_t | id_ |
| Session identifier. | |
| std::string | active_session_ |
| Current MoldUDP64 session name. | |
| bool | link_is_up_ = true |
| Multicast link status. | |
| std::int64_t | msg_recv_time_ = 0 |
| Timestamp of last received message. | |
| std::shared_ptr< b2bits::IOContext > | ctx_ |
| IO context for async operations. | |
| class b2bits::nasdaq::itch50::Session::EOP |
End-of-packet marker type.
Used as a sentinel value in listener callbacks to indicate the end of a MoldUDP64 packet.
Listener delegate type.
Multi-signature delegate supporting all ITCH 5.0 market data events. Listeners receive callbacks for orders, trades, book updates, and session lifecycle events.
Timestamp type for book updates (nanoseconds since epoch).
| b2bits::nasdaq::itch50::Session::Session | ( | Settings | s | ) |
Construct a new ITCH 5.0 Session.
Initializes the session with the provided settings, including network configuration, order book depth, and recovery parameters.
| s | Complete session settings (ITCH + MoldUDP64) |
| std::runtime_error | if initialization fails |
| b2bits::nasdaq::itch50::Session::~Session | ( | ) |
Destructor.
Ensures proper cleanup of resources and termination of the session. If the session is still running, it will be stopped before destruction.
| void b2bits::nasdaq::itch50::Session::add_instrument | ( | const OrderbookDirectory * | info, |
| std::any && | cookie = std::any{} ) |
Manually add an instrument to track.
Creates a new Instrument object for the given directory information. The instrument will be tracked and maintained by the session, receiving updates from incoming market data messages.
| info | Orderbook directory message containing instrument definition |
| cookie | Optional user-defined data to associate with the instrument |
| bool b2bits::nasdaq::itch50::Session::aggregated_mode | ( | ) | const |
Check if session is in aggregated mode.
|
inline |
Attach a listener for market data events.
Registers a callback handler that will be invoked for all market data events. The handler must be compatible with the ListenerType delegate signature (supports multiple overloads for different event types).
| Handler | Type of the handler (typically a lambda or SessionHandlers) |
| h | Handler to attach (perfect-forwarded) |
|
inline |
Detach the current listener.
Removes the currently attached listener. After this call, no events will be delivered until a new listener is attached.
|
noexcept |
Get all tracked instruments.
Returns a read-only reference to the map of all instruments currently being tracked by this session.
| void b2bits::nasdaq::itch50::Session::operator() | ( | Instrument * | , |
| Seqnum | sn, | ||
| const AddOrder * | ) |
Handle add order update for an instrument.
| inst | Target instrument |
| sn | Sequence number |
| msg | Add order message |
| void b2bits::nasdaq::itch50::Session::operator() | ( | Instrument * | , |
| Seqnum | sn, | ||
| const T * | , | ||
| const Instrument::Order * | ) |
Handle generic order update (executed, cancel, replace).
| T | Message type (OrderExecuted, OrderCancel, etc.) |
| inst | Target instrument |
| sn | Sequence number |
| msg | Order message |
| order | Current order state |
| void b2bits::nasdaq::itch50::Session::operator() | ( | Instrument * | , |
| Timestamp | timestamp, | ||
| const Instrument::BookLevelUpdate & | update ) |
Handle aggregated book level update.
| inst | Target instrument |
| timestamp | Event timestamp |
| update | Book level update data |