OnixS ICE iMpact Multicast Price Feed Handler C++ library  8.10.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 "Export.h"
23 #include "Containers.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  const PriceLevelArray& bids() const;
140 
141  /// Gets offer side of the price level book.
142  const PriceLevelArray& offers() const;
143 
144  /// Gets bid side of the full order depth book.
145  const OrderArray& bidOrders() const;
146 
147  /// Gets offer side of the full order depth book.
148  const OrderArray& offerOrders() const;
149 
150  /// Returns brief book info.
151  std::string brief() const;
152 
153  /// Appends brief book info to the string.
154  void brief(std::string&) const;
155 
156  /// String presentation of the book.
157  std::string toString() const;
158 
159  /// String presentation of the book.
160  void toString(std::string&) const;
161 
162  /// Creates immutable snapshot of the book owned by caller.
163  /// It's responsibility of caller to delete returned snapshot.
164  const OrderBook* snapshot() const;
165 
166  /// Destructor
167  ~OrderBook();
168 
169 private:
170  friend class OrderBookHolder;
171  struct Impl;
172 
173  OrderBook(Impl*);
174 
175  // No implementation
176  OrderBook(const OrderBook&);
177  OrderBook& operator=(const OrderBook&);
178 
179  Impl* impl_;
180 };
181 
182 inline std::string OrderBook::brief() const
183 {
184  std::string str;
185  brief(str);
186  return str;
187 }
188 
189 inline std::string OrderBook::toString() const
190 {
191  std::string str;
192  toString(str);
193  return str;
194 }
195 
196 }}}} // namespace MarketData, iMpact, ICE, OnixS
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:189
Rational number representation.
Definition: Rational.h:30
std::string brief() const
Returns brief book info.
Definition: OrderBook.h:182
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