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