OnixS C++ B3 Binary UMDF Market Data Handler  1.4.0
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 #pragma once
20 
24 
25 #include <vector>
26 #include <memory>
27 
28 namespace OnixS
29 {
30  namespace B3
31  {
32  namespace MarketData
33  {
34  namespace UMDF
35  {
36  /// Alias for Instrument Id type.
38 
39  /// Alias for Order Id type.
40  typedef UInt64 OrderId;
41 
42  /// Alias for Quantity type.
43  typedef Int64 Quantity;
44 
45  /// Alias for Price type (4 decimal places)
47 
48 
49  /// Order information
50  struct Order
51  {
52  /// Initializes the instances according to specified attributes.
53  Order(OrderId orderId, Price price, Quantity quantity) ONIXS_B3_UMDF_MD_NOTHROW;
54 
55  /// Returns string representation of the instance.
56  std::string toString() const;
57 
58  /// Appends representation of the instance to the string.
59  ONIXS_B3_UMDF_MD_API
60  void toString(std::string&) const;
61 
62  /// Order Id
63  OrderId orderId() const ONIXS_B3_UMDF_MD_NOTHROW { return orderId_; };
64 
65  /// Price
66  Price price() const ONIXS_B3_UMDF_MD_NOTHROW { return price_; };
67 
68  /// Quantity
69  Quantity quantity() const ONIXS_B3_UMDF_MD_NOTHROW { return quantity_; };
70 
71  /// Indicates whether the order is the market order.
72  bool marketOrder() const { return price_.isNull(); }
73 
74  private:
75  OrderId orderId_;
76  Price price_;
77  Quantity quantity_;
78  };
79 
80  /// compare
81  bool operator==(const Order& l, const Order& r) ONIXS_B3_UMDF_MD_NOTHROW;
82 
83  ///
84  ONIXS_B3_UMDF_MD_API
85  std::ostream& operator<<(std::ostream& stream, const Order& value);
86 
87  /// Miscellaneous traits for PriceLevel class.
89  {
90  /// Sequential collection of price levels.
91  typedef std::vector<Order> Array;
92 
93  /// Mutable entry iterator.
94  typedef Array::iterator ArrayEntry;
95 
96  /// Iterator for read-only access.
97  typedef Array::const_iterator ArrayConstEntry;
98  };
99 
100  /// Sequence of price levels.
102 
103  /// Iterator to access price levels with write permissions.
105 
106  /// Iterator over read-only collection of price levels.
108 
109  /// Order Book.
110  /// A set of bid and ask orders for the given
111  /// security (bids are descending and asks are ascending).
112  /// The quantity is provided at each price level.
113  class ONIXS_B3_UMDF_MD_API OrderBook
114  {
115  public:
116  // Base initialization.
117  OrderBook ();
118 
119  /// Destruction interface.
120  virtual ~OrderBook();
121 
122  /// Instrument Id
123  InstrumentId instrumentId() const;
124 
125  /// Indicates whether book has no bids & asks.
126  bool empty() const ONIXS_B3_UMDF_MD_NOTHROW;
127 
128  /// String presentation of the book.
129  std::string toString() const;
130 
131  /// String presentation of the book.
132  void toString (std::string&) const;
133 
134  /// Returns brief book info.
135  std::string toShortString() const;
136 
137  /// Appends brief book info to the string.
138  void toShortString (std::string&) const;
139 
140  /// Returns formatted presentation of the book.
141  std::string toFormattedString() const;
142 
143  /// Appends Formatted presentation of the book.
144  void toFormattedString (std::string&) const;
145 
146  /// Returns a set of descending bid prices for the given security.
147  const Orders& asks() const;
148 
149  /// Returns a set of ascending ask prices for the given security.
150  const Orders& bids() const;
151 
152  /// Returns the last processed packet sequence number of the incremental channel
153  Messaging::SeqNum lastMessageSeqNumApplied() const;
154 
155  /// Returns the last processed RptSeq (sequence number per instrument update) for this instrument.
156  Messaging::RptSeq lastRptSeq() const;
157 
158  private:
159  virtual const Orders& doAsks() const = 0;
160  virtual const Orders& doBids() const = 0;
161  virtual InstrumentId doInstrumentID() const = 0;
162  virtual Messaging::SeqNum doLastMessageSeqNumApplied() const = 0;
163  virtual Messaging::RptSeq doLastRptSeq() const = 0;
164  };
165 
166  /// For testing only.
167  void validate(const OrderBook&);
168 
169  inline Order::Order(OrderId orderId, Price price, Quantity quantity) ONIXS_B3_UMDF_MD_NOTHROW
170  : orderId_(orderId)
171  , price_(price)
172  , quantity_(quantity)
173  {
174  }
175 
176  inline bool operator==(const Order& l, const Order& r) ONIXS_B3_UMDF_MD_NOTHROW
177  {
178  return (l.orderId() == r.orderId()) && (l.price().mantissa() == r.price().mantissa()) && (l.quantity() == r.quantity());
179  }
180 
181  inline const Orders& OrderBook::asks() const
182  {
183  return doAsks();
184  }
185 
186  inline const Orders& OrderBook::bids() const
187  {
188  return doBids();
189  }
190 
191  inline InstrumentId OrderBook::instrumentId() const
192  {
193  return doInstrumentID();
194  }
195 
196  inline bool OrderBook::empty() const ONIXS_B3_UMDF_MD_NOTHROW
197  {
198  return bids().empty() && asks().empty();
199  }
200 
202  {
203  return doLastMessageSeqNumApplied();
204  }
205 
207  {
208  return doLastRptSeq();
209  }
210 
211  inline std::string Order::toString() const
212  {
213  std::string str;
214  toString(str);
215  return str;
216  }
217  }
218  }
219  }
220 }
const Orders & bids() const
Returns a set of ascending ask prices for the given security.
Definition: OrderBook.h:186
Messaging::RptSeq lastRptSeq() const
Returns the last processed RptSeq (sequence number per instrument update) for this instrument...
Definition: OrderBook.h:206
bool marketOrder() const
Indicates whether the order is the market order.
Definition: OrderBook.h:72
#define ONIXS_B3_UMDF_MD_NOTHROW
Definition: Compiler.h:114
ONIXS_B3_UMDF_MD_API std::ostream & operator<<(std::ostream &stream, const LoggerSettings &settings)
std::string toString() const
Returns string representation of the instance.
Definition: OrderBook.h:211
Messaging::UInt64 UInt64
Definition: Integral.h:40
OrderCollections::Array Orders
Sequence of price levels.
Definition: OrderBook.h:101
Messaging::SeqNum lastMessageSeqNumApplied() const
Returns the last processed packet sequence number of the incremental channel.
Definition: OrderBook.h:201
const Orders & asks() const
Returns a set of descending bid prices for the given security.
Definition: OrderBook.h:181
Int64 Quantity
Alias for Quantity type.
Definition: OrderBook.h:43
Messaging::PriceOptional Price
Alias for Price type (4 decimal places)
Definition: OrderBook.h:46
Miscellaneous traits for PriceLevel class.
Definition: OrderBook.h:88
OrderCollections::ArrayConstEntry OrderConstEntry
Iterator over read-only collection of price levels.
Definition: OrderBook.h:107
Array::iterator ArrayEntry
Mutable entry iterator.
Definition: OrderBook.h:94
void validate(const OrderBook &)
For testing only.
Definition: Handler.h:29
Array::const_iterator ArrayConstEntry
Iterator for read-only access.
Definition: OrderBook.h:97
UInt32 SeqNum
Sequence number inside the given channel.
Definition: Fields.h:154
Price price() const
Price.
Definition: OrderBook.h:66
OrderId orderId() const
Order Id.
Definition: OrderBook.h:63
A nullable real number with a constant exponent.
Definition: Decimal.h:116
Order(OrderId orderId, Price price, Quantity quantity)
Initializes the instances according to specified attributes.
Definition: OrderBook.h:169
Messaging::Int64 Int64
Definition: Integral.h:39
bool empty() const
Indicates whether book has no bids & asks.
Definition: OrderBook.h:196
OrderCollections::ArrayEntry OrderEntry
Iterator to access price levels with write permissions.
Definition: OrderBook.h:104
InstrumentId instrumentId() const
Instrument Id.
Definition: OrderBook.h:191
Quantity quantity() const
Quantity.
Definition: OrderBook.h:69
std::vector< Order > Array
Sequential collection of price levels.
Definition: OrderBook.h:91
UInt64 OrderId
Alias for Order Id type.
Definition: OrderBook.h:40
UInt32 RptSeq
Sequence number per instrument update.
Definition: Fields.h:186
bool operator==(const TimeSpan &left, const TimeSpan &right)
Compares with other instance for equality.
Definition: Time.h:327
UInt64 InstrumentId
Alias for Instrument Id type.
Definition: OrderBook.h:37