OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.4.2
API documentation
EobiBookImpl.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 
21 
22 #include "EobiBookImpl.h"
23 #include "EobiBookSnapshot.h"
24 #include "../BookSanityChecker.h"
25 
26 
27 namespace OnixS {
28 namespace Eurex {
29 namespace MarketData {
30 namespace EOBI {
31 namespace Implementation {
32 
33 
35  id_(0),
36  price_(),
37  quantity_(0)
38 {
39 }
40 
41 Order::Order(const OrderId& inId, const Decimal& inPrice, QuantityType inQuantity) :
42  id_(inId),
43  price_(inPrice),
44  quantity_(inQuantity)
45 {
46 }
47 
48 void Order::addOrder(const Order& order, PriceLevel& level)
49 {
50  BOOST_ASSERT(level.numberOfOrders() == (QuantityType)level.orders().size());
51 
52  level.quantity(level.quantity() + order.quantity_);
53  level.addOrderId(order.id_, order.quantity_);
54 
55  BOOST_ASSERT(level.quantity() >= level.numberOfOrders());
56  BOOST_ASSERT(level.numberOfOrders() == (QuantityType)level.orders().size());
57 }
58 
59 void Order::removeOrder(const Order& order, PriceLevel& level)
60 {
61  BOOST_ASSERT(level.quantity() >= order.quantity_);
62  BOOST_ASSERT(level.numberOfOrders() > 0);
63  BOOST_ASSERT(level.quantity() >= level.numberOfOrders());
64  BOOST_ASSERT(level.numberOfOrders() == (QuantityType)level.orders().size());
65 
66  level.quantity(level.quantity() - order.quantity_);
67  level.removeOrderId(order.id_);
68 
69  BOOST_ASSERT(level.quantity() >= level.numberOfOrders());
70  BOOST_ASSERT(level.numberOfOrders() == (QuantityType)level.orders().size());
71 }
72 
73 void addOrder(const Order& order, PriceLevel& level)
74 {
75  Order::addOrder(order, level);
76 }
77 
78 void removeOrder(const Order& order, PriceLevel& level)
79 {
80  Order::removeOrder(order, level);
81 }
82 
83 const OrderId& getOrderId(const Order& order)
84 {
85  return order.id_;
86 }
87 
88 const Decimal& getPrice(const Order& order)
89 {
90  return order.price_;
91 }
92 
93 bool isOrderAffectsPriceLevel (const Order& order)
94 {
95  return (order.price_ != Decimal(0, 0)) && (order.quantity_ != 0);
96 }
97 
99 (
100  const SecurityId& id,
101  size_t bookDepth,
102  size_t maxAggregatedPriceLevelsCount,
103  const PoolManagerPtr& poolManager
104  ) :
105  OrderDepthBook(maxAggregatedPriceLevelsCount, bookDepth, poolManager),
106  bookDepth_(bookDepth),
107  id_(id)
108 {
109 }
110 
111 size_t OrderBookInternal::doDepth() const
112 {
113  return bookDepth_;
114 }
115 
116 const PriceLevels& OrderBookInternal::doAsks() const
117 {
118  return OrderDepthBook::askOrders().levels().levels();
119 }
120 
121 const PriceLevels& OrderBookInternal::doBids() const
122 {
123  return OrderDepthBook::bidOrders().levels().levels();
124 }
125 
126 bool OrderBookInternal::doBestAsk(Price& price, QuantityType& quantity) const
127 {
128  OnixS::HandlerCore::MarketData::PriceLevelList<PriceLevel> priceLevelList;
129  OrderDepthBook::askOrders().levels().normalize(priceLevelList);
130 
131  if(priceLevelList.size() == 0)
132  return false;
133 
134  priceLevelList.sort(OnixS::HandlerCore::MarketData::PriceLevelLessSortPredicate());
135 
136  const PriceLevel& level = priceLevelList.get(0);
137  price = level.price();
138  quantity = level.quantity();
139 
140  return true;
141 }
142 
143 bool OrderBookInternal::doBestBid(Price& price, QuantityType& quantity) const
144 {
145  OnixS::HandlerCore::MarketData::PriceLevelList<PriceLevel> priceLevelList;
146  OrderDepthBook::bidOrders().levels().normalize(priceLevelList);
147 
148  if(priceLevelList.size() == 0)
149  return false;
150 
151  priceLevelList.sort(OnixS::HandlerCore::MarketData::PriceLevelGreaterSortPredicate());
152 
153  const PriceLevel& level = priceLevelList.get(0);
154  price = level.price();
155  quantity = level.quantity();
156 
157  return true;
158 }
159 
160 SecurityId OrderBookInternal::doSecurityId() const
161 {
162  return id_;
163 }
164 /*
165 boost::scoped_ptr<OrderBook> OrderBookInternal::doSnapshot() const
166 {
167  boost::scoped_ptr<OrderBook> ptr(new OrderBookSnapshot(*this));
168  return ptr;
169 }
170 */
171 void OrderBookInternal::operator delete (void* book)
172 {
173  BOOST_ASSERT(book != nullptr);
174  (void)book;
175 }
176 
177 
179 {
181  checker.checkSanity();
182  checker.checkBestsSanitry();
183 }
184 
185 
187 {
188  return OrderDepthBook::askOrders();
189 }
190 
192 {
193  return OrderDepthBook::askOrders();
194 }
195 
197 {
198  return OrderDepthBook::bidOrders();
199 }
200 
202 {
203  return OrderDepthBook::bidOrders();
204 }
205 
206 void OrderBookInternal::remove(const OrderId& orderId)
207 {
208  return OrderDepthBook::remove(orderId);
209 }
210 
212 {
213  OrderDepthBook::clear();
214 }
215 
216 
218  poolSize_(objectsAmount * sizeof(OrderBookInternal)),
219  poolPtr_(poolSize_, 0),
220  allocator_(&poolPtr_.front(), poolSize_)
221 {
222 }
223 
225 {
226  allocator_.reset();
227 }
228 
230 {
231  return allocator_.allocate(sizeof(OrderBookInternal));
232 }
233 
235 {
236  allocator_.reset();
237 }
238 
239 size_t hash_value(OrderBookInternal const& book)
240 {
241  size_t seed = 0;
242 
243  const PriceLevels& asks = book.asks();
244  for(PriceLevels::const_iterator i = asks.begin(), end = asks.end(); i < end; ++i)
245  {
246  boost::hash_combine(seed, i->quantity());
247  boost::hash_combine(seed, i->numberOfOrders());
248  boost::hash_combine(seed, (Int64)i->price());
249  }
250 
251  const PriceLevels& bids = book.bids();
252  for(PriceLevels::const_iterator i = bids.begin(), end = bids.end(); i < end; ++i)
253  {
254  boost::hash_combine(seed, i->quantity());
255  boost::hash_combine(seed, i->numberOfOrders());
256  boost::hash_combine(seed, (Int64)i->price());
257  }
258 
259  return seed;
260 }
261 
262 
263 }}}}}
QuantityType numberOfOrders() const
Total number of orders of given price.
Definition: EobiBook.cpp:123
bool isOrderAffectsPriceLevel(const Order &order)
Definition: Defines.h:30
Decimal type for better precision.
Definition: Numeric.h:63
size_t hash_value(OrderBookInternal const &book)
const OrderId & getOrderId(const Order &order)
Int64 SecurityId
Alias for Security Id type.
Definition: Defines.h:51
static void removeOrder(const Order &order, PriceLevel &level)
static void addOrder(const Order &order, PriceLevel &level)
const Decimal & price() const
Price value.
Definition: EobiBook.cpp:103
PriceLevelCollections::Array PriceLevels
Sequence of price levels.
Definition: EobiBook.h:129
const PriceLevels & asks() const
Returns a set of descending bid prices for the given security.
Definition: EobiBook.cpp:258
OnixS::HandlerCore::MarketData::FullOrderDepthBook< PriceLevel, Order, OrderId, Decimal, BaseFullOrderDepthBook > OrderDepthBook
Definition: EobiBookImpl.h:63
OrderBookInternal(const SecurityId &id, size_t bookDepth, size_t maxAggregatedPriceLevelsCount=(size_t)-1, const PoolManagerPtr &poolManager=PoolManagerPtr())
QuantityType quantity() const
Quantify for the given price.
Definition: EobiBook.cpp:113
const PriceLevels & bids() const
Returns a set of ascending ask prices for the given security.
Definition: EobiBook.cpp:263
Encapsulates price level concept.
Definition: EobiBook.h:55
const Decimal & getPrice(const Order &order)
const OrderInfos & orders() const
orders ids for a given level
Definition: EobiBook.cpp:128