OnixS C++ Cboe CFE Multicast PITCH Market Data Handler  1.12.1
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 CboeCFE
31  {
32  namespace MarketData
33  {
34  namespace Pitch
35  {
36  struct ONIXS_CBOECFE_PITCH_API OrderInfo
37  {
40 
43  };
44 
45  typedef std::vector<OrderInfo> OrderInfos;
46 
47  /// Encapsulates price level concept.
48  struct ONIXS_CBOECFE_PITCH_API PriceLevel
49  {
50  /// Default initialization.
51  PriceLevel();
52 
53  /// Initializes the instances according to specified attributes.
54  explicit
55  PriceLevel (const BinaryPrice& price,
56  Quantity quantity = 0,
57  Quantity numberOfOrders = 0,
58  Time unitTimestamp = 0,
59  Time timeOffset = 0,
60  const OrderInfos& orders = OrderInfos() );
61 
62 #if defined(ONIXS_BATS_PITCH_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_BATS_PITCH_COMPILER_CXX_RVALUE_REFERENCES
63 
64  PriceLevel(PriceLevel&&)
66 
67  PriceLevel&
68  operator=(PriceLevel&& other)
70 #endif
71 
72 #if defined(ONIXS_BATS_PITCH_COMPILER_CXX_DEFAULTED_FUNCTIONS) && ONIXS_BATS_PITCH_COMPILER_CXX_DEFAULTED_FUNCTIONS
73  PriceLevel(const PriceLevel&) = default;
74 #else
75  PriceLevel(const PriceLevel&);
76 #endif
77 
78  PriceLevel&
79  operator=(const PriceLevel& other);
80 
81  /// Price8 value.
82  const BinaryPrice& getPrice() const
84 
85  /// Updates price value.
86  void setPrice (const BinaryPrice& value)
88 
89  /// Quantify for the given price.
90  Quantity quantity() const
92 
93  /// Updates quantity value.
94  void quantity (Quantity value)
96 
97  /// Total number of orders of given price.
98  Quantity numberOfOrders() const
100 
101  /// Updates total number of orders.
102  void numberOfOrders (Quantity value)
104 
105  /// Unit timestamp
106  Time unitTimestamp() const
108 
109  ///
110  void unitTimestamp(Time)
112 
113  /// Time offset of Unit timestamp
114  Time timeOffset() const
116 
117  ///
118  void timeOffset(Time)
120 
121  /// Returns string representation of the instance.
122  std::string toString() const;
123 
124  /// Appends representation of the instance to the string.
125  void toString (std::string&) const;
126 
127  /// swap values
128  void swap (PriceLevel&)
130 
131  /// returns list of order IDs for the price level
132  const OrderInfos& orders() const
134 
135  /// add OrderId to the list
136  void addOrderId(OrderId id, Quantity quantity);
137 
138  /// remove OrderId from the list
139  void removeOrderId (OrderId id);
140 
141  /// upate order by Id
142  void updateOrderId(OrderId id, Quantity quantity);
143 
144  private:
145  BinaryPrice price_;
146  Quantity qty_;
147  Quantity ordersQty_;
148  Time unitTimestamp_;
149  Time timeOffset_;
150  OrderInfos orders_;
151  };
152 
153  /// compare
154  bool operator== (const PriceLevel& l, const PriceLevel& r)
156 
157  /// Indicates whether the instance of PriceLevel is valid.
158  bool isValid (const PriceLevel& level)
160 
161  /// Returns value of Price8
162  const BinaryPrice& getPrice (const PriceLevel& level)
164 
165  ONIXS_CBOECFE_PITCH_API
166  std::ostream& operator << (std::ostream& stream, const PriceLevel& value);
167 
168 
169  /// Miscellaneous traits for PriceLevel class.
170  struct ONIXS_CBOECFE_PITCH_API PriceLevelCollections
171  {
172  /// Sequential collection of price levels.
173  typedef std::vector<PriceLevel> Array;
174 
175  /// Mutable entry iterator.
176  typedef Array::iterator ArrayEntry;
177 
178  /// Iterator for read-only access.
179  typedef Array::const_iterator ArrayConstEntry;
180  };
181 
182  /// Sequence of price levels.
184 
185  /// Iterator to access price levels with write permissions.
187 
188  /// Iterator over read-only collection of price levels.
190 
191  /// Order Book.
192  /// A set of bid prices and ask prices for the given
193  /// security (bids are descending and asks are ascending).
194  /// The quantity is provided at each price level.
195  class ONIXS_CBOECFE_PITCH_API OrderBook
196  {
197  public:
198  // Base initialization.
199  OrderBook ();
200 
201  /// Destruction interface.
202  virtual ~OrderBook() {};
203 
204  /// Symbol
205  StrRef symbol() const;
206 
207  /// Indicates whether book has no bids & asks.
208  bool empty() const
210 
211  bool bestAsk (BinaryPrice& price, Quantity& quantity) const;
212 
213  bool bestBid (BinaryPrice& price, Quantity& quantity) const;
214 
215  /// String presentation of the book.
216  std::string toString() const;
217 
218  /// String presentation of the book.
219  void toString (std::string&) const;
220 
221  /// Returns brief book info.
222  std::string toShortString() const;
223 
224  /// Appends brief book info to the string.
225  void toShortString (std::string&) const;
226 
227  /// Returns formatted presentation of the book.
228  std::string toFormattedString() const;
229 
230  /// Appends Formatted presentation of the book.
231  void toFormattedString (std::string&) const;
232 
233  /// Returns a set of descending bid prices for the given security.
234  const PriceLevels& asks() const;
235 
236  /// Returns a set of ascending ask prices for the given security.
237  const PriceLevels& bids() const;
238 
239  /// Returns Last Message Seq Num Applied to the Book
240  UInt32 lastMessageSeqNumApplied() const;
241 
242  protected:
243  InstrumentId instrumentId() const;
244 
245  private:
246  virtual const PriceLevels& doAsks() const = 0;
247  virtual const PriceLevels& doBids() const = 0;
248  virtual bool doBestAsk (BinaryPrice& price, Quantity& quantity) const = 0;
249  virtual bool doBestBid (BinaryPrice& price, Quantity& quantity) const = 0;
250  virtual InstrumentId doInstrumentID() const = 0;
251  virtual StrRef doSymbol() const = 0;
252  virtual UInt32 doLastMessageSeqNumApplied() const = 0;
253  };
254 
255  inline const BinaryPrice& PriceLevel::getPrice() const
256  ONIXS_BATS_PITCH_NOTHROW
257  {
258  return price_;
259  }
260 
261  inline void PriceLevel::setPrice (const BinaryPrice& value)
262  ONIXS_BATS_PITCH_NOTHROW
263  {
264  price_ = value;
265  }
266 
268  ONIXS_BATS_PITCH_NOTHROW
269  {
270  return qty_;
271  }
272 
273  inline void PriceLevel::quantity (Quantity value)
274  ONIXS_BATS_PITCH_NOTHROW
275  {
276  qty_ = value;
277  }
278 
280  ONIXS_BATS_PITCH_NOTHROW
281  {
282  return ordersQty_;
283  }
284 
286  ONIXS_BATS_PITCH_NOTHROW
287  {
288  ordersQty_ = value;
289  }
290 
291  inline const BinaryPrice& getPrice (const PriceLevel& level)
292  ONIXS_BATS_PITCH_NOTHROW
293  {
294  return level.getPrice();
295  }
296 
297  inline bool isValid (const PriceLevel& level)
298  ONIXS_BATS_PITCH_NOTHROW
299  {
300  return (level.quantity() != 0);
301  }
302 
304  ONIXS_BATS_PITCH_NOTHROW
305  {
306  return timeOffset_;
307  }
308 
309  inline void PriceLevel::timeOffset(Time offset)
310  ONIXS_BATS_PITCH_NOTHROW
311  {
312  timeOffset_ = offset;
313  }
314 
316  ONIXS_BATS_PITCH_NOTHROW
317  {
318  return unitTimestamp_;
319  }
320 
321  inline void PriceLevel::unitTimestamp(Time timestamp)
322  ONIXS_BATS_PITCH_NOTHROW
323  {
324  unitTimestamp_ = timestamp;
325  }
326 
327  inline bool operator== (const PriceLevel& l, const PriceLevel& r)
328  ONIXS_BATS_PITCH_NOTHROW
329  {
330  return (l.quantity() == r.quantity() ) && (l.numberOfOrders() == r.numberOfOrders() ) && (l.getPrice() == r.getPrice() );
331  }
332 
333  inline const PriceLevels& OrderBook::asks() const
334  {
335  return doAsks();
336  }
337 
338  inline const PriceLevels& OrderBook::bids() const
339  {
340  return doBids();
341  }
342 
343  inline bool OrderBook::bestAsk (BinaryPrice& price, Quantity& quantity ) const
344  {
345  return doBestAsk (price, quantity);
346  }
347 
348  inline bool OrderBook::bestBid (BinaryPrice& price, Quantity& quantity ) const
349  {
350  return doBestBid (price, quantity);
351  }
352 
354  {
355  return doInstrumentID();
356  }
357 
358  inline StrRef OrderBook::symbol() const
359  {
360  return doSymbol();
361  }
362 
363  inline bool OrderBook::empty() const
364  ONIXS_BATS_PITCH_NOTHROW
365  {
366  return bids().empty() && asks().empty();
367  }
368 
370  {
371  return doLastMessageSeqNumApplied();
372  }
373  }
374  }
375  }
376 }
377 
378 
379 
PriceLevelCollections::ArrayConstEntry PriceLevelsConstEntry
Iterator over read-only collection of price levels.
Definition: OrderBook.h:189
PriceLevelCollections::ArrayEntry PriceLevelsEntry
Iterator to access price levels with write permissions.
Definition: OrderBook.h:186
const BinaryPrice & getPrice() const ONIXS_BATS_PITCH_NOTHROW
Price8 value.
Definition: OrderBook.h:255
PriceLevelCollections::Array PriceLevels
Sequence of price levels.
Definition: OrderBook.h:183
Miscellaneous traits for PriceLevel class.
Definition: OrderBook.h:170
Quantity numberOfOrders() const ONIXS_BATS_PITCH_NOTHROW
Total number of orders of given price.
Definition: OrderBook.h:279
Provides efficient way of accessing text-based FIX field values.
Definition: String.h:45
Array::iterator ArrayEntry
Mutable entry iterator.
Definition: OrderBook.h:176
Binary4 Quantity
Alias for Quantity type.
Definition: Defines.h:118
bool bestBid(BinaryPrice &price, Quantity &quantity) const
Definition: OrderBook.h:348
bool empty() const ONIXS_BATS_PITCH_NOTHROW
Indicates whether book has no bids & asks.
Definition: OrderBook.h:363
ONIXS_CBOECFE_PITCH_API std::ostream & operator<<(std::ostream &stream, const ServiceDescriptor &descriptor)
std::vector< PriceLevel > Array
Sequential collection of price levels.
Definition: OrderBook.h:173
Time timeOffset() const ONIXS_BATS_PITCH_NOTHROW
Time offset of Unit timestamp.
Definition: OrderBook.h:303
UInt32 lastMessageSeqNumApplied() const
Returns Last Message Seq Num Applied to the Book.
Definition: OrderBook.h:369
void setPrice(const BinaryPrice &value) ONIXS_BATS_PITCH_NOTHROW
Updates price value.
Definition: OrderBook.h:261
bool isValid(const PriceLevel &level) ONIXS_BATS_PITCH_NOTHROW
Indicates whether the instance of PriceLevel is valid.
Definition: OrderBook.h:297
Quantity quantity() const ONIXS_BATS_PITCH_NOTHROW
Quantify for the given price.
Definition: OrderBook.h:267
virtual ~OrderBook()
Destruction interface.
Definition: OrderBook.h:202
bool operator==(const PriceLevel &l, const PriceLevel &r) ONIXS_BATS_PITCH_NOTHROW
compare
Definition: OrderBook.h:327
const BinaryPrice & getPrice(const PriceLevel &level) ONIXS_BATS_PITCH_NOTHROW
Returns value of Price8.
Definition: OrderBook.h:291
bool bestAsk(BinaryPrice &price, Quantity &quantity) const
Definition: OrderBook.h:343
const PriceLevels & asks() const
Returns a set of descending bid prices for the given security.
Definition: OrderBook.h:333
#define ONIXS_BATS_PITCH_NOTHROW
Definition: Compiler.h:107
Encapsulates price level concept.
Definition: OrderBook.h:48
std::vector< OrderInfo > OrderInfos
Definition: OrderBook.h:45
Binary8 OrderId
Alias for Order Id type.
Definition: Defines.h:115
const PriceLevels & bids() const
Returns a set of ascending ask prices for the given security.
Definition: OrderBook.h:338
Time unitTimestamp() const ONIXS_BATS_PITCH_NOTHROW
Unit timestamp.
Definition: OrderBook.h:315
Array::const_iterator ArrayConstEntry
Iterator for read-only access.
Definition: OrderBook.h:179
Binary8 InstrumentId
Alias for Instrument Id type.
Definition: Defines.h:123