OnixS C++ SGX Titan ITCH Market Data Handler  1.2.2
API documentation
ListenerHolder.cpp
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable OnixS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #include <boost/function.hpp>
21 
22 #include "ListenerHolder.h"
23 
27 
29 
36 
38 
40 
41 #include "HandlerLogger.h"
42 #include "BookImpl.h"
43 
44 #include <boost/bind.hpp>
45 
46 using namespace OnixS::HandlerCore::Common;
47 
48 ONIXS_HANDLER_NAMESPACE_BEGIN
49 
50 ListenerHolder::ListenerHolder (const OnixS::Logging::LogFacility* parent, HandlerLogger* logger)
51  : base("ListenerHolder", parent, OnixS::Logging::LOG_LEVEL_DEBUG)
52  , logger_(logger)
53  , errorListener_(nullptr)
54  , warningListener_(nullptr)
55  , handlerStateListener_(nullptr)
56  , messageListener_(nullptr)
57  , timeListener_(nullptr)
58  , referenceDataListener_(nullptr)
59  , systemEventListener_(nullptr)
60  , orderListener_(nullptr)
61  , tradeListener_(nullptr)
62  , auctionListener_(nullptr)
63  , orderBookListener_(nullptr)
64 {
65 }
66 
67 void ListenerHolder::setLogger (HandlerLogger* handlerLogger)
68 {
69  BOOST_ASSERT(handlerLogger != nullptr);
70  logger_ = handlerLogger;
71 }
72 
73 /*
74  User callback's
75 */
76 
78  ErrorCode::Enum code, const std::string& description) ONIXS_NOEXCEPT
79 {
80  if (ErrorListener* listener = errorListener_)
81  {
82  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->onError(code, description), "onError");
83  }
84 }
85 
87  const std::string& description) ONIXS_NOEXCEPT
88 {
89  if (WarningListener* listener = warningListener_)
90  {
91  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->onWarning(description), "onWarning");
92  }
93 }
94 
96 {
97  if (HandlerStateListener* listener = handlerStateListener_)
98  {
99  ONIXS_EXCEPTION_TRACED_CALLBACK(listener->onStateChanged(newState), "onStateChanged");
100  }
101 }
102 
104  SequenceNumber expectedSeqNum, SequenceNumber receivedSeqNum) ONIXS_NOEXCEPT
105 {
106  if (messageListener_ != nullptr)
107  {
108  ONIXS_EXCEPTION_TRACED_CALLBACK(messageListener_->onGap(expectedSeqNum, receivedSeqNum), "onGap");
109  }
110 }
111 
112 void ListenerHolder::invokeInactivity() ONIXS_NOEXCEPT
113 {
114  if (messageListener_ != nullptr)
115  {
116  ONIXS_EXCEPTION_TRACED_CALLBACK(messageListener_->onInactivity(), "onInactivity");
117  }
118 }
119 
121  const SecondsMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
122 {
123  BOOST_ASSERT(msg != nullptr);
124 
125  if (timeListener_ != nullptr)
126  {
127  ONIXS_EXCEPTION_TRACED_CALLBACK(timeListener_->onSeconds(*msg, dataSource), "onSeconds");
128  }
129 }
130 
132  const OrderBookDirectoryMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
133 {
134  BOOST_ASSERT(msg != nullptr);
135 
136  if (referenceDataListener_ != nullptr)
137  {
138  ONIXS_EXCEPTION_TRACED_CALLBACK(referenceDataListener_->onOrderBookDirectory(*msg, dataSource), "onOrderBookDirectory");
139  }
140 }
141 
143  const CombinationOrderBookLegMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
144 {
145  BOOST_ASSERT(msg != nullptr);
146 
147  if (referenceDataListener_ != nullptr)
148  {
149  ONIXS_EXCEPTION_TRACED_CALLBACK(referenceDataListener_->onCombinationOrderBookLeg(*msg, dataSource), "onCombinationOrderBookLeg");
150  }
151 }
152 
154  const TickSizeTableEntryMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
155 {
156  BOOST_ASSERT(msg != nullptr);
157 
158  if (referenceDataListener_ != nullptr)
159  {
160  ONIXS_EXCEPTION_TRACED_CALLBACK(referenceDataListener_->onTickSizeTableEntry(*msg, dataSource), "onTickSizeTableEntry");
161  }
162 }
163 
165  const SystemEventMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
166 {
167  BOOST_ASSERT(msg != nullptr);
168 
169  if (systemEventListener_ != nullptr)
170  {
171  ONIXS_EXCEPTION_TRACED_CALLBACK(systemEventListener_->onSystemEvent(*msg, dataSource), "onSystemEvent");
172  }
173 }
174 
176  const OrderBookStateMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
177 {
178  BOOST_ASSERT(msg != nullptr);
179 
180  if (systemEventListener_ != nullptr)
181  {
182  ONIXS_EXCEPTION_TRACED_CALLBACK(systemEventListener_->onOrderBookState(*msg, dataSource), "onOrderBookState");
183  }
184 }
185 
187  const AddOrderMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
188 {
189  BOOST_ASSERT(msg != nullptr);
190 
191  if (orderListener_ != nullptr)
192  {
193  ONIXS_EXCEPTION_TRACED_CALLBACK(orderListener_->onAddOrder(*msg, dataSource), "onAddOrder");
194  }
195 }
196 
198  const OrderExecutedMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
199 {
200  BOOST_ASSERT(msg != nullptr);
201 
202  if (orderListener_ != nullptr)
203  {
204  ONIXS_EXCEPTION_TRACED_CALLBACK(orderListener_->onOrderExecuted(*msg, dataSource), "onOrderExecuted");
205  }
206 }
207 
209  const OrderExecutedWithPriceMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
210 {
211  BOOST_ASSERT(msg != nullptr);
212 
213  if (orderListener_ != nullptr)
214  {
215  ONIXS_EXCEPTION_TRACED_CALLBACK(orderListener_->onOrderExecutedWithPrice(*msg, dataSource), "onOrderExecutedWithPrice");
216  }
217 }
218 
220  const OrderReplaceMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
221 {
222  BOOST_ASSERT(msg != nullptr);
223 
224  if (orderListener_ != nullptr)
225  {
226  ONIXS_EXCEPTION_TRACED_CALLBACK(orderListener_->onOrderReplace(*msg, dataSource), "onOrderReplace");
227  }
228 }
229 
231  const OrderDeleteMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
232 {
233  BOOST_ASSERT(msg != nullptr);
234 
235  if (orderListener_ != nullptr)
236  {
237  ONIXS_EXCEPTION_TRACED_CALLBACK(orderListener_->onOrderDelete(*msg, dataSource), "onOrderDelete");
238  }
239 }
240 
242  const TradeMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
243 {
244  BOOST_ASSERT(msg != nullptr);
245 
246  if (tradeListener_ != nullptr)
247  {
248  ONIXS_EXCEPTION_TRACED_CALLBACK(tradeListener_->onTrade(*msg, dataSource), "onTrade");
249  }
250 }
251 
253  const EquilibriumPriceUpdateMsg* msg, const DataSource& dataSource) ONIXS_NOEXCEPT
254 {
255  BOOST_ASSERT(msg != nullptr);
256 
257  if (tradeListener_ != nullptr)
258  {
259  ONIXS_EXCEPTION_TRACED_CALLBACK(auctionListener_->onEquilibriumPriceUpdate(*msg, dataSource), "onEquilibriumPriceUpdate");
260  }
261 }
262 
264  const OrderBookInternal& book) ONIXS_NOEXCEPT
265 {
266  if (orderBookListener_ != nullptr)
267  {
268  ONIXS_EXCEPTION_TRACED_CALLBACK(orderBookListener_->onOrderBookUpdated(book), "onOrderBookUpdated");
269  }
270 }
271 
273 {
274  if (orderBookListener_ != nullptr)
275  {
276  ONIXS_EXCEPTION_TRACED_CALLBACK(orderBookListener_->onOrderBookOutOfDate(book), "onOrderBookOutOfDate");
277  }
278 }
279 
281 {
282  if (messageListener_ != nullptr)
283  {
284  ONIXS_EXCEPTION_TRACED_CALLBACK(messageListener_->onEndOfSession(), "onEndOfSession");
285  }
286 }
287 
289 {
290  if (messageListener_ != nullptr)
291  {
292  ONIXS_EXCEPTION_TRACED_CALLBACK(messageListener_->onSnapshotRecoveryStarted(), "onSnapshotRecoveryStarted");
293  }
294 }
295 
297 {
298  if (messageListener_ != nullptr)
299  {
300  ONIXS_EXCEPTION_TRACED_CALLBACK(messageListener_->onSnapshotRecoveryFinished(), "onSnapshotRecoveryFinished");
301  }
302 }
303 
304 void ListenerHolder::reportError(const std::string& description)
305 {
306  logger_->log(ONIXS_LOG_DEBUG[this] << description);
307 }
308 
309 ONIXS_HANDLER_NAMESPACE_END
void invokeOrderExecutedWithPrice(const OrderExecutedWithPriceMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
void invokeAddOrder(const AddOrderMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
void invokeGap(SequenceNumber expectedSeqNum, SequenceNumber receivedSeqNum) ONIXS_NOEXCEPT
virtual void onOrderBookState(const OrderBookStateMsg &msg, const DataSource &dataSource)=0
Is invoked when OrderBookStateMsg received.
virtual void onSystemEvent(const SystemEventMsg &msg, const DataSource &dataSource)=0
Is invoked when SystemEventMsg received.
void invokeOrderReplace(const OrderReplaceMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
void invokeOrderBookState(const OrderBookStateMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
UInt64 SequenceNumber
Alias for Sequence Number type.
Definition: Defines.h:37
virtual void onOrderExecutedWithPrice(const OrderExecutedWithPriceMsg &msg, const DataSource &dataSource)=0
Is invoked when OrderExecutedWithPriceMsg received.
void invokeEquilibriumPriceUpdate(const EquilibriumPriceUpdateMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
virtual void onOrderReplace(const OrderReplaceMsg &msg, const DataSource &dataSource)=0
Is invoked when OrderReplaceMsg received.
void invokeOrderBookUpdated(const OrderBookInternal &book) ONIXS_NOEXCEPT
virtual void onEquilibriumPriceUpdate(const EquilibriumPriceUpdateMsg &msg, const DataSource &dataSource)=0
Is invoked when TradeMsg received.
void invokeOrderBookDirectory(const OrderBookDirectoryMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
void invokeOrderBookOutOfDate(const OrderBookInternal &book) ONIXS_NOEXCEPT
virtual void onOrderExecuted(const OrderExecutedMsg &msg, const DataSource &dataSource)=0
Is invoked when OrderExecutedMsg received.
void invokeTime(const SecondsMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
Enum
Defines the state that the handler is in.
virtual void onOrderBookDirectory(const OrderBookDirectoryMsg &msg, const DataSource &dataSource)=0
Is invoked when OrderBookDirectoryMsg received.
virtual void onSnapshotRecoveryFinished()=0
is invoked when snapshot recovery finished
virtual void onEndOfSession()=0
is invoking when end of session event received
void setLogger(HandlerCore::Common::HandlerLogger *handlerLogger)
virtual void onOrderDelete(const OrderDeleteMsg &msg, const DataSource &dataSource)=0
Is invoked when OrderDeleteMsg received.
void invokeOrderDelete(const OrderDeleteMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
virtual void onAddOrder(const AddOrderMsg &msg, const DataSource &dataSource)=0
Is invoked when AddOrderMsg received.
virtual void onOrderBookUpdated(const OrderBook &book)=0
Is called when the book is updated.
void invokeTrade(const TradeMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
void invokeWarning(const std::string &description) ONIXS_NOEXCEPT
virtual void onInactivity()=0
is invoking when inactivity happens
virtual void onSnapshotRecoveryStarted()=0
is invoked when snapshot recovery started
void invokeStateChanged(HandlerState::Enum newState) ONIXS_NOEXCEPT
virtual void onSeconds(const SecondsMsg &time, const DataSource &dataSource)=0
void invokeOrderExecuted(const OrderExecutedMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
virtual void onCombinationOrderBookLeg(const CombinationOrderBookLegMsg &msg, const DataSource &dataSource)=0
Is invoked when CombinationOrderBookLegMsg received.
void invokeCombinationOrderBookLeg(const CombinationOrderBookLegMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
virtual void onOrderBookOutOfDate(const OrderBook &book)=0
virtual void onTickSizeTableEntry(const TickSizeTableEntryMsg &msg, const DataSource &dataSource)=0
Is invoked when TickSizeTableEntryMsg received.
void invokeTickSizeTableEntry(const TickSizeTableEntryMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
void invokeError(ErrorCode::Enum code, const std::string &description) ONIXS_NOEXCEPT
#define ONIXS_EXCEPTION_TRACED_CALLBACK(callback, contextName)
virtual void onGap(SequenceNumber expectedSeqNum, SequenceNumber receivedSeqNum)=0
is invoke when Gap happens
virtual void onTrade(const TradeMsg &msg, const DataSource &dataSource)=0
Is invoked when TradeMsg received.
void invokeSystemEvent(const SystemEventMsg *msg, const DataSource &dataSource) ONIXS_NOEXCEPT
Enum
Known (selected) error codes.
Definition: ErrorListener.h:34