ITCHCPP 1.6.0
High-Performance NASDAQ TotalView-ITCH 5.0 Parser & Market-Data Platform
Loading...
Searching...
No Matches
auctions.hpp
Go to the documentation of this file.
1#pragma once
2
11
12#include <array>
13#include <cstdint>
14#include <functional>
15#include <string>
16#include <string_view>
17#include <unordered_map>
18#include <utility>
19#include <variant>
20
22#include "itch/indicators.hpp"
23#include "itch/messages.hpp"
24#include "itch/price.hpp"
25
26namespace itch::analytics {
27
34struct Auction {
35 std::uint64_t timestamp {0};
36 std::uint16_t stock_locate {0};
37 std::string stock;
38 char cross_type {'\0'};
40 std::uint64_t cross_shares {0};
41 std::uint64_t paired_shares {0};
42 std::uint64_t imbalance_shares {0};
44 bool had_imbalance {false};
45};
46
51[[nodiscard]] inline auto cross_type_name(char cross_type) -> std::string_view {
52 constexpr indicators::FrozenMap types {std::to_array<std::pair<char, std::string_view>>({
53 {'O', "Opening Cross"},
54 {'C', "Closing Cross"},
55 {'H', "Cross for halted/paused security"},
56 {'I', "Intraday/IPO Cross"},
57 })};
58 return types.at_or(cross_type, "Unknown");
59}
60
68 public:
69 using AuctionCallback = std::function<void(const Auction&)>;
70
74 auto set_auction_callback(AuctionCallback callback) -> void {
75 m_callback = std::move(callback);
76 }
77
82 auto process(const Message& message) -> void {
83 if (const auto* noii = std::get_if<NOIIMessage>(&message)) {
84 m_latest_imbalance[noii->stock_locate] = make_imbalance_info(*noii);
85 return;
86 }
87 if (const auto* cross = std::get_if<CrossTradeMessage>(&message)) {
88 Auction auction {};
89 auction.timestamp = cross->timestamp;
90 auction.stock_locate = cross->stock_locate;
91 auction.stock = to_string(cross->stock, STOCK_LEN);
92 auction.cross_type = cross->cross_type;
93 auction.cross_price = StandardPrice {cross->cross_price};
94 auction.cross_shares = cross->shares;
95
96 const auto iter = m_latest_imbalance.find(cross->stock_locate);
97 if (iter != m_latest_imbalance.end()) {
98 auction.paired_shares = iter->second.paired_shares;
99 auction.imbalance_shares = iter->second.imbalance_shares;
100 auction.imbalance_direction = iter->second.imbalance_direction;
101 auction.had_imbalance = true;
102 }
103 if (m_callback) {
104 m_callback(auction);
105 }
106 return;
107 }
108 }
109
110 private:
111 std::unordered_map<std::uint16_t, ImbalanceInfo> m_latest_imbalance;
112 AuctionCallback m_callback {};
113};
114
115} // namespace itch::analytics
Reconstructs auctions from the NOII and Cross Trade message stream.
Definition auctions.hpp:67
auto process(const Message &message) -> void
Processes one ITCH message, emitting an auction on each cross.
Definition auctions.hpp:82
auto set_auction_callback(AuctionCallback callback) -> void
Installs the callback invoked for each reconstructed auction.
Definition auctions.hpp:74
std::function< void(const Auction &)> AuctionCallback
Definition auctions.hpp:69
An immutable, compile-time lookup table from a key to a description.
constexpr auto at_or(const KeyType &key, std::string_view fallback) const noexcept -> std::string_view
Returns the description for a key, or a fallback if absent.
Decoded view of Net Order Imbalance Indicator (NOII) messages.
Compile-time lookup tables translating ITCH single- and multi-character indicator codes into human-re...
Defines every ITCH 5.0 message struct, the Message variant, and the stream-printing helpers used to f...
auto cross_type_name(char cross_type) -> std::string_view
A human-readable description of a cross type code.
Definition auctions.hpp:51
auto make_imbalance_info(const NOIIMessage &msg) -> ImbalanceInfo
Builds an ImbalanceInfo from a raw NOII message.
Definition imbalance.hpp:47
constexpr int STOCK_LEN
Definition messages.hpp:485
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
auto to_string(const char *source, size_t size) -> std::string
Converts a fixed-width character array to a string, trimming trailing spaces and NUL characters.
Definition messages.hpp:495
Strongly typed, fixed-point price representation for ITCH price fields.
A reconstructed auction (cross) event.
Definition auctions.hpp:34
std::uint64_t timestamp
Definition auctions.hpp:35
std::uint16_t stock_locate
Definition auctions.hpp:36
std::uint64_t cross_shares
Shares executed in the cross.
Definition auctions.hpp:40
std::uint64_t paired_shares
Paired shares from the latest NOII.
Definition auctions.hpp:41
std::uint64_t imbalance_shares
Imbalance shares from the latest NOII.
Definition auctions.hpp:42
bool had_imbalance
Whether NOII context was available.
Definition auctions.hpp:44
StandardPrice cross_price
The cross execution price.
Definition auctions.hpp:39
char cross_type
'O' open, 'C' close, 'H' halt/pause, 'I' IPO.
Definition auctions.hpp:38