OnixS C++ Eurex T7 Market and Reference Data Interface (EMDI, RDI, EOBI) Handlers  7.4.2
API documentation
EobiBook.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 <vector>
23 #include <memory>
24 
27 
28 namespace OnixS
29 {
30  namespace Eurex
31  {
32  namespace MarketData
33  {
34  namespace EOBI
35  {
36  namespace Implementation
37  {
38  struct Order;
39  }
40 
41  typedef UInt64 OrderId;
42 
43  struct ONIXS_EUREX_EMDI_API OrderInfo
44  {
45  OrderInfo();
46  OrderInfo (OrderId orderId, QuantityType quantity);
47 
48  OrderId orderId_;
50  };
51 
52  typedef std::vector<OrderInfo> OrderInfos;
53 
54  /// Encapsulates price level concept.
55  struct ONIXS_EUREX_EMDI_API PriceLevel
56  {
57  /// Initializes the instances according to specified attributes.
58  PriceLevel (const Decimal& price, QuantityType quantity = 0, QuantityType numberOfOrders = 0, const OrderInfos& orders = OrderInfos() );
59  PriceLevel();
60 
62 
63  /// Validity check
64  bool isValid() const;
65 
66  /// Price value.
67  const Decimal& price() const;
68 
69  /// Quantify for the given price.
70  QuantityType quantity() const;
71 
72  /// Total number of orders of given price.
73  QuantityType numberOfOrders() const;
74 
75  /// orders ids for a given level
76  const OrderInfos& orders() const;
77 
78  /// swap values
79  void swap (PriceLevel&) throw();
80 
81  /// Returns string representation of the instance.
82  std::string toString() const;
83 
84  /// Appends representation of the instance to the string.
85  void toString (std::string&) const;
86 
87  private:
88  /// Updates price value.
89  void price (const Decimal& value);
90 
91  /// Updates quantity value.
92  void quantity (QuantityType value);
93 
94  /// add order id to the list
95  void addOrderId (OrderId id, QuantityType quantity);
96 
97  /// remove order id from the list
98  void removeOrderId (OrderId id);
99 
100  private:
101  Decimal price_;
102  Quantity qty_;
103  OrderInfos orders_;
104 
105  friend struct Implementation::Order;
106  };
107 
108  const Decimal& getPrice (const PriceLevel& level);
109 
110  bool isValid (const PriceLevel& level);
111 
112  ONIXS_EUREX_EMDI_API
113  std::ostream& operator << (std::ostream& stream, const PriceLevel& value);
114 
115  /// Miscellaneous traits for PriceLevel class.
116  struct ONIXS_EUREX_EMDI_API PriceLevelCollections
117  {
118  /// Sequential collection of price levels.
119  typedef std::vector<PriceLevel> Array;
120 
121  /// Mutable entry iterator.
122  typedef Array::iterator ArrayEntry;
123 
124  /// Iterator for read-only access.
125  typedef Array::const_iterator ArrayConstEntry;
126  };
127 
128  /// Sequence of price levels.
130 
131  /// Iterator to access price levels with write permissions.
133 
134  /// Iterator over read-only collection of price levels.
136 
137  class ONIXS_EUREX_EMDI_API OrderBook
138  {
139  public:
140  typedef PriceLevels PriceLevelsType;
141 
142  /// Base initialization.
143  OrderBook ();
144 
145  /// Destruction interface.
146  virtual ~OrderBook();
147 
148  /// Unique instrument Id as qualified
149  SecurityId securityId() const;
150 
151  /// Indicates whether book has no bids & asks.
152  bool empty() const;
153 
154  /// Returns a set of descending bid prices for the given security.
155  const PriceLevels& asks() const;
156 
157  /// Returns a set of ascending ask prices for the given security.
158  const PriceLevels& bids() const;
159 
160  /// Returns the maximum book depth.
161  size_t depth() const;
162 
163  /// String presentation of the book.
164  std::string toString() const;
165 
166  /// String presentation of the book.
167  void toString (std::string&) const;
168 
169  /// Returns brief book info.
170  std::string toShortString() const;
171 
172  /// Appends brief book info to the string.
173  void toShortString (std::string&) const;
174 
175  /// Returns formatted presentation of the book.
176  std::string toFormattedString() const;
177 
178  /// Appends Formatted presentation of the book.
179  void toFormattedString (std::string&) const;
180 
181  ///
182  bool bestAsk (Decimal& price, QuantityType& quantity) const;
183 
184  ///
185  bool bestBid (Decimal& price, QuantityType& quantity) const;
186 
187  /// sets user data pointer
188  void setUserPointer (void* pointer);
189 
190  /// returns kept user data pointer
191  void* getUserPointer() const;
192 
193  private:
194  virtual const PriceLevels& doAsks() const = 0;
195  virtual const PriceLevels& doBids() const = 0;
196  virtual SecurityId doSecurityId() const = 0;
197  virtual size_t doDepth() const = 0;
198  virtual bool doBestAsk (Decimal& price, QuantityType& quantity) const = 0;
199  virtual bool doBestBid (Decimal& price, QuantityType& quantity) const = 0;
200 
201  private:
202 
203  void* userPointer_;
204  };
205 
206 
207  ONIXS_EUREX_EMDI_API
208  std::ostream& operator << (std::ostream& stream, const OrderBook& book);
209 
210  /// checks whether the given book is properly built
211  void checkSanity (const OrderBook& book);
212  }
213  }
214  }
215 }
PriceLevelCollections::ArrayConstEntry PriceLevelsConstEntry
Iterator over read-only collection of price levels.
Definition: EobiBook.h:135
bool isValid(const PriceLevel &level)
Definition: EobiBook.cpp:171
PriceLevelCollections::ArrayEntry PriceLevelsEntry
Iterator to access price levels with write permissions.
Definition: EobiBook.h:132
void checkSanity(const OrderBook &book)
checks whether the given book is properly built
Definition: EobiBook.cpp:407
Definition: Defines.h:30
Decimal type for better precision.
Definition: Numeric.h:63
Int64 SecurityId
Alias for Security Id type.
Definition: Defines.h:51
Array::const_iterator ArrayConstEntry
Iterator for read-only access.
Definition: EobiBook.h:125
Array::iterator ArrayEntry
Mutable entry iterator.
Definition: EobiBook.h:122
Miscellaneous traits for PriceLevel class.
Definition: EobiBook.h:116
PriceLevelCollections::Array PriceLevels
Sequence of price levels.
Definition: EobiBook.h:129
TextBuilder & operator<<(TextBuilder &o, const BaseMsgData &msg)
Definition: Formatting.h:155
UInt64 Quantity
Alias for Quantity type.
Definition: Defines.h:54
std::vector< PriceLevel > Array
Sequential collection of price levels.
Definition: EobiBook.h:119
Encapsulates price level concept.
Definition: EobiBook.h:55
std::vector< OrderInfo > OrderInfos
Definition: EobiBook.h:52
const Decimal & getPrice(const Order &order)