OnixS C++ FMX UST BIMP Market Data Handler 1.2.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 FmxUST
31 {
32 namespace MarketData
33 {
34 namespace Bimp
35 {
44
45 typedef std::vector<OrderInfo> OrderInfos;
46
48 struct ONIXS_FMXUST_BIMP_API PriceLevel
49 {
52
54 explicit
55 PriceLevel (const Price& price,
58 Integer8 imestamp = 0,
59 const OrderInfos& orders = OrderInfos() );
60
61#if defined(ONIXS_FMXUST_BIMP_COMPILER_CXX_RVALUE_REFERENCES) && ONIXS_FMXUST_BIMP_COMPILER_CXX_RVALUE_REFERENCES
62
65
67 operator=(PriceLevel&& other)
69#endif
70
71#if defined(ONIXS_FMXUST_BIMP_COMPILER_CXX_DEFAULTED_FUNCTIONS) && ONIXS_FMXUST_BIMP_COMPILER_CXX_DEFAULTED_FUNCTIONS
72 PriceLevel(const PriceLevel&) = default;
73#else
75#endif
76
78 operator=(const PriceLevel& other);
79
81 const Price& getPrice() const
83
85 void setPrice (const Price& value)
87
89 Quantity quantity() const
91
93 void quantity (Quantity value)
95
99
101 void numberOfOrders (Quantity value)
103
105 Integer8 timestamp() const
107
109 void timestamp(Integer8)
111
113 std::string toString() const;
114
116 void toString (std::string&) const;
117
121
123 const OrderInfos& orders() const
125
128
131
134
135 private:
136 Price price_;
137 Quantity qty_;
138 Quantity ordersQty_;
139 Integer8 timestamp_;
140 OrderInfos orders_;
141 };
142
144 bool operator== (const PriceLevel& l, const PriceLevel& r)
146
148 bool isValid (const PriceLevel& level)
150
152 const Price& getPrice (const PriceLevel& level)
154
155 ONIXS_FMXUST_BIMP_API
156 std::ostream& operator << (std::ostream& stream, const PriceLevel& value);
157
158
160 struct ONIXS_FMXUST_BIMP_API PriceLevelCollections
161 {
163 typedef std::vector<PriceLevel> Array;
164
166 typedef Array::iterator ArrayEntry;
167
169 typedef Array::const_iterator ArrayConstEntry;
170 };
171
174
177
180
185 class ONIXS_FMXUST_BIMP_API OrderBook
186 {
187 public:
188 // Base initialization.
190
192 virtual ~OrderBook() {};
193
195 InstrumentId instrumentId() const;
196
198 bool empty() const
200
201 bool bestAsk (Price& price, Quantity& quantity) const;
202
203 bool bestBid (Price& price, Quantity& quantity) const;
204
206 std::string toString() const;
207
209 void toString (std::string&) const;
210
212 std::string toShortString() const;
213
215 void toShortString (std::string&) const;
216
218 std::string toFormattedString() const;
219
221 void toFormattedString (std::string&) const;
222
224 const PriceLevels& asks() const;
225
227 const PriceLevels& bids() const;
228
230 UInt64 lastMessageSeqNumApplied() const;
231
232
233 private:
234 virtual const PriceLevels& doAsks() const = 0;
235 virtual const PriceLevels& doBids() const = 0;
236 virtual bool doBestAsk (Price& price, Quantity& quantity) const = 0;
237 virtual bool doBestBid (Price& price, Quantity& quantity) const = 0;
238 virtual InstrumentId doInstrumentID() const = 0;
239 virtual UInt64 doLastMessageSeqNumApplied() const = 0;
240 };
241
242 inline const Price& PriceLevel::getPrice() const
244 {
245 return price_;
246 }
247
248 inline void PriceLevel::setPrice (const Price& value)
250 {
251 price_ = value;
252 }
253
256 {
257 return qty_;
258 }
259
260 inline void PriceLevel::quantity (Quantity value)
262 {
263 qty_ = value;
264 }
265
268 {
269 return ordersQty_;
270 }
271
274 {
275 ordersQty_ = value;
276 }
277
278 inline const Price& getPrice (const PriceLevel& level)
280 {
281 return level.getPrice();
282 }
283
284 inline bool isValid (const PriceLevel& level)
286 {
287 return (level.quantity() != 0);
288 }
289
292 {
293 return timestamp_;
294 }
295
298 {
299 timestamp_ = timestamp;
300 }
301
302 inline bool operator== (const PriceLevel& l, const PriceLevel& r)
304 {
305 return (l.quantity() == r.quantity() ) && (l.numberOfOrders() == r.numberOfOrders() ) && (l.getPrice() == r.getPrice() );
306 }
307
308 inline const PriceLevels& OrderBook::asks() const
309 {
310 return doAsks();
311 }
312
313 inline const PriceLevels& OrderBook::bids() const
314 {
315 return doBids();
316 }
317
318 inline bool OrderBook::bestAsk (Price& price, Quantity& quantity ) const
319 {
320 return doBestAsk (price, quantity);
321 }
322
323 inline bool OrderBook::bestBid (Price& price, Quantity& quantity ) const
324 {
325 return doBestBid (price, quantity);
326 }
327
329 {
330 return doInstrumentID();
331 }
332
333 inline bool OrderBook::empty() const
335 {
336 return bids().empty() && asks().empty();
337 }
338
340 {
341 return doLastMessageSeqNumApplied();
342 }
343 }
344 }
345 }
346}
#define ONIXS_FMXUST_BIMP_NOTHROW
Definition Compiler.h:108
std::string toString() const
String presentation of the book.
virtual ~OrderBook()
Destruction interface.
Definition OrderBook.h:192
std::string toFormattedString() const
Returns formatted presentation of the book.
bool empty() const ONIXS_FMXUST_BIMP_NOTHROW
Indicates whether book has no bids & asks.
Definition OrderBook.h:333
InstrumentId instrumentId() const
Instrument Id.
Definition OrderBook.h:328
const PriceLevels & bids() const
Returns a set of ascending ask prices for the given security.
Definition OrderBook.h:313
bool bestAsk(Price &price, Quantity &quantity) const
Definition OrderBook.h:318
UInt64 lastMessageSeqNumApplied() const
Returns Last Message Seq Num Applied to the Book.
Definition OrderBook.h:339
const PriceLevels & asks() const
Returns a set of descending bid prices for the given security.
Definition OrderBook.h:308
bool bestBid(Price &price, Quantity &quantity) const
Definition OrderBook.h:323
std::string toShortString() const
Returns brief book info.
const Price & getPrice(const PriceLevel &level) ONIXS_FMXUST_BIMP_NOTHROW
Returns value of Price8.
Definition OrderBook.h:278
PriceLevelCollections::Array PriceLevels
Sequence of price levels.
Definition OrderBook.h:173
Integer8 Quantity
Alias for Quantity type.
Definition Defines.h:97
SignedInteger8 Price
Alias for Order Id type.
Definition Defines.h:94
std::vector< OrderInfo > OrderInfos
Definition OrderBook.h:45
PriceLevelCollections::ArrayEntry PriceLevelsEntry
Iterator to access price levels with write permissions.
Definition OrderBook.h:176
Integer8 OrderId
Alias for Order Id type.
Definition Defines.h:91
PriceLevelCollections::ArrayConstEntry PriceLevelsConstEntry
Iterator over read-only collection of price levels.
Definition OrderBook.h:179
Integer8 InstrumentId
Alias for Instrument Id type.
Definition Defines.h:88
bool isValid(const PriceLevel &level) ONIXS_FMXUST_BIMP_NOTHROW
Indicates whether the instance of PriceLevel is valid.
Definition OrderBook.h:284
OrderInfo() ONIXS_FMXUST_BIMP_NOTHROW
Miscellaneous traits for PriceLevel class.
Definition OrderBook.h:161
Array::iterator ArrayEntry
Mutable entry iterator.
Definition OrderBook.h:166
std::vector< PriceLevel > Array
Sequential collection of price levels.
Definition OrderBook.h:163
Array::const_iterator ArrayConstEntry
Iterator for read-only access.
Definition OrderBook.h:169
Encapsulates price level concept.
Definition OrderBook.h:49
Integer8 timestamp() const ONIXS_FMXUST_BIMP_NOTHROW
Timestamp.
Definition OrderBook.h:290
PriceLevel & operator=(const PriceLevel &other)
void updateOrderId(OrderId id, Quantity quantity)
upate order by Id
std::string toString() const
Returns string representation of the instance.
Quantity numberOfOrders() const ONIXS_FMXUST_BIMP_NOTHROW
Total number of orders of given price.
Definition OrderBook.h:266
PriceLevel(const Price &price, Quantity quantity=0, Quantity numberOfOrders=0, Integer8 imestamp=0, const OrderInfos &orders=OrderInfos())
Initializes the instances according to specified attributes.
Quantity quantity() const ONIXS_FMXUST_BIMP_NOTHROW
Quantify for the given price.
Definition OrderBook.h:254
void removeOrderId(OrderId id)
remove OrderId from the list
const OrderInfos & orders() const ONIXS_FMXUST_BIMP_NOTHROW
returns list of order IDs for the price level
void setPrice(const Price &value) ONIXS_FMXUST_BIMP_NOTHROW
Updates price value.
Definition OrderBook.h:248
void addOrderId(OrderId id, Quantity quantity)
add OrderId to the list
const Price & getPrice() const ONIXS_FMXUST_BIMP_NOTHROW
Price8 value.
Definition OrderBook.h:242
void swap(PriceLevel &) ONIXS_FMXUST_BIMP_NOTHROW
swap values