OnixS ICE iMpact Multicast Price Feed Handler C++ library  8.18.0
API documentation
OrderBook.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Onix Solutions Limited. All rights reserved.
3  *
4  * This software owned by Onix Solutions Limited 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 "Containers.h"
23 #include "Export.h"
24 #include "Rational.h"
25 #include "Time.h"
26 #include "Types.h"
27 
28 namespace OnixS { namespace ICE { namespace iMpact { namespace MarketData {
29 
30 /// forward declarations
31 class OrderBookHolder;
32 
33 /// \brief Defines data for single price level of order book.
34 struct ONIXS_ICEMDH_EXPORT PriceLevel
35 {
36  typedef Rational Price;
37 
38  /// Raw exchange price (fixed point).
40 
41  /// Total order quantity at price.
42  int quantity;
43 
44  /// Implied order quantity at price.
46 
47  /// Order count at price.
48  short orderCount;
49 
50  /// Implied order count at price.
52 
53  /// Constructor.
54  explicit PriceLevel(
55  const Rational& inPrice = Rational(),
56  int inQuantity = 0,
57  int inImpliedQuantity = 0,
58  short inOrderCount = 0,
59  short inImpliedOrderCount = 0
60  )
61  : price(inPrice)
62  , quantity(inQuantity)
63  , impliedQuantity(inImpliedQuantity)
64  , orderCount(inOrderCount)
65  , impliedOrderCount(inImpliedOrderCount)
66  {
67  }
68 };
69 
70 /// /brief Defines data for single entry of full order depth book.
71 struct ONIXS_ICEMDH_EXPORT Order
72 {
74 
75  /// Order ID unique for market.
76  OrderId orderId;
77 
78  /// Order entry date/time (milliseconds since 01-01-1970 00:00 GMT).
80 
81  /// Raw exchange price (fixed point).
83 
84  /// Order quantity.
85  int quantity;
86 
87  /// Sub-milliseconds ordering sequence.
89 
90  /// Legacy order modification count.
92 
93  /// True if order is implied.
94  bool isImplied;
95 
96  /// True if order is Request For Quote.
97  bool isRFQ;
98 
99  /// Constructor.
100  explicit Order(
101  OrderId inOrderId = OrderId(),
102  const DateTime& inEntryDateTime = DateTime(),
103  const Rational& inPrice = Rational(),
104  int inQuantity = 0,
105  int inSequenceWithinMillis = 0,
106  short inOrderSequenceId = 0,
107  bool inIsImplied = false,
108  bool inIsRFQ = false
109  )
110  : orderId(inOrderId)
111  , entryDateTime(inEntryDateTime)
112  , price(inPrice)
113  , quantity(inQuantity)
114  , sequenceWithinMillis(inSequenceWithinMillis)
115  , orderSequenceId(inOrderSequenceId)
116  , isImplied(inIsImplied)
117  , isRFQ(inIsRFQ)
118  {
119  }
120 };
121 
124 
125 /// \brief Book instance composing price level book and full order depth book.
126 class ONIXS_ICEMDH_EXPORT OrderBook
127 {
128 public:
129  /// Unique identifier of a market.
130  MarketId marketId() const;
131 
132  /// Returns the maximum book depth.
133  std::size_t depth() const;
134 
135  /// Indicates whether book has no bids & asks.
136  bool empty() const;
137 
138  /// Gets bid side of the price level book.
139  /// The bids are stored in descending order based on price.
140  ///
141  /// \note Could be affected by the bid orders.
142  const PriceLevelArray& bids() const;
143 
144  /// Gets offer side of the price level book.
145  /// The offers are stored in ascending order based on price.
146  ///
147  /// \note Could be affected by the offer orders.
148  const PriceLevelArray& offers() const;
149 
150  /// Gets bid side of the full order depth book.
151  /// The bid orders are stored in order of arrival.
152  ///
153  /// \note Always empty for price level books.
154  const OrderArray& bidOrders() const;
155 
156  /// Gets offer side of the full order depth book.
157  /// The offer orders are stored in order of arrival.
158  ///
159  /// \note Always empty for price level books.
160  const OrderArray& offerOrders() const;
161 
162  /// Returns brief book info.
163  std::string brief() const;
164 
165  /// Appends brief book info to the string.
166  void brief(std::string&) const;
167 
168  /// String presentation of the book.
169  std::string toString() const;
170 
171  /// String presentation of the book.
172  void toString(std::string&) const;
173 
174  /// Creates immutable snapshot of the book owned by caller.
175  /// It's responsibility of caller to delete returned snapshot.
176  const OrderBook* snapshot() const;
177 
178  /// Destructor
179  ~OrderBook();
180 
181 private:
182  friend class OrderBookHolder;
183  struct Impl;
184 
185  OrderBook(Impl*);
186 
187  // No implementation
188  OrderBook(const OrderBook&);
189  OrderBook& operator=(const OrderBook&);
190 
191  Impl* impl_;
192 };
193 
194 inline std::string OrderBook::brief() const
195 {
196  std::string str;
197  brief(str);
198  return str;
199 }
200 
201 inline std::string OrderBook::toString() const
202 {
203  std::string str;
204  toString(str);
205  return str;
206 }
207 
208 }}}} // namespace OnixS::ICE::iMpact::MarketData
Rational price
Raw exchange price (fixed point).
Definition: OrderBook.h:82
/brief Defines data for single entry of full order depth book.
Definition: OrderBook.h:71
Defines data for single price level of order book.
Definition: OrderBook.h:34
Rational price
Raw exchange price (fixed point).
Definition: OrderBook.h:39
ArrayRef< const Order, std::size_t > OrderArray
Definition: OrderBook.h:123
bool isImplied
True if order is implied.
Definition: OrderBook.h:94
short orderSequenceId
Legacy order modification count.
Definition: OrderBook.h:91
short orderCount
Order count at price.
Definition: OrderBook.h:48
int sequenceWithinMillis
Sub-milliseconds ordering sequence.
Definition: OrderBook.h:88
OnixS::ICE::iMpact::MarketData::OrderId OrderId
Definition: OrderBook.h:73
OrderId orderId
Order ID unique for market.
Definition: OrderBook.h:76
int MarketId
Alias for market identifiers type.
Definition: Types.h:39
std::string toString() const
String presentation of the book.
Definition: OrderBook.h:201
Rational number representation.
Definition: Rational.h:30
std::string brief() const
Returns brief book info.
Definition: OrderBook.h:194
int quantity
Total order quantity at price.
Definition: OrderBook.h:42
DateTime entryDateTime
Order entry date/time (milliseconds since 01-01-1970 00:00 GMT).
Definition: OrderBook.h:79
Book instance composing price level book and full order depth book.
Definition: OrderBook.h:126
bool isRFQ
True if order is Request For Quote.
Definition: OrderBook.h:97
PriceLevel(const Rational &inPrice=Rational(), int inQuantity=0, int inImpliedQuantity=0, short inOrderCount=0, short inImpliedOrderCount=0)
Constructor.
Definition: OrderBook.h:54
Order(OrderId inOrderId=OrderId(), const DateTime &inEntryDateTime=DateTime(), const Rational &inPrice=Rational(), int inQuantity=0, int inSequenceWithinMillis=0, short inOrderSequenceId=0, bool inIsImplied=false, bool inIsRFQ=false)
Constructor.
Definition: OrderBook.h:100
int impliedQuantity
Implied order quantity at price.
Definition: OrderBook.h:45
ArrayRef< const PriceLevel, std::size_t > PriceLevelArray
Definition: OrderBook.h:122
short impliedOrderCount
Implied order count at price.
Definition: OrderBook.h:51
long long OrderId
Alias for order identifiers type.
Definition: Types.h:42
long long DateTime
Represents the number of nanoseconds since Jan 1st, 1970, 00:00:00 GMT.
Definition: Types.h:57