ITCHCPP 1.6.0
High-Performance NASDAQ TotalView-ITCH 5.0 Parser & Market-Data Platform
Loading...
Searching...
No Matches
book_manager.hpp
Go to the documentation of this file.
1#pragma once
2
13
14#include <cstdint>
15#include <functional>
16#include <memory>
17#include <string>
18#include <string_view>
19#include <unordered_set>
20#include <vector>
21
22#include "itch/book/l3_book.hpp"
23#include "itch/messages.hpp"
24#include "itch/tape.hpp"
25
26namespace itch::book {
27
38 public:
40 using BboCallback = std::function<void(const L3Book& book, const Bbo& bbo)>;
41
43 BookManager() = default;
44
48 auto process(const Message& message) -> void;
49
53 auto set_bbo_callback(BboCallback callback) -> void { m_bbo_callback = std::move(callback); }
54
57 auto set_trade_callback(TradeCallback callback) -> void {
58 m_trade_callback = std::move(callback);
59 }
60
64 auto track_symbol(std::string symbol) -> void { m_universe.insert(std::move(symbol)); }
65
70 [[nodiscard]] auto book(std::uint16_t stock_locate) const -> const L3Book*;
71
76 [[nodiscard]] auto book_for_symbol(std::string_view symbol) const -> const L3Book*;
77
80 [[nodiscard]] auto book_count() const noexcept -> std::size_t { return m_book_count; }
81
86 [[nodiscard]] auto symbol_for_locate(std::uint16_t stock_locate) const -> std::string_view;
87
88 private:
89 struct BookEntry {
90 L3Book book;
91 Bbo last_bbo {};
92 };
93
100 auto ensure_entry(std::uint16_t stock_locate, std::string_view symbol) -> BookEntry*;
101
106 [[nodiscard]] auto entry(std::uint16_t stock_locate) const -> BookEntry*;
107
110 auto emit_bbo_if_changed(BookEntry& target) -> void;
111
116 [[nodiscard]] auto in_universe(std::string_view symbol) const -> bool;
117
122 template <typename AddMessage>
123 auto handle_add_order(const AddMessage& add) -> void;
124
128 auto handle_order_executed(const OrderExecutedMessage& exec) -> void;
129
133 auto handle_order_executed_with_price(const OrderExecutedWithPriceMessage& exec) -> void;
134
137 auto handle_order_cancel(const OrderCancelMessage& cancel) -> void;
138
141 auto handle_order_delete(const OrderDeleteMessage& del) -> void;
142
146 auto handle_order_replace(const OrderReplaceMessage& replace) -> void;
147
151 auto handle_non_cross_trade(const NonCrossTradeMessage& trade) -> void;
152
155 auto handle_cross_trade(const CrossTradeMessage& cross) -> void;
156
160 auto handle_stock_directory(const StockDirectoryMessage& directory) -> void;
161
162 std::vector<std::unique_ptr<BookEntry>> m_books_by_locate;
163 std::vector<std::string> m_symbol_by_locate;
164 std::unordered_set<std::string> m_universe;
165 BboCallback m_bbo_callback {};
166 TradeCallback m_trade_callback {};
167 std::size_t m_book_count {0};
168};
169
170} // namespace itch::book
Maintains a full-market set of order books from a single pass over the feed.
auto set_bbo_callback(BboCallback callback) -> void
Installs the best-bid/offer change callback (empty clears it).
auto process(const Message &message) -> void
Processes one parsed ITCH message, updating the relevant book and emitting BBO/trade events as approp...
std::function< void(const L3Book &book, const Bbo &bbo)> BboCallback
Invoked when a book's best bid or offer changes.
auto book_for_symbol(std::string_view symbol) const -> const L3Book *
The book for a symbol, or nullptr if none is tracked.
auto symbol_for_locate(std::uint16_t stock_locate) const -> std::string_view
The symbol associated with a locate code (empty if unknown).
auto book_count() const noexcept -> std::size_t
The number of books currently maintained.
BookManager()=default
Constructs an empty manager with no books tracked yet.
auto set_trade_callback(TradeCallback callback) -> void
Installs the trade-tape callback (empty clears it).
auto track_symbol(std::string symbol) -> void
Restricts tracking to the given symbol (call once per symbol).
A single-symbol, order-level (L3) limit order book with allocation-light internals.
Definition l3_book.hpp:72
std::string symbol
Definition csv_sink.cpp:19
std::uint16_t stock_locate
Definition csv_sink.cpp:17
Single-symbol, order-level (L3) limit order book with allocation-light internals.
Defines every ITCH 5.0 message struct, the Message variant, and the stream-printing helpers used to f...
std::function< void(const Trade &)> TradeCallback
Callback invoked for each extracted trade.
Definition tape.hpp:42
std::variant< SystemEventMessage, StockDirectoryMessage, StockTradingActionMessage, RegSHOMessage, MarketParticipantPositionMessage, MWCBDeclineLevelMessage, MWCBStatusMessage, IPOQuotingPeriodUpdateMessage, LULDAuctionCollarMessage, OperationalHaltMessage, AddOrderMessage, AddOrderMPIDAttributionMessage, OrderExecutedMessage, OrderExecutedWithPriceMessage, OrderCancelMessage, OrderDeleteMessage, OrderReplaceMessage, NonCrossTradeMessage, CrossTradeMessage, BrokenTradeMessage, NOIIMessage, RetailPriceImprovementIndicatorMessage, DLCRMessage > Message
A variant able to hold any one of the ITCH 5.0 message structs.
Definition messages.hpp:483
Best bid and offer of a single book.
Definition l3_book.hpp:46
A normalized trade record and callback type for consuming the ITCH trade tape.