OnixS C++ HKEX OMD-C Handler 1.0.0
API documentation
Loading...
Searching...
No Matches
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
28namespace OnixS
29{
30 namespace HKEX
31 {
32 namespace MarketData
33 {
34 namespace Omdc
35 {
44
45 typedef std::vector<OrderInfo> OrderInfos;
46
48 struct ONIXS_HKEX_OMDC_API PriceLevel
49 {
52
54 explicit
55 PriceLevel (const Price& price,
58 const OrderInfos& orders = OrderInfos() );
59
60#if defined(ONIXS_HKEX_OMDC_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_HKEX_OMDC_COMPILER_CXX_RVALUE_REFERENCES
61
64
66 operator=(PriceLevel&& other)
68#endif
69
70#if defined(ONIXS_HKEX_OMDC_COMPILER_CXX_DEFAULTED_FUNCTIONS) && ONIXS_HKEX_OMDC_COMPILER_CXX_DEFAULTED_FUNCTIONS
71 PriceLevel(const PriceLevel&) = default;
72#else
74#endif
75
77 operator=(const PriceLevel& other);
78
80 const Price& getPrice() const
82
84 void setPrice (const Price& value)
86
88 Quantity quantity() const
90
92 void quantity (Quantity value)
94
98
100 void numberOfOrders (Quantity value)
102
104 std::string toString() const;
105
107 void toString (std::string&) const;
108
112
114 const OrderInfos& orders() const
116
119
122
125
126 private:
127 Price price_;
128 Quantity qty_;
129 Quantity ordersQty_;
130 OrderInfos orders_;
131 };
132
134 bool operator== (const PriceLevel& l, const PriceLevel& r)
136
138 bool isValid (const PriceLevel& level)
140
142 const Price& getPrice (const PriceLevel& level)
144
145 ONIXS_HKEX_OMDC_API
146 std::ostream& operator << (std::ostream& stream, const PriceLevel& value);
147
148
150 struct ONIXS_HKEX_OMDC_API PriceLevelCollections
151 {
153 typedef std::vector<PriceLevel> Array;
154
156 typedef Array::iterator ArrayEntry;
157
159 typedef Array::const_iterator ArrayConstEntry;
160 };
161
164
167
170
175 class ONIXS_HKEX_OMDC_API OrderBook
176 {
177 public:
178 // Base initialization.
180
182 virtual ~OrderBook() {};
183
185 InstrumentId instrumentId() const;
186
188 bool empty() const
190
191 bool bestAsk (Price& price, Quantity& quantity) const;
192
193 bool bestBid (Price& price, Quantity& quantity) const;
194
196 std::string toString() const;
197
199 void toString (std::string&) const;
200
202 std::string toShortString() const;
203
205 void toShortString (std::string&) const;
206
208 std::string toFormattedString() const;
209
211 void toFormattedString (std::string&) const;
212
214 const PriceLevels& asks() const;
215
217 const PriceLevels& bids() const;
218
220 UInt64 lastMessageSeqNumApplied() const;
221
222
223 private:
224 virtual const PriceLevels& doAsks() const = 0;
225 virtual const PriceLevels& doBids() const = 0;
226 virtual bool doBestAsk (Price& price, Quantity& quantity) const = 0;
227 virtual bool doBestBid (Price& price, Quantity& quantity) const = 0;
228 virtual InstrumentId doInstrumentID() const = 0;
229 virtual UInt64 doLastMessageSeqNumApplied() const = 0;
230 };
231
232 inline const Price& PriceLevel::getPrice() const
234 {
235 return price_;
236 }
237
238 inline void PriceLevel::setPrice (const Price& value)
240 {
241 price_ = value;
242 }
243
246 {
247 return qty_;
248 }
249
250 inline void PriceLevel::quantity (Quantity value)
252 {
253 qty_ = value;
254 }
255
258 {
259 return ordersQty_;
260 }
261
264 {
265 ordersQty_ = value;
266 }
267
268 inline const Price& getPrice (const PriceLevel& level)
270 {
271 return level.getPrice();
272 }
273
274 inline bool isValid (const PriceLevel& level)
276 {
277 return (level.quantity() != 0);
278 }
279
280 inline bool operator== (const PriceLevel& l, const PriceLevel& r)
282 {
283 return (l.quantity() == r.quantity() ) && (l.numberOfOrders() == r.numberOfOrders() ) && (l.getPrice() == r.getPrice() );
284 }
285
286 inline const PriceLevels& OrderBook::asks() const
287 {
288 return doAsks();
289 }
290
291 inline const PriceLevels& OrderBook::bids() const
292 {
293 return doBids();
294 }
295
296 inline bool OrderBook::bestAsk (Price& price, Quantity& quantity ) const
297 {
298 return doBestAsk (price, quantity);
299 }
300
301 inline bool OrderBook::bestBid (Price& price, Quantity& quantity ) const
302 {
303 return doBestBid (price, quantity);
304 }
305
307 {
308 return doInstrumentID();
309 }
310
311 inline bool OrderBook::empty() const
313 {
314 return bids().empty() && asks().empty();
315 }
316
318 {
319 return doLastMessageSeqNumApplied();
320 }
321 }
322 }
323 }
324}
325
326
327
#define ONIXS_HKEX_OMDC_NOTHROW
Definition Compiler.h:169
std::string toString() const
String presentation of the book.
virtual ~OrderBook()
Destruction interface.
Definition OrderBook.h:182
std::string toFormattedString() const
Returns formatted presentation of the book.
InstrumentId instrumentId() const
Instrument Id.
Definition OrderBook.h:306
bool empty() const noexcept
Indicates whether book has no bids & asks.
Definition OrderBook.h:311
const PriceLevels & bids() const
Returns a set of ascending ask prices for the given security.
Definition OrderBook.h:291
bool bestAsk(Price &price, Quantity &quantity) const
Definition OrderBook.h:296
UInt64 lastMessageSeqNumApplied() const
Returns Last Message Seq Num Applied to the Book.
Definition OrderBook.h:317
const PriceLevels & asks() const
Returns a set of descending bid prices for the given security.
Definition OrderBook.h:286
bool bestBid(Price &price, Quantity &quantity) const
Definition OrderBook.h:301
std::string toShortString() const
Returns brief book info.
PriceLevelCollections::Array PriceLevels
Sequence of price levels.
Definition OrderBook.h:163
UInt64 OrderId
Alias for Order Id type.
Definition Defines.h:84
const Price & getPrice(const PriceLevel &level) noexcept
Returns value of Price8.
Definition OrderBook.h:268
Int32 Price
Alias for Order Id type.
Definition Defines.h:87
std::vector< OrderInfo > OrderInfos
Definition OrderBook.h:45
PriceLevelCollections::ArrayEntry PriceLevelsEntry
Iterator to access price levels with write permissions.
Definition OrderBook.h:166
bool isValid(const PriceLevel &level) noexcept
Indicates whether the instance of PriceLevel is valid.
Definition OrderBook.h:274
PriceLevelCollections::ArrayConstEntry PriceLevelsConstEntry
Iterator over read-only collection of price levels.
Definition OrderBook.h:169
UInt32 Quantity
Alias for Quantity type.
Definition Defines.h:90
UInt32 InstrumentId
Alias for Instrument Id type.
Definition Defines.h:81
Miscellaneous traits for PriceLevel class.
Definition OrderBook.h:151
Array::iterator ArrayEntry
Mutable entry iterator.
Definition OrderBook.h:156
std::vector< PriceLevel > Array
Sequential collection of price levels.
Definition OrderBook.h:153
Array::const_iterator ArrayConstEntry
Iterator for read-only access.
Definition OrderBook.h:159
Encapsulates price level concept.
Definition OrderBook.h:49
PriceLevel & operator=(const PriceLevel &other)
Quantity numberOfOrders() const noexcept
Total number of orders of given price.
Definition OrderBook.h:256
void updateOrderId(OrderId id, Quantity quantity)
upate order by Id
std::string toString() const
Returns string representation of the instance.
const Price & getPrice() const noexcept
Price8 value.
Definition OrderBook.h:232
void removeOrderId(OrderId id)
remove OrderId from the list
Quantity quantity() const noexcept
Quantify for the given price.
Definition OrderBook.h:244
const OrderInfos & orders() const noexcept
returns list of order IDs for the price level
void setPrice(const Price &value) noexcept
Updates price value.
Definition OrderBook.h:238
void swap(PriceLevel &) noexcept
swap values
void addOrderId(OrderId id, Quantity quantity)
add OrderId to the list
PriceLevel(const Price &price, Quantity quantity=0, Quantity numberOfOrders=0, const OrderInfos &orders=OrderInfos())
Initializes the instances according to specified attributes.