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