OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.2.2
API documentation
OrderBook.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 
23 
24 #include <vector>
25 
26 namespace OnixS
27 {
28  namespace Eurex
29  {
30  namespace MarketData
31  {
32  /// Encapsulates price level concept.
33  struct ONIXS_EUREX_EMDI_API PriceLevel
34  {
35  public:
36  /// Default initialization.
37  PriceLevel();
38 
39  /// Initializes the instances according to specified attributes.
40  PriceLevel (Decimal price, Quantity quantity, Quantity numberOfOrders);
41 
42  /// Price value.
43  Decimal price() const;
44 
45  /// Updates price value.
46  void price (Decimal value);
47 
48  /// Quantify for the given price.
49  Quantity quantity() const;
50 
51  /// Updates quantity value.
52  void quantity (Quantity value);
53 
54  /// Total number of orders of given price.
55  Quantity numberOfOrders() const;
56 
57  /// Updates total number of orders.
58  void numberOfOrders (Quantity value);
59 
60  /// Returns string representation of the instance.
61  std::string toString() const;
62 
63  /// Appends representation of the instance to the string.
64  void toString (std::string&) const;
65 
66  protected:
68 
71  };
72 
73  ///
74  bool operator ==(const PriceLevel& l, const PriceLevel& r);
75 
76  ///
77  std::ostream& operator<< (std::ostream& s, const PriceLevel& lvl);
78 
79 
80  inline Decimal PriceLevel::price() const
81  {
82  return price_;
83  }
84 
85  inline void PriceLevel::price (Decimal value)
86  {
87  price_ = value;
88  }
89 
91  {
92  return qty_;
93  }
94 
95  inline void PriceLevel::quantity (Quantity value)
96  {
97  qty_ = value;
98  }
99 
101  {
102  return ordersQty_;
103  }
104 
106  {
107  ordersQty_ = value;
108  }
109 
110  inline std::string PriceLevel::toString() const
111  {
112  std::string str;
113 
114  toString (str);
115 
116  return str;
117  }
118 
119  bool isValid (const PriceLevel& level);
120 
121  /// Miscellaneous traits for PriceLevel class.
122  struct ONIXS_EUREX_EMDI_API PriceLevelCollections
123  {
124  /// Sequential collection of price levels.
125  typedef std::vector<PriceLevel> Array;
126 
127  /// Mutable entry iterator.
128  typedef Array::iterator ArrayEntry;
129 
130  /// Iterator for read-only access.
131  typedef Array::const_iterator ArrayConstEntry;
132  };
133 
134  /// Sequence of price levels.
136 
137  /// Iterator to access price levels with write permissions.
139 
140  /// Iterator over read-only collection of price levels.
142 
143  /// Order Book.
144  ///
145  /// A set of bid prices and ask prices for the given
146  /// security (bids are descending and asks are ascending).
147  /// The quantity is provided at each price level.
148  class ONIXS_EUREX_EMDI_API OrderBook
149  {
150  public:
151  typedef PriceLevels PriceLevelsType;
152 
153  /// Destruction interface.
154  virtual ~OrderBook();
155 
156  /// Unique instrument Id (tag 48) as qualified
157  /// by the exchange per tag 22-SecurityIDSource.
158  SecurityId securityId() const;
159 
160  /// Sequence number of the last processed message
161  virtual UInt32 lastMsgSeqNumProcessed() const = 0;
162 
163  /// Returns the maximum book depth.
164  size_t depth() const;
165 
166  /// Indicates whether book has no bids & asks.
167  bool empty() const;
168 
169  /// Returns a set of descending bid prices for the given security.
170  virtual const PriceLevels& asks() const = 0;
171 
172  /// Returns a set of ascending ask prices for the given security.
173  virtual const PriceLevels& bids() const = 0;
174 
175  /// Returns best implied ask
176  virtual bool bestAsk (Decimal& price, Quantity& quantity) const = 0;
177 
178  /// Returns best implied bid
179  virtual bool bestBid (Decimal& price, Quantity& quantity) const = 0;
180 
181  /// For bids and offers the official time of book entry, for trades official time of execution (all in nanoseconds).
182  virtual UInt64 mdEntryTime () const = 0;
183 
184  /// String presentation of the book.
185  std::string toString() const;
186 
187  /// String presentation of the book.
188  void toString (std::string&) const;
189 
190  /// Returns brief book info.
191  std::string toShortString() const;
192 
193  /// Appends brief book info to the string.
194  void toShortString (std::string&) const;
195 
196  /// Returns formatted presentation of the book.
197  std::string toFormattedString() const;
198 
199  /// Appends Formatted presentation of the book.
200  void toFormattedString (std::string&) const;
201 
202  /// Creates immutable snapshot of the book.
203  OrderBook* snapshot() const;
204 
205  /// Allocation operator to avoid runtime collision.
206  /// Primarily designed for snapshot/cloning.
207  void* operator new (size_t bookSize);
208 
209  /// De-allocating operator to avoid runtime collision.
210  /// Primarily designed for snapshot/cloning.
211  void operator delete (void* book);
212 
213  protected:
214  // Security id.
216 
217  // Depth (max num. of price levels) of book.
218  size_t depth_;
219 
220  // Base initialization.
221  OrderBook (SecurityId securityId, size_t bookDepth);
222 
223  private:
224  // No public copies are allowed.
225  // Snapshot creation is exposed instead.
226 
227  OrderBook (const OrderBook& book);
228  OrderBook& operator= (const OrderBook& book);
229  };
230 
231  /// checks whether the given book is properly built
232  void checkSanity (const OrderBook& book);
233 
235  {
236  return securityId_;
237  }
238 
239  inline size_t OrderBook::depth() const
240  {
241  return depth_;
242  }
243 
244  inline bool OrderBook::empty() const
245  {
246  return bids().empty() && asks().empty();
247  }
248 
249  inline std::string OrderBook::toString() const
250  {
251  std::string str;
252 
253  toString (str);
254 
255  return str;
256  }
257 
258  inline std::string OrderBook::toShortString() const
259  {
260  std::string str;
261 
262  toShortString (str);
263 
264  return str;
265  }
266 
267  inline std::string OrderBook::toFormattedString() const
268  {
269  std::string str;
270 
271  toFormattedString (str);
272 
273  return str;
274  }
275  }
276  }
277 }
void checkSanity(const OrderBook &book)
checks whether the given book is properly built
Definition: OrderBook.cpp:254
bool operator==(const FieldValueRef &ref, const std::string &str)
PriceLevelCollections::ArrayEntry PriceLevelsEntry
Iterator to access price levels with write permissions.
Definition: OrderBook.h:138
Quantity numberOfOrders() const
Total number of orders of given price.
Definition: OrderBook.h:100
std::vector< PriceLevel > Array
Sequential collection of price levels.
Definition: OrderBook.h:125
Encapsulates price level concept.
Definition: OrderBook.h:33
Decimal price() const
Price value.
Definition: OrderBook.h:80
bool empty() const
Indicates whether book has no bids & asks.
Definition: OrderBook.h:244
unsigned int UInt32
Definition: Numeric.h:41
Definition: Defines.h:30
Decimal type for better precision.
Definition: Numeric.h:63
std::string toString() const
Returns string representation of the instance.
Definition: OrderBook.h:110
SecurityId securityId() const
Definition: OrderBook.h:234
PriceLevelCollections::Array PriceLevels
Sequence of price levels.
Definition: OrderBook.h:135
Int64 SecurityId
Alias for Security Id type.
Definition: Defines.h:51
bool isValid(const PriceLevel &level)
Definition: OrderBook.cpp:63
std::string toFormattedString() const
Returns formatted presentation of the book.
Definition: OrderBook.h:267
size_t depth() const
Returns the maximum book depth.
Definition: OrderBook.h:239
ONIXS_EUREX_EMDI_API std::ostream & operator<<(std::ostream &stream, const FeedEngineSettings &settings)
Array::iterator ArrayEntry
Mutable entry iterator.
Definition: OrderBook.h:128
PriceLevelCollections::ArrayConstEntry PriceLevelsConstEntry
Iterator over read-only collection of price levels.
Definition: OrderBook.h:141
std::string toString() const
String presentation of the book.
Definition: OrderBook.h:249
Quantity quantity() const
Quantify for the given price.
Definition: OrderBook.h:90
UInt64 Quantity
Alias for Quantity type.
Definition: Defines.h:54
Miscellaneous traits for PriceLevel class.
Definition: OrderBook.h:122
std::string toShortString() const
Returns brief book info.
Definition: OrderBook.h:258
Array::const_iterator ArrayConstEntry
Iterator for read-only access.
Definition: OrderBook.h:131