OnixS C++ CME Market Data Handler  4.8.0.10
API documentation
BookManagement.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 
23 #include <string>
24 
25 #include <OnixS/CME/MDH/Decimal.h>
26 
28 
31 
33 
34 /// Raises exception on invalid best bid/offer threshold value.
35 inline
36 void
38 {
39  throw std::runtime_error
40  (
41  "Threshold for tracking best bids "
42  "or offers can't be a negative value. "
43  );
44 }
45 
46 /// Defines tracking attributes for a particular BBO parameter.
48 {
49  // Actual threshold value.
50  Decimal threshold_;
51 
52  // Indicates whether threshold must be used.
53  bool enabled_;
54 
55 public:
56  /// Initializes parameter tracking.
58  : threshold_()
59  , enabled_(false)
60  {
61  }
62 
63  /// Indicates whether tracking is enabled.
64  bool enabled() const
65  {
66  return enabled_;
67  }
68 
69  /// Indicates whether tracking is enabled.
70  void enabled(bool value)
71  {
72  enabled_ = value;
73  }
74 
75  /// Defines value threshold for parameter being tracked.
76  const Decimal& threshold() const
77  {
78  return threshold_;
79  }
80 
81  /// Defines value threshold for parameter being tracked.
82  void
84  const Decimal& threshold)
85  {
86  if (0 > threshold.mantissa())
88 
89  threshold_ = threshold;
90  }
91 };
92 
93 /// Checks whether new value exceeds given
94 /// threshold in compare to the old value.
95 ONIXS_CMEMDH_EXPORTED
96 bool
98  const Decimal&,
99  const Decimal&,
100  const Decimal&);
101 
102 /// Checks whether new value exceeds given
103 /// threshold in compare to the old value.
104 ONIXS_CMEMDH_EXPORTED
105 bool
107  const Decimal&,
108  Int32,
109  Int32);
110 
111 
112 /// Defines tracking for BBO in MBO books.
114 {
115  BboThreshold price_;
116  BboThreshold quantity_;
117 
118 public:
119  /// Initializes tracking.
121  {
122  }
123 
124  /// Price tracking attributes.
125  const
126  BboThreshold&
127  price() const
128  {
129  return price_;
130  }
131 
132  /// Price tracking attributes.
134  {
135  return price_;
136  }
137 
138  /// Indicates whether tracking enabled at all.
139  bool enabled() const
140  {
141  return (
142  price_.enabled()
143  );
144  }
145 
146  /// Checks whether any of thresholds is exceeded.
147  bool
149  const Order& previous,
150  const Order& current) const
151  {
152  return (
153  price_.enabled()
154  &&
156  price_.threshold(),
157  previous.price(),
158  current.price())
159  );
160  }
161 };
162 
163 /// Serializes BBO tracking parameters into string.
164 ONIXS_CMEMDH_EXPORTED
165 void
166 toStr(
167  std::string&,
168  const MboBboTracking&);
169 
170 /// Serializes BBO tracking parameters into string.
171 inline
172 std::string
174  const MboBboTracking& tracking)
175 {
176  std::string str;
177 
178  toStr(str, tracking);
179 
180  return str;
181 }
182 
183 /// Defines tracking for BBO in implied books.
185 {
186  BboThreshold price_;
187  BboThreshold quantity_;
188 
189 public:
190  /// Initializes tracking.
192  {
193  }
194 
195  /// Price tracking attributes.
196  const
197  BboThreshold&
198  price() const
199  {
200  return price_;
201  }
202 
203  /// Price tracking attributes.
205  {
206  return price_;
207  }
208 
209  /// Quantity tracking attributes.
210  const
211  BboThreshold&
212  quantity() const
213  {
214  return quantity_;
215  }
216 
217  /// Quantity tracking attributes.
219  {
220  return quantity_;
221  }
222 
223  /// Indicates whether tracking enabled at all.
224  bool enabled() const
225  {
226  return (
227  price_.enabled()
228  ||
229  quantity_.enabled()
230  );
231  }
232 
233  /// Checks whether any of thresholds is exceeded.
234  bool
236  const ImpliedPriceLevel& previous,
237  const ImpliedPriceLevel& current) const
238  {
239  return (
240  (price_.enabled()
241  &&
243  price_.threshold(),
244  previous.price(),
245  current.price()))
246  ||
247  (quantity_.enabled()
248  &&
250  quantity_.threshold(),
251  previous.quantity(),
252  current.quantity()))
253  );
254  }
255 };
256 
257 /// Serializes BBO tracking parameters into string.
258 ONIXS_CMEMDH_EXPORTED
259 void
260 toStr(
261  std::string&,
262  const ImpliedBboTracking&);
263 
264 /// Serializes BBO tracking parameters into string.
265 inline
266 std::string
268  const ImpliedBboTracking& tracking)
269 {
270  std::string str;
271 
272  toStr(str, tracking);
273 
274  return str;
275 }
276 
277 /// Defines tracking for BBO in direct books.
280 : public ImpliedBboTracking
281 {
282  BboThreshold numberOfOrders_;
283 
284 public:
285  /// Initializes tracking.
287  {
288  }
289 
290  /// Tracking for order quantity.
291  const
292  BboThreshold&
294  {
295  return numberOfOrders_;
296  }
297 
298  /// Tracking for order quantity.
300  {
301  return numberOfOrders_;
302  }
303 
304  /// Indicates whether tracking enabled at all.
305  bool enabled() const
306  {
307  return (
308  ImpliedBboTracking::enabled()
309  ||
310  numberOfOrders_.enabled()
311  );
312  }
313 
314  /// Checks whether any of thresholds is exceeded.
315  bool
317  const DirectPriceLevel& previous,
318  const DirectPriceLevel& current) const
319  {
320  return (
321  ImpliedBboTracking::exceeded(previous, current)
322  ||
323  (numberOfOrders_.enabled()
324  &&
326  numberOfOrders_.threshold(),
327  previous.numberOfOrders(),
328  current.numberOfOrders())
329  )
330  );
331  }
332 };
333 
334 /// Serializes BBO tracking parameters into string.
335 ONIXS_CMEMDH_EXPORTED
336 void
337 toStr(
338  std::string&,
339  const DirectBboTracking&);
340 
341 /// Serializes BBO tracking parameters into string.
342 inline
343 std::string
345  const DirectBboTracking& tracking)
346 {
347  std::string str;
348 
349  toStr(str, tracking);
350 
351  return str;
352 }
353 
354 /// Parameters affecting book management machinery for
355 /// a particular book type (direct, implied, consolidated).
356 template
357 <
358  class BboTracking
359 >
361 {
362  // Indicates whether feature is enabled.
363  bool maintain_;
364 
365  // Parameters for tracking.
366  BboTracking bboTracking_;
367 
368 public:
369  /// Initializes instance with default values.
371  : maintain_(false)
372  , bboTracking_()
373  {
374  }
375 
376  /// Forces to build order book of a particular kind.
377  ///
378  /// Unless parameter is set to 'true', Handler doesn't
379  /// construct and doesn't process data blocks for the
380  /// books of given kind. If book isn't built, book snapshot
381  /// retrieval is not possible.
382  ///
383  /// @note Default value is 'false'.
384  bool maintain() const
385  {
386  return maintain_;
387  }
388 
389  /// Forces Handler to maintain direct order books.
390  void maintain(bool value)
391  {
392  maintain_ = value;
393  }
394 
395  /// Parameters affecting BBO tracking for
396  /// books which given settings refer to.
397  const BboTracking& bboTracking() const
398  {
399  return bboTracking_;
400  }
401 
402  /// Parameters affecting BBO tracking for
403  /// books which given settings refer to.
404  BboTracking& bboTracking()
405  {
406  return bboTracking_;
407  }
408 };
409 
410 /// Parameters affecting book management machinery for
411 /// a particular book type (direct, implied, consolidated).
412 template
413 <
414  class BboTracking,
415  typename Depth
416 >
417 class
419 : public BaseBookManagement
420 <
421  BboTracking
422 >
423 {
424  Depth defaultDepth_;
425 
426 public:
427  /// Initializes instance with default values.
429  Depth defaultDepth = 0)
430  : BaseBookManagement<BboTracking>()
431  , defaultDepth_(defaultDepth)
432  {
433  }
434 
435  /// Defines default depth of order book for
436  /// the security whose definition wasn't
437  /// received or had no corresponding data.
438  Depth defaultDepth() const
439  {
440  return defaultDepth_;
441  }
442 
443  /// Defines default depth of order book for
444  /// the security whose definition wasn't
445  /// received or had no corresponding data.
446  void defaultDepth(Depth value)
447  {
448  defaultDepth_ = value;
449  }
450 };
451 
452 /// Parameters affecting book management machinery
453 /// for a books having variable depth like MBO ones.
454 template
455 <
456  class BboTracking,
457  typename Depth
458 >
459 class
461 : public BaseBookManagement
462 <
463  BboTracking
464 >
465 {
466  Depth reserved_;
467 
468 public:
469  /// Initializes instance with default values.
471  : BaseBookManagement<BboTracking>()
472  {
473  }
474 };
475 
476 /// Defines book update notification strategies.
478 {
479  /// Integral type used as basement for constants.
480  typedef UInt32 Base;
481 
482  enum Enum
483  {
484  /// Book update event is raised once security id is changed in
485  /// sequence of market data entries being processed by the Handler.
486  ///
487  /// @warning Given strategy does not follow MDP policy
488  /// on exposing order books and thus can be used on own risk!
489  /// Also, books may not be in a valid state (especially consolidated),
490  /// as far as exposed earlier than data for entire market event
491  /// is processed.
493 
494  /// Book update event is raised at the end of market event.
495  ///
496  /// Direct books updates are raised at the end of real
497  /// quotes updates, implied books updates are raised at
498  /// the end of implied quotes updates and consolidated
499  /// books updates are raised at the end of entire event.
500  OnEndOfEvent
501  };
502 };
503 
504 /// Serializes book update notification policy into a string.
505 ONIXS_CMEMDH_EXPORTED
506 void
507 toStr(
508  std::string&,
510 
511 /// Serializes book update notification policy into a string.
512 inline
513 std::string
516 {
517  std::string str;
518 
519  toStr(str, strategy);
520 
521  return str;
522 }
523 
524 /// Parameters affecting book management machinery.
526 {
527 public:
528  /// Management and tracking parameters for MBO books.
529  typedef
531  <
533  SortedOrders::size_type
534  >
536 
537  /// Management and tracking parameters for direct books.
538  typedef
540  <
543  >
545 
546  /// Management and tracking parameters for implied books.
547  typedef
549  <
552  >
554 
555  /// Management and tracking parameters for consolidated books.
556  typedef
558  <
559  ImpliedBboTracking
560  >
562 
563  /// Initializes instance with default values.
565  : mboBooks_()
566  , directBooks_(10)
567  , impliedBooks_(2)
568  , consolidatedBooks_()
569  , updateNotification_(
571  OnEndOfEvent)
572  {
573  }
574 
575  /// Management and tracking parameters for direct books.
576  const
578  mboBooks() const
579  {
580  return mboBooks_;
581  }
582 
583  /// Management and tracking parameters for direct books.
586  {
587  return mboBooks_;
588  }
589 
590  /// Management and tracking parameters for direct books.
591  const
593  directBooks() const
594  {
595  return directBooks_;
596  }
597 
598  /// Management and tracking parameters for direct books.
601  {
602  return directBooks_;
603  }
604 
605  /// Management and tracking parameters for implied books.
606  const
608  impliedBooks() const
609  {
610  return impliedBooks_;
611  }
612 
613  /// Management and tracking parameters for implied books.
616  {
617  return impliedBooks_;
618  }
619 
620  /// Management and tracking parameters for consolidated books.
621  const
624  {
625  return consolidatedBooks_;
626  }
627 
628  /// Management and tracking parameters for consolidated books.
631  {
632  return consolidatedBooks_;
633  }
634 
635  /// Defines the way Handler raises onBookUpdated callbacks.
636  ///
637  /// @note Default is BookUpdateNotification::OnEndOfEvent.
640  {
641  return updateNotification_;
642  }
643 
644  /// Defines the way Handler raises order book update event.
645  void
648  {
649  updateNotification_ = value;
650  }
651 
652 private:
653  MboBookManagement mboBooks_;
654 
655  DirectBookManagement directBooks_;
656  ImpliedBookManagement impliedBooks_;
657 
658  ConsolidatedBookManagement consolidatedBooks_;
659 
660  BookUpdateNotification::Enum updateNotification_;
661 };
662 
663 /// Serializes book management settings into string.
664 ONIXS_CMEMDH_EXPORTED
665 void
666 toStr(
667  std::string&,
668  const BookManagement&);
669 
670 /// Serializes book management settings into string.
671 inline
672 std::string
674  const BookManagement& settings)
675 {
676  std::string str;
677 
678  toStr(str, settings);
679 
680  return str;
681 }
682 
BookUpdateNotification::Enum updateNotification() const
Encapsulates price level concept.
FixedDepthBookManagement< ImpliedBboTracking, MbpBookDepth > ImpliedBookManagement
Management and tracking parameters for implied books.
void threshold(const Decimal &threshold)
Defines value threshold for parameter being tracked.
#define ONIXS_CMEMDH_LTWT_CLASS
Definition: Bootstrap.h:110
const ImpliedBookManagement & impliedBooks() const
Management and tracking parameters for implied books.
Int32 quantity() const
Quantify for the given price.
Int32 Int32
int32.
Definition: Fields.h:63
Defines tracking for BBO in direct books.
void maintain(bool value)
Forces Handler to maintain direct order books.
ImpliedBookManagement & impliedBooks()
Management and tracking parameters for implied books.
AnyDepthBookManagement< MboBboTracking, SortedOrders::size_type > MboBookManagement
Management and tracking parameters for MBO books.
const BboTracking & bboTracking() const
DirectBboTracking()
Initializes tracking.
BboThreshold & price()
Price tracking attributes.
BboThreshold & price()
Price tracking attributes.
UInt32 UInt32
uInt32.
Definition: Fields.h:189
const DirectBookManagement & directBooks() const
Management and tracking parameters for direct books.
const Decimal & threshold() const
Defines value threshold for parameter being tracked.
BookManagement()
Initializes instance with default values.
Defines tracking for BBO in MBO books.
void updateNotification(BookUpdateNotification::Enum value)
Defines the way Handler raises order book update event.
BaseBookManagement()
Initializes instance with default values.
bool enabled() const
Indicates whether tracking enabled at all.
DirectBookManagement & directBooks()
Management and tracking parameters for direct books.
Order as the member of the Market By Order (MBO) book.
Definition: Order.h:79
const BboThreshold & numberOfOrders() const
Tracking for order quantity.
std::string toStr(const BookManagement &settings)
Serializes book management settings into string.
const BboThreshold & price() const
Price tracking attributes.
Int32 & numberOfOrders()
Updates total number of orders.
BboThreshold()
Initializes parameter tracking.
BaseBookManagement< ImpliedBboTracking > ConsolidatedBookManagement
Management and tracking parameters for consolidated books.
const Decimal & price() const
Order price.
Definition: Order.h:145
Mantissa mantissa() const
Returns mantissa of given decimal.
Definition: Decimal.h:269
bool enabled() const
Indicates whether tracking enabled at all.
bool exceeded(const DirectPriceLevel &previous, const DirectPriceLevel &current) const
Checks whether any of thresholds is exceeded.
Defines tracking for BBO in implied books.
const ConsolidatedBookManagement & consolidatedBooks() const
Management and tracking parameters for consolidated books.
void enabled(bool value)
Indicates whether tracking is enabled.
Encapsulates price level concept.
Defines tracking attributes for a particular BBO parameter.
#define ONIXS_CMEMDH_LTWT_STRUCT
Definition: Bootstrap.h:114
BboThreshold & numberOfOrders()
Tracking for order quantity.
Defines book update notification strategies.
MboBookManagement & mboBooks()
Management and tracking parameters for direct books.
UInt8 MbpBookDepth
Market by price order book depth type.
Definition: MbpBookTraits.h:28
const Decimal & price() const
A real number with floating exponent.
Definition: Decimal.h:220
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition: Bootstrap.h:168
bool exceeded(const ImpliedPriceLevel &previous, const ImpliedPriceLevel &current) const
Checks whether any of thresholds is exceeded.
bool enabled() const
Indicates whether tracking is enabled.
MboBboTracking()
Initializes tracking.
const BboThreshold & quantity() const
Quantity tracking attributes.
BboThreshold & quantity()
Quantity tracking attributes.
FixedDepthBookManagement< DirectBboTracking, MbpBookDepth > DirectBookManagement
Management and tracking parameters for direct books.
FixedDepthBookManagement(Depth defaultDepth=0)
Initializes instance with default values.
bool enabled() const
Indicates whether tracking enabled at all.
const MboBookManagement & mboBooks() const
Management and tracking parameters for direct books.
const BboThreshold & price() const
Price tracking attributes.
ConsolidatedBookManagement & consolidatedBooks()
Management and tracking parameters for consolidated books.
void throwBadBboThreshold()
Raises exception on invalid best bid/offer threshold value.
bool exceeded(const Order &previous, const Order &current) const
Checks whether any of thresholds is exceeded.
Parameters affecting book management machinery.
AnyDepthBookManagement()
Initializes instance with default values.
ONIXS_CMEMDH_EXPORTED bool thresholdExceeded(const Decimal &, Int32, Int32)
ImpliedBboTracking()
Initializes tracking.
UInt32 Base
Integral type used as basement for constants.
#define ONIXS_CMEMDH_NAMESPACE_END
Definition: Bootstrap.h:172