CppTrader  1.0.4.0
C++ Trader
itch_handler.h
Go to the documentation of this file.
1 
9 #ifndef CPPTRADER_ITCH_HANDLER_H
10 #define CPPTRADER_ITCH_HANDLER_H
11 
12 #include "utility/endian.h"
13 #include "utility/iostream.h"
14 
15 #include <vector>
16 
17 namespace CppTrader {
18 
23 namespace ITCH {
24 
27 {
28  char Type;
29  uint16_t StockLocate;
30  uint16_t TrackingNumber;
31  uint64_t Timestamp;
32  char EventCode;
33 
34  template <class TOutputStream>
35  friend TOutputStream& operator<<(TOutputStream& stream, const SystemEventMessage& message);
36 };
37 
40 {
41  char Type;
42  uint16_t StockLocate;
43  uint16_t TrackingNumber;
44  uint64_t Timestamp;
45  char Stock[8];
48  uint32_t RoundLotSize;
51  char IssueSubType[2];
54  char IPOFlag;
56  char ETPFlag;
59 
60  template <class TOutputStream>
61  friend TOutputStream& operator<<(TOutputStream& stream, const StockDirectoryMessage& message);
62 };
63 
66 {
67  char Type;
68  uint16_t StockLocate;
69  uint16_t TrackingNumber;
70  uint64_t Timestamp;
71  char Stock[8];
73  char Reserved;
74  char Reason;
75 
76  template <class TOutputStream>
77  friend TOutputStream& operator<<(TOutputStream& stream, const StockTradingActionMessage& message);
78 };
79 
82 {
83  char Type;
84  uint16_t StockLocate;
85  uint16_t TrackingNumber;
86  uint64_t Timestamp;
87  char Stock[8];
89 
90  template <class TOutputStream>
91  friend TOutputStream& operator<<(TOutputStream& stream, const RegSHOMessage& message);
92 };
93 
96 {
97  char Type;
98  uint16_t StockLocate;
99  uint16_t TrackingNumber;
100  uint64_t Timestamp;
101  char MPID[4];
102  char Stock[8];
106 
107  template <class TOutputStream>
108  friend TOutputStream& operator<<(TOutputStream& stream, const MarketParticipantPositionMessage& message);
109 };
110 
113 {
114  char Type;
115  uint16_t StockLocate;
116  uint16_t TrackingNumber;
117  uint64_t Timestamp;
118  uint64_t Level1;
119  uint64_t Level2;
120  uint64_t Level3;
121 
122  template <class TOutputStream>
123  friend TOutputStream& operator<<(TOutputStream& stream, const MWCBDeclineMessage& message);
124 };
125 
128 {
129  char Type;
130  uint16_t StockLocate;
131  uint16_t TrackingNumber;
132  uint64_t Timestamp;
134 
135  template <class TOutputStream>
136  friend TOutputStream& operator<<(TOutputStream& stream, const MWCBStatusMessage& message);
137 };
138 
141 {
142  char Type;
143  uint16_t StockLocate;
144  uint16_t TrackingNumber;
145  uint64_t Timestamp;
146  char Stock[8];
147  uint32_t IPOReleaseTime;
149  uint32_t IPOPrice;
150 
151  template <class TOutputStream>
152  friend TOutputStream& operator<<(TOutputStream& stream, const IPOQuotingMessage& message);
153 };
154 
157 {
158  char Type;
159  uint16_t StockLocate;
160  uint16_t TrackingNumber;
161  uint64_t Timestamp;
164  uint32_t Shares;
165  char Stock[8];
166  uint32_t Price;
167 
168  template <class TOutputStream>
169  friend TOutputStream& operator<<(TOutputStream& stream, const AddOrderMessage& message);
170 };
171 
174 {
175  char Type;
176  uint16_t StockLocate;
177  uint16_t TrackingNumber;
178  uint64_t Timestamp;
181  uint32_t Shares;
182  char Stock[8];
183  uint32_t Price;
185 
186  template <class TOutputStream>
187  friend TOutputStream& operator<<(TOutputStream& stream, const AddOrderMPIDMessage& message);
188 };
189 
192 {
193  char Type;
194  uint16_t StockLocate;
195  uint16_t TrackingNumber;
196  uint64_t Timestamp;
198  uint32_t ExecutedShares;
199  uint64_t MatchNumber;
200 
201  template <class TOutputStream>
202  friend TOutputStream& operator<<(TOutputStream& stream, const OrderExecutedMessage& message);
203 };
204 
207 {
208  char Type;
209  uint16_t StockLocate;
210  uint16_t TrackingNumber;
211  uint64_t Timestamp;
213  uint32_t ExecutedShares;
214  uint64_t MatchNumber;
215  char Printable;
216  uint32_t ExecutionPrice;
217 
218  template <class TOutputStream>
219  friend TOutputStream& operator<<(TOutputStream& stream, const OrderExecutedWithPriceMessage& message);
220 };
221 
224 {
225  char Type;
226  uint16_t StockLocate;
227  uint16_t TrackingNumber;
228  uint64_t Timestamp;
230  uint32_t CanceledShares;
231 
232  template <class TOutputStream>
233  friend TOutputStream& operator<<(TOutputStream& stream, const OrderCancelMessage& message);
234 };
235 
238 {
239  char Type;
240  uint16_t StockLocate;
241  uint16_t TrackingNumber;
242  uint64_t Timestamp;
244 
245  template <class TOutputStream>
246  friend TOutputStream& operator<<(TOutputStream& stream, const OrderDeleteMessage& message);
247 };
248 
251 {
252  char Type;
253  uint16_t StockLocate;
254  uint16_t TrackingNumber;
255  uint64_t Timestamp;
258  uint32_t Shares;
259  uint32_t Price;
260 
261  template <class TOutputStream>
262  friend TOutputStream& operator<<(TOutputStream& stream, const OrderReplaceMessage& message);
263 };
264 
267 {
268  char Type;
269  uint16_t StockLocate;
270  uint16_t TrackingNumber;
271  uint64_t Timestamp;
274  uint32_t Shares;
275  char Stock[8];
276  uint32_t Price;
277  uint64_t MatchNumber;
278 
279  template <class TOutputStream>
280  friend TOutputStream& operator<<(TOutputStream& stream, const TradeMessage& message);
281 };
282 
285 {
286  char Type;
287  uint16_t StockLocate;
288  uint16_t TrackingNumber;
289  uint64_t Timestamp;
290  uint64_t Shares;
291  char Stock[8];
292  uint32_t CrossPrice;
293  uint64_t MatchNumber;
294  char CrossType;
295 
296  template <class TOutputStream>
297  friend TOutputStream& operator<<(TOutputStream& stream, const CrossTradeMessage& message);
298 };
299 
302 {
303  char Type;
304  uint16_t StockLocate;
305  uint16_t TrackingNumber;
306  uint64_t Timestamp;
307  uint64_t MatchNumber;
308 
309  template <class TOutputStream>
310  friend TOutputStream& operator<<(TOutputStream& stream, const BrokenTradeMessage& message);
311 };
312 
315 {
316  char Type;
317  uint16_t StockLocate;
318  uint16_t TrackingNumber;
319  uint64_t Timestamp;
320  uint64_t PairedShares;
321  uint64_t ImbalanceShares;
323  char Stock[8];
324  uint32_t FarPrice;
325  uint32_t NearPrice;
327  char CrossType;
329 
330  template <class TOutputStream>
331  friend TOutputStream& operator<<(TOutputStream& stream, const NOIIMessage& message);
332 };
333 
336 {
337  char Type;
338  uint16_t StockLocate;
339  uint16_t TrackingNumber;
340  uint64_t Timestamp;
341  char Stock[8];
343 
344  template <class TOutputStream>
345  friend TOutputStream& operator<<(TOutputStream& stream, const RPIIMessage& message);
346 };
347 
350 {
351  char Type;
352  uint16_t StockLocate;
353  uint16_t TrackingNumber;
354  uint64_t Timestamp;
355  char Stock[8];
360 
361  template <class TOutputStream>
362  friend TOutputStream& operator<<(TOutputStream& stream, const LULDAuctionCollarMessage& message);
363 };
364 
367 {
368  char Type;
369 
370  template <class TOutputStream>
371  friend TOutputStream& operator<<(TOutputStream& stream, const UnknownMessage& message);
372 };
373 
375 
388 {
389 public:
391  ITCHHandler(const ITCHHandler&) = delete;
393  virtual ~ITCHHandler() = default;
394 
395  ITCHHandler& operator=(const ITCHHandler&) = delete;
397 
399 
404  bool Process(void* buffer, size_t size);
406 
411  bool ProcessMessage(void* buffer, size_t size);
412 
414  void Reset();
415 
416 protected:
417  // Message handlers
418  virtual bool onMessage(const SystemEventMessage& message) { return true; }
419  virtual bool onMessage(const StockDirectoryMessage& message) { return true; }
420  virtual bool onMessage(const StockTradingActionMessage& message) { return true; }
421  virtual bool onMessage(const RegSHOMessage& message) { return true; }
422  virtual bool onMessage(const MarketParticipantPositionMessage& message) { return true; }
423  virtual bool onMessage(const MWCBDeclineMessage& message) { return true; }
424  virtual bool onMessage(const MWCBStatusMessage& message) { return true; }
425  virtual bool onMessage(const IPOQuotingMessage& message) { return true; }
426  virtual bool onMessage(const AddOrderMessage& message) { return true; }
427  virtual bool onMessage(const AddOrderMPIDMessage& message) { return true; }
428  virtual bool onMessage(const OrderExecutedMessage& message) { return true; }
429  virtual bool onMessage(const OrderExecutedWithPriceMessage& message) { return true; }
430  virtual bool onMessage(const OrderCancelMessage& message) { return true; }
431  virtual bool onMessage(const OrderDeleteMessage& message) { return true; }
432  virtual bool onMessage(const OrderReplaceMessage& message) { return true; }
433  virtual bool onMessage(const TradeMessage& message) { return true; }
434  virtual bool onMessage(const CrossTradeMessage& message) { return true; }
435  virtual bool onMessage(const BrokenTradeMessage& message) { return true; }
436  virtual bool onMessage(const NOIIMessage& message) { return true; }
437  virtual bool onMessage(const RPIIMessage& message) { return true; }
438  virtual bool onMessage(const LULDAuctionCollarMessage& message) { return true; }
439  virtual bool onMessage(const UnknownMessage& message) { return true; }
440 
441 private:
442  size_t _size;
443  std::vector<uint8_t> _cache;
444 
445  bool ProcessSystemEventMessage(void* buffer, size_t size);
446  bool ProcessStockDirectoryMessage(void* buffer, size_t size);
447  bool ProcessStockTradingActionMessage(void* buffer, size_t size);
448  bool ProcessRegSHOMessage(void* buffer, size_t size);
449  bool ProcessMarketParticipantPositionMessage(void* buffer, size_t size);
450  bool ProcessMWCBDeclineMessage(void* buffer, size_t size);
451  bool ProcessMWCBStatusMessage(void* buffer, size_t size);
452  bool ProcessIPOQuotingMessage(void* buffer, size_t size);
453  bool ProcessAddOrderMessage(void* buffer, size_t size);
454  bool ProcessAddOrderMPIDMessage(void* buffer, size_t size);
455  bool ProcessOrderExecutedMessage(void* buffer, size_t size);
456  bool ProcessOrderExecutedWithPriceMessage(void* buffer, size_t size);
457  bool ProcessOrderCancelMessage(void* buffer, size_t size);
458  bool ProcessOrderDeleteMessage(void* buffer, size_t size);
459  bool ProcessOrderReplaceMessage(void* buffer, size_t size);
460  bool ProcessTradeMessage(void* buffer, size_t size);
461  bool ProcessCrossTradeMessage(void* buffer, size_t size);
462  bool ProcessBrokenTradeMessage(void* buffer, size_t size);
463  bool ProcessNOIIMessage(void* buffer, size_t size);
464  bool ProcessRPIIMessage(void* buffer, size_t size);
465  bool ProcessLULDAuctionCollarMessage(void* buffer, size_t size);
466  bool ProcessUnknownMessage(void* buffer, size_t size);
467 
468  template <size_t N>
469  size_t ReadString(const void* buffer, char (&str)[N]);
470  size_t ReadTimestamp(const void* buffer, uint64_t& value);
471 };
472 
475 } // namespace ITCH
476 } // namespace CppTrader
477 
478 #include "itch_handler.inl"
479 
480 #endif // CPPTRADER_ITCH_HANDLER_H
NASDAQ ITCH handler class.
Definition: itch_handler.h:388
virtual bool onMessage(const AddOrderMPIDMessage &message)
Definition: itch_handler.h:427
virtual bool onMessage(const OrderDeleteMessage &message)
Definition: itch_handler.h:431
virtual bool onMessage(const SystemEventMessage &message)
Definition: itch_handler.h:418
virtual bool onMessage(const RPIIMessage &message)
Definition: itch_handler.h:437
ITCHHandler & operator=(ITCHHandler &&)=delete
bool ProcessMessage(void *buffer, size_t size)
Process a single message from the given buffer in ITCH format and call corresponding handlers.
virtual bool onMessage(const NOIIMessage &message)
Definition: itch_handler.h:436
virtual bool onMessage(const OrderExecutedMessage &message)
Definition: itch_handler.h:428
virtual bool onMessage(const UnknownMessage &message)
Definition: itch_handler.h:439
virtual bool onMessage(const OrderExecutedWithPriceMessage &message)
Definition: itch_handler.h:429
virtual ~ITCHHandler()=default
virtual bool onMessage(const IPOQuotingMessage &message)
Definition: itch_handler.h:425
virtual bool onMessage(const StockTradingActionMessage &message)
Definition: itch_handler.h:420
ITCHHandler(ITCHHandler &&)=delete
virtual bool onMessage(const OrderReplaceMessage &message)
Definition: itch_handler.h:432
virtual bool onMessage(const StockDirectoryMessage &message)
Definition: itch_handler.h:419
virtual bool onMessage(const MarketParticipantPositionMessage &message)
Definition: itch_handler.h:422
virtual bool onMessage(const LULDAuctionCollarMessage &message)
Definition: itch_handler.h:438
ITCHHandler & operator=(const ITCHHandler &)=delete
virtual bool onMessage(const RegSHOMessage &message)
Definition: itch_handler.h:421
bool Process(void *buffer, size_t size)
Process all messages from the given buffer in ITCH format and call corresponding handlers.
ITCHHandler(const ITCHHandler &)=delete
virtual bool onMessage(const MWCBDeclineMessage &message)
Definition: itch_handler.h:423
virtual bool onMessage(const CrossTradeMessage &message)
Definition: itch_handler.h:434
virtual bool onMessage(const TradeMessage &message)
Definition: itch_handler.h:433
void Reset()
Reset ITCH handler.
virtual bool onMessage(const MWCBStatusMessage &message)
Definition: itch_handler.h:424
virtual bool onMessage(const AddOrderMessage &message)
Definition: itch_handler.h:426
virtual bool onMessage(const OrderCancelMessage &message)
Definition: itch_handler.h:430
virtual bool onMessage(const BrokenTradeMessage &message)
Definition: itch_handler.h:435
NASDAQ ITCH handler inline implementation.
C++ Trader project definitions.
Definition: errors.h:16
Add Order with MPID Attribution Message.
Definition: itch_handler.h:174
friend TOutputStream & operator<<(TOutputStream &stream, const AddOrderMPIDMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const AddOrderMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const BrokenTradeMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const CrossTradeMessage &message)
IPO Quoting Period Update Message.
Definition: itch_handler.h:141
friend TOutputStream & operator<<(TOutputStream &stream, const IPOQuotingMessage &message)
Limit Up – Limit Down (LULD) Auction Collar Message.
Definition: itch_handler.h:350
friend TOutputStream & operator<<(TOutputStream &stream, const LULDAuctionCollarMessage &message)
MWCB Decline Level Message.
Definition: itch_handler.h:113
friend TOutputStream & operator<<(TOutputStream &stream, const MWCBDeclineMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const MWCBStatusMessage &message)
Market Participant Position Message.
Definition: itch_handler.h:96
friend TOutputStream & operator<<(TOutputStream &stream, const MarketParticipantPositionMessage &message)
Net Order Imbalance Indicator (NOII) Message.
Definition: itch_handler.h:315
friend TOutputStream & operator<<(TOutputStream &stream, const NOIIMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const OrderCancelMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const OrderDeleteMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const OrderExecutedMessage &message)
Order Executed With Price Message.
Definition: itch_handler.h:207
friend TOutputStream & operator<<(TOutputStream &stream, const OrderExecutedWithPriceMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const OrderReplaceMessage &message)
Retail Price Improvement Indicator (RPII) Message.
Definition: itch_handler.h:336
friend TOutputStream & operator<<(TOutputStream &stream, const RPIIMessage &message)
Reg SHO Short Sale Price Test Restricted Indicator Message.
Definition: itch_handler.h:82
friend TOutputStream & operator<<(TOutputStream &stream, const RegSHOMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const StockDirectoryMessage &message)
Stock Trading Action Message.
Definition: itch_handler.h:66
friend TOutputStream & operator<<(TOutputStream &stream, const StockTradingActionMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const SystemEventMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const TradeMessage &message)
friend TOutputStream & operator<<(TOutputStream &stream, const UnknownMessage &message)