OnixS C++ SGX Titan ITCH Market Data Handler  1.2.2
API documentation
HandlerImpl.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
5 *
6 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
7 * and international copyright treaties.
8 *
9 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
10 * Services Agreement (the Agreement) and Customer end user license agreements granting
11 * a non-assignable, non-transferable and non-exclusive license to use the software
12 * for it's own data processing purposes under the terms defined in the Agreement.
13 *
14 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
15 * of this source code or associated reference material to any other location for further reproduction
16 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
17 *
18 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
19 * the terms of the Agreement is a violation of copyright law.
20 */
21 #include <licensing/LicenseChecker.h>
22 
23 #include <OnixS/HandlerCore/MulticastFeedHandler.h>
24 
25 #include <OnixS/ItchCore/Types.h>
26 
30 #include <OnixS/ItchCore/MoldUDP64/PacketProcessor.h>
31 
32 
34 #include "GlimpsePacketProcessor.h"
35 
36 #include "NamespaceHelper.h"
37 
38 namespace OnixS {
39 
40 namespace HandlerCore { namespace Common {
41  class HandlerLogger;
42 }}
43 
44 namespace ItchCore { namespace MoldUDP64 {
45  class RetransmissionService;
46 }}
47 
48 }
49 
50 ONIXS_HANDLER_NAMESPACE_BEGIN
51 
52 struct ReplayOptions;
53 class GlimpseService;
54 
55 class ListenerHolder;
56 class MessageRepository;
57 class OrderBookAllocator;
58 
59 
61 typedef OnixS::ItchCore::MoldUDP64::PacketProcessor<HandlerImpl> RealtimePacketProcessor;
62 
63 class HandlerImpl : public Licensing::LicenseChecker, public HandlerCore::MarketData::MulticastFeedHandler
64 {
65  typedef HandlerCore::MarketData::MulticastFeedHandler base;
66 
67 public:
68  explicit
69  HandlerImpl(const HandlerSettings & settings);
70 
71  virtual ~HandlerImpl();
72 
73  void bindFeedEngine(FeedEngine& feedEngine);
74 
75  /// Start handler.
76  void start();
77 
78  /// Starts replaying previously logged data.
79  void start(const ReplayOptions& options);
80 
81  /// Stop handler.
82  void stop(bool wait);
83 
84  /// Returns commons services as shared object.
85  ListenerHolder& listenerHolder();
86 
87  /// Invoke helpers
88  void invokeError(const std::string& description) override;
89  void invokeWarning(const std::string& description) override;
90 
91  /// User's common log
92  void commonLog (int logLevel, const char * msg, size_t length);
93 
94  void setOrderBookIdFilter(const std::set<OrderBookId>& orderBookIdFilter);
95 
96 protected:
97  virtual void onStateChanged(State::Enum newState);
98  void onPrepareLogPlayer(HandlerCore::Common::LogPlayer* logPlayer);
99  bool parseGlimpseStart(const std::string& logLine, HandlerCore::Common::LogEntry&);
100 
101 private:
102  void onStarting() override;
103  void onStopping() override;
104 
105  void initLogger(const HandlerSettings &settings);
106  static std::string os();
107 
108  void onPacket(OnixS::HandlerCore::MarketData::FE::PacketContainer& packetContainer, bool fromCache);
109  void onHeartbeat(OnixS::HandlerCore::MarketData::FE::PacketContainer& packetContainer);
110  void onMulticastPacketGap(const OnixS::ItchCore::SessionType&, SequenceNumber expectedSeqNum, SequenceNumber receivedSeqNum);
111  void onMulticastInactivity();
112 
113 
114  void onReplayPacket(OnixS::HandlerCore::MarketData::FE::PacketContainer& packetContainer);
115 
116  void onReplayFailure(const ItchCore::SessionType&, SequenceNumber begin, ItchCore::Binary8 count);
117 
118  void onGlimpseFailure(const std::string& what);
119  void onGlimpseWarning(const std::string& what);
120  void onGlimpseMessage(const DataSource& dataSource, const IncomingMessage* message);
121  void onGlimpseRestarted();
122 
123  void initRetransmissionService();
124 
125 private:
126  HandlerSettings settings_;
127 
128  boost::scoped_ptr<OrderBookAllocator> bookAllocator_;
129  boost::scoped_ptr<HandlerCore::Common::HandlerLogger> logger_;
130 
131  boost::scoped_ptr<ListenerHolder> listenerHolder_;
132 
133  MulticastFeedClusterPtr realtimeFeeds_;
134  UnicastFeedClusterPtr gapResponseFeeds_;
135 
136  boost::scoped_ptr<RealtimePacketProcessor> realtimePacketProcessor_;
137 
138  boost::scoped_ptr<MessageRepository> messageRepository_;
139 
140  boost::scoped_ptr<OnixS::ItchCore::MoldUDP64::RetransmissionService> retransmissionService_;
141 
142  boost::scoped_ptr<GlimpseService> glimpseService_;
143 
144  bool backtestingMode_;
145  boost::scoped_ptr<RetransmissionPacketProcessor> retransmissionPacketProcessor_;
146  boost::scoped_ptr<GlimpsePacketProcessor> glimpsePacketProcessor_;
147 
148  friend class OnixS::ItchCore::MoldUDP64::PacketProcessor<HandlerImpl>;
149 };
150 
151 struct Handler::Impl : public HandlerImpl
152 {
154 
155 public:
156 Impl(const HandlerSettings & settings)
157  : base(settings)
158 {}
159 };
160 
161 ONIXS_HANDLER_NAMESPACE_END
162 
163 
UInt64 SequenceNumber
Alias for Sequence Number type.
Definition: Defines.h:37
OnixS::ItchCore::MoldUDP64::PacketProcessor< HandlerImpl > RealtimePacketProcessor
Definition: HandlerImpl.h:60
Defines ONIXS_SGXTITAN_ITCH_API which affect logs replay.
Definition: Replay.h:55
Impl(const HandlerSettings &settings)
Definition: HandlerImpl.h:156
Manages processing machinery for market data received from feeds.
Definition: FeedEngine.h:254