OnixS C++ SGX Titan ITCH Market Data Handler  1.2.2
API documentation
OrderBookHolder.h
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 #pragma once
21 
22 #include "BookImpl.h"
23 
24 #include <boost/functional/hash.hpp>
25 #include <boost/function.hpp>
26 
27 #include <map>
28 #include <set>
29 
30 #include <boost/scoped_ptr.hpp>
31 #include <boost/atomic.hpp>
32 
33 #include "NamespaceHelper.h"
34 
35 ONIXS_HANDLER_NAMESPACE_BEGIN
36 
37 struct AddOrderMsg;
38 struct OrderExecutedMsg;
39 struct OrderExecutedWithPriceMsg;
40 struct OrderReplaceMsg;
41 struct OrderDeleteMsg;
42 
43 class SnapshotOrder;
44 class OrderBookInternal;
45 
46 using OnixS::HandlerCore::MarketData::OrderBookRegistry;
47 
48 class ListenerHolder;
49 
50 static const size_t DefaultBookDepth = 5;
51 
52 class OrderBookCreator : public OnixS::HandlerCore::MarketData::FullOrderDepthBookCreator<OrderBookInternal, false>
53 {
54 public:
55  typedef OnixS::HandlerCore::MarketData::FullOrderDepthBookCreator<OrderBookInternal, false> FullOrderDepthBookCreator;
57 
58  OrderBookCreator(size_t bookDepth, OrderBookAllocator* bookAllocator);
59  OrderBookCreator(const OrderBookCreator& other);
60  boost::shared_ptr<OrderBookInternal> operator()(const OrderBookId& id) const;
61  void reset();
62 
63 private:
64  const size_t bookDepth_;
65  OrderBookAllocator* const bookAllocator_;
66 };
67 
68 
70 {
71 public:
72  typedef OrderBookRegistry<OrderBookId, OrderBookInternal, OrderBookCreator> BookRegistry;
73  typedef BookRegistry::BookPtr BookPtr;
74  typedef boost::function<void(const OrderBookInternal&)> OnOrderBookUpdatedCallback;
75 
76  OrderBookHolder(const OnOrderBookUpdatedCallback& onOrderBookUpdated, OrderBookAllocator* bookAllocator, size_t bookDepth = DefaultBookDepth);
77 
78  void onOrderAdd(const AddOrderMsg&);
79  void onOrderReplace(const OrderReplaceMsg&);
80  void onOrderExecuted(const OrderExecutedMsg&);
81  void onOrderExecutedWithPrice(const OrderExecutedWithPriceMsg&);
82  void onOrderDelete(const OrderDeleteMsg&);
83 
84 
85  void onBookOutOfDate(const boost::function<void(const OrderBookInternal&)>& onOrderBookOutOfDate);
86  void reset();
87 
88  void snapshotRecoveryStarted();
89  void snapshotRecoveryFinished();
90 
91 private:
92  template <typename OrderList>
93  bool checkOrderExistence(const OrderList& map, OrderId orderid, bool shouldExist);
94 
95  Side::Enum getOrderSide(BookPtr ptr, OrderId orderId);
96 
97  void onBookChanged(const OrderBookInternal& book);
98 
99 private:
100  boost::scoped_ptr<BookRegistry> impl_;
101  OnOrderBookUpdatedCallback onOrderBookUpdated_;
102 
103  typedef OnixS::PoolAllocator<BookPtr> BookPtrMapAllocator;
104  std::set<BookPtr, std::less<BookPtr>, BookPtrMapAllocator> books_;
105 
106  boost::atomic_bool snapshotRecoveryInProgress_;
107 };
108 
109 
110 ONIXS_HANDLER_NAMESPACE_END
OrderBookRegistry< OrderBookId, OrderBookInternal, OrderBookCreator > BookRegistry
UInt64 OrderId
Alias for OrderId type.
Definition: Defines.h:40
OnixS::HandlerCore::MarketData::FullOrderDepthBookCreator< OrderBookInternal, false > FullOrderDepthBookCreator
UInt32 OrderBookId
Alias for Security Id type.
Definition: Defines.h:43
boost::function< void(const OrderBookInternal &)> OnOrderBookUpdatedCallback