OnixS C++ B3 Binary UMDF Market Data Handler  1.3.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 ONIXS_B3_UMDF_MD_API 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  void toString(std::string&) const;
60 
61  /// Order Id
62  OrderId orderId() const { return orderId_; };
63 
64  /// Price
65  Price price() const { return price_; };
66 
67  /// Quantity
68  Quantity quantity() const { return quantity_; };
69 
70  /// Indicates whether the order is the market order.
71  bool marketOrder() const { return price_.isNull(); }
72 
73  private:
74  OrderId orderId_;
75  Price price_;
76  Quantity quantity_;
77  };
78 
79  /// compare
80  bool operator==(const Order& l, const Order& r) ONIXS_B3_UMDF_MD_NOTHROW;
81 
82  ///
83  ONIXS_B3_UMDF_MD_API
84  std::ostream& operator<<(std::ostream& stream, const Order& value);
85 
86  /// Miscellaneous traits for PriceLevel class.
87  struct ONIXS_B3_UMDF_MD_API OrderCollections
88  {
89  /// Sequential collection of price levels.
90  typedef std::vector<Order> Array;
91 
92  /// Mutable entry iterator.
93  typedef Array::iterator ArrayEntry;
94 
95  /// Iterator for read-only access.
96  typedef Array::const_iterator ArrayConstEntry;
97  };
98 
99  /// Sequence of price levels.
101 
102  /// Iterator to access price levels with write permissions.
104 
105  /// Iterator over read-only collection of price levels.
107 
108  /// Order Book.
109  /// A set of bid and ask orders for the given
110  /// security (bids are descending and asks are ascending).
111  /// The quantity is provided at each price level.
112  class ONIXS_B3_UMDF_MD_API OrderBook
113  {
114  public:
115  // Base initialization.
116  OrderBook ();
117 
118  /// Destruction interface.
119  virtual ~OrderBook() {};
120 
121  /// Instrument Id
122  InstrumentId instrumentId() const;
123 
124  /// Indicates whether book has no bids & asks.
125  bool empty() const
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 bool operator==(const Order& l, const Order& r) ONIXS_B3_UMDF_MD_NOTHROW
170  {
171  return (l.orderId() == r.orderId()) && (l.price().mantissa() == r.price().mantissa()) && (l.quantity() == r.quantity());
172  }
173 
174  inline const Orders& OrderBook::asks() const
175  {
176  return doAsks();
177  }
178 
179  inline const Orders& OrderBook::bids() const
180  {
181  return doBids();
182  }
183 
184  inline InstrumentId OrderBook::instrumentId() const
185  {
186  return doInstrumentID();
187  }
188 
189  inline bool OrderBook::empty() const
190  ONIXS_B3_UMDF_MD_NOTHROW
191  {
192  return bids().empty() && asks().empty();
193  }
194 
196  {
197  return doLastMessageSeqNumApplied();
198  }
199 
201  {
202  return doLastRptSeq();
203  }
204 
205  }
206  }
207  }
208 }
const Orders & bids() const
Returns a set of ascending ask prices for the given security.
Definition: OrderBook.h:179
Messaging::RptSeq lastRptSeq() const
Returns the last processed RptSeq (sequence number per instrument update) for this instrument...
Definition: OrderBook.h:200
bool marketOrder() const
Indicates whether the order is the market order.
Definition: OrderBook.h:71
#define ONIXS_B3_UMDF_MD_NOTHROW
Definition: Compiler.h:114
ONIXS_B3_UMDF_MD_API std::ostream & operator<<(std::ostream &stream, const LoggerSettings &settings)
Messaging::UInt64 UInt64
Definition: Integral.h:40
OrderCollections::Array Orders
Sequence of price levels.
Definition: OrderBook.h:100
virtual ~OrderBook()
Destruction interface.
Definition: OrderBook.h:119
Messaging::SeqNum lastMessageSeqNumApplied() const
Returns the last processed packet sequence number of the incremental channel.
Definition: OrderBook.h:195
const Orders & asks() const
Returns a set of descending bid prices for the given security.
Definition: OrderBook.h:174
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:87
OrderCollections::ArrayConstEntry OrderConstEntry
Iterator over read-only collection of price levels.
Definition: OrderBook.h:106
Array::iterator ArrayEntry
Mutable entry iterator.
Definition: OrderBook.h:93
void validate(const OrderBook &)
For testing only.
Definition: Handler.h:26
Array::const_iterator ArrayConstEntry
Iterator for read-only access.
Definition: OrderBook.h:96
UInt32 SeqNum
Sequence number inside the given channel.
Definition: Fields.h:154
Price price() const
Price.
Definition: OrderBook.h:65
OrderId orderId() const
Order Id.
Definition: OrderBook.h:62
A nullable real number with a constant exponent.
Definition: Decimal.h:130
Messaging::Int64 Int64
Definition: Integral.h:39
bool empty() const
Indicates whether book has no bids & asks.
Definition: OrderBook.h:189
OrderCollections::ArrayEntry OrderEntry
Iterator to access price levels with write permissions.
Definition: OrderBook.h:103
InstrumentId instrumentId() const
Instrument Id.
Definition: OrderBook.h:184
Quantity quantity() const
Quantity.
Definition: OrderBook.h:68
std::vector< Order > Array
Sequential collection of price levels.
Definition: OrderBook.h:90
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