OnixS C++ CME Market Data Handler  5.4.0
API documentation
MboBook.h
Go to the documentation of this file.
1 // Copyright Onix Solutions Limited [OnixS]. All rights reserved.
2 //
3 // This software owned by Onix Solutions Limited [OnixS] and is
4 // protected by copyright law and international copyright treaties.
5 //
6 // Access to and use of the software is governed by the terms of the applicable
7 // OnixS Software Services Agreement (the Agreement) and Customer end user license
8 // agreements granting a non-assignable, non-transferable and non-exclusive license
9 // to use the software for it's own data processing purposes under the terms defined
10 // in the Agreement.
11 //
12 // Except as otherwise granted within the terms of the Agreement, copying or
13 // reproduction of any part of this source code or associated reference material
14 // to any other location for further reproduction or redistribution, and any
15 // amendments to this copyright notice, are expressly prohibited.
16 //
17 // Any reproduction or redistribution for sale or hiring of the Software not in
18 // accordance with the terms of the Agreement is a violation of copyright law.
19 //
20 
21 #pragma once
22 
25 
27 
28 /// Private base for MBO book.
29 ///
30 /// Manages internals related with
31 /// efficient order entry allocation.
34 {
35  MemoryPool& pool_;
36  const bool releasePool_;
37 
38 protected:
39  /// Instantiates allocator using MemoryPool for orders.
40  typedef
43 
44  /// Initializes with privately maintained memory pool.
46  : pool_(
48  (
49  64,
50  1,
51  20,
52  1
53  )
54  )
55  , releasePool_(true)
56  {
57  }
58 
59  /// Binds to given memory pool.
61  MemoryPool& sharedPool)
62  : pool_(sharedPool)
63  , releasePool_(false)
64  {
65  }
66 
67  /// Releases memory pool according to policy.
69  {
70  if (releasePool_)
71  pool_.release();
72  }
73 
74  /// Allocator over memory pool.
76  {
77  return OrderAllocator(pool_);
78  }
79 };
80 
81 /// Market By Order book.
84 {
85  BookState::Enum state_;
86 
87  SortedOrders bids_;
88  SortedOrders offers_;
89 
90 public:
91  /// Order as book entry.
92  typedef Order Entry;
93 
94  /// Book depth type.
95  typedef
96  SortedOrders::size_type
98 
99  /// Sorted orders are book entries.
101 
102  /// Iterator over bids and offers.
103  typedef
104  Entries::const_iterator
106 
107  /// Initializes blank order book.
109  : state_(
110  BookState::Constructed)
111  , bids_(
112  allocator())
113  , offers_(
114  allocator())
115  {
116  }
117 
118  /// Initializes book using given memory pool.
120  MemoryPool& pool)
121  : MboBookBase(pool)
122  , state_(
123  BookState::Constructed)
124  , bids_(
125  allocator())
126  , offers_(
127  allocator())
128  {
129  }
130 
131  /// Initializes as copy of other book.
133  const MboBook& other)
134  : MboBookBase()
135  , state_(other.state())
136  , bids_(allocator())
137  , offers_(allocator())
138  {
139  bids_ = other.bids();
140  offers_ = other.offers();
141  }
142 
143  /// Disposes allocated resources.
145  {
146  }
147 
148  /// List of descending bid prices.
149  Entries& bids()
150  {
151  return bids_;
152  }
153 
154  /// List of descending bid prices.
155  Entries&
156  operator [](
157  const Bids&)
158  {
159  return bids_;
160  }
161 
162  /// List of descending bid prices.
163  const
164  Entries&
165  bids() const
166  {
167  return bids_;
168  }
169 
170  /// List of descending bid prices.
171  const
172  Entries&
173  operator [](
174  const Bids&) const
175  {
176  return bids_;
177  }
178 
179  /// List of ascending offer prices.
180  Entries& offers()
181  {
182  return offers_;
183  }
184 
185  /// List of ascending offer prices.
186  Entries&
187  operator [](
188  const Offers&)
189  {
190  return offers_;
191  }
192 
193  /// List of ascending offer prices.
194  const
195  Entries&
196  offers() const
197  {
198  return offers_;
199  }
200 
201  /// List of ascending offer prices.
202  const
203  Entries&
204  operator [](
205  const Offers&) const
206  {
207  return offers_;
208  }
209 
210  /// Indicates current state of book.
212  {
213  return state_;
214  }
215 
216  /// Updates state of book.
217  void
219  BookState::Enum state)
220  {
221  state_ = state;
222  }
223 
224  /// Wipes out all bids and offers and other
225  /// data associated with book (like instance
226  /// of last applied FIX message).
227  void
229  BookState::Enum bookState)
230  {
231  state(bookState);
232 
233  bids_.clear();
234  offers_.clear();
235  }
236 
237  /// Re-initializes as copy of other instance.
238  MboBook&
239  operator =(
240  const MboBook& other)
241  {
242  if (this != &other)
243  {
244  state_ = other.state();
245 
246  bids_ = other.bids();
247  offers_ = other.offers();
248  }
249 
250  return *this;
251  }
252 };
253 
254 /// Copies content of MBO book to the other one.
255 inline
256 void
258  MboBook& target,
259  const MboBook& source)
260 {
261  target = source;
262 }
263 
264 /// Book brief info.
265 ONIXS_CMEMDH_EXPORTED
266 void
267 brief(
268  std::string&,
269  const MboBook&);
270 
271 /// Book brief info.
272 inline
273 std::string
275  const MboBook& book)
276 {
277  std::string str;
278 
279  brief(str, book);
280 
281  return str;
282 }
283 
284 /// Serializes book.
285 ONIXS_CMEMDH_EXPORTED
286 void
287 toStr(
288  std::string&,
289  const MboBook&);
290 
291 /// Serializes book.
292 inline
293 std::string
295  const MboBook& book)
296 {
297  std::string str;
298 
299  toStr(str, book);
300 
301  return str;
302 }
303 
304 /// Serializes book in formatted form.
305 ONIXS_CMEMDH_EXPORTED
306 void
308  std::string&,
309  const MboBook&);
310 
311 /// Serializes book in formatted form.
312 inline
313 std::string
315  const MboBook& book)
316 {
317  std::string str;
318 
319  toFormattedStr(str, book);
320 
321  return str;
322 }
323 
Order Entry
Order as book entry.
Definition: MboBook.h:92
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:94
std::string toStr(const MboBook &book)
Serializes book.
Definition: MboBook.h:294
~MboBook()
Disposes allocated resources.
Definition: MboBook.h:144
ONIXS_CMEMDH_EXPORTED MemoryPool * makeMemoryPool(size_t, size_t, size_t, size_t)
MboBookBase()
Initializes with privately maintained memory pool.
Definition: MboBook.h:45
std::list< Order, MemoryPoolAllocator< Order >> SortedOrders
Arranged collection of orders.
Definition: MboBookTraits.h:37
OrderAllocator allocator() const
Allocator over memory pool.
Definition: MboBook.h:75
SortedOrders Entries
Sorted orders are book entries.
Definition: MboBook.h:100
Tag class for accessing bids in templates.
void reset(BookState::Enum bookState)
Definition: MboBook.h:228
BookState::Enum state() const
Indicates current state of book.
Definition: MboBook.h:211
Entries::const_iterator EntryIterator
Iterator over bids and offers.
Definition: MboBook.h:105
MboBook(MemoryPool &pool)
Initializes book using given memory pool.
Definition: MboBook.h:119
Order as the member of the Market By Order (MBO) book.
Definition: Order.h:79
MemoryPoolAllocator< Order > OrderAllocator
Instantiates allocator using MemoryPool for orders.
Definition: MboBook.h:42
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:152
std::string brief(const MboBook &book)
Book brief info.
Definition: MboBook.h:274
MboBookBase(MemoryPool &sharedPool)
Binds to given memory pool.
Definition: MboBook.h:60
SortedOrders::size_type Depth
Book depth type.
Definition: MboBook.h:97
MboBook()
Initializes blank order book.
Definition: MboBook.h:108
~MboBookBase()
Releases memory pool according to policy.
Definition: MboBook.h:68
const Entries & bids() const
List of descending bid prices.
Definition: MboBook.h:165
void state(BookState::Enum state)
Updates state of book.
Definition: MboBook.h:218
State of order book.
void copy(MboBook &target, const MboBook &source)
Copies content of MBO book to the other one.
Definition: MboBook.h:257
virtual void release()=0
Releases given instance.
Entries & bids()
List of descending bid prices.
Definition: MboBook.h:149
Entries & offers()
List of ascending offer prices.
Definition: MboBook.h:180
Tag class for accessing offers in templates.
Market By Order book.
Definition: MboBook.h:82
std::string toFormattedStr(const MboBook &book)
Serializes book in formatted form.
Definition: MboBook.h:314
const Entries & offers() const
List of ascending offer prices.
Definition: MboBook.h:196
MboBook(const MboBook &other)
Initializes as copy of other book.
Definition: MboBook.h:132
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:156