OnixS C++ CME MDP Conflated UDP Handler  1.1.2
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 
26 
28 
30 
32 
34 
35 /// Raises exception on invalid best bid/offer threshold value.
36 inline
37 void
39 {
40  throw std::runtime_error
41  (
42  "Threshold for tracking best bids "
43  "or offers can't be a negative value. "
44  );
45 }
46 
47 /// Defines tracking attributes for a particular BBO parameter.
49 {
50  // Group which the given set of settings belongs to.
51  const SettingGroup& group_;
52 
53  // Actual threshold value.
54  Decimal threshold_;
55 
56  // Indicates whether threshold must be used.
57  bool enabled_;
58 
59 protected:
60 
61  /// Lets grouping and value assignment control functioning.
62  friend
64  (
66  );
67 
68  /// Instance of a group which the
69  /// given set of settings belongs to.
70  const SettingGroup& group() const
71  {
72  return group_;
73  }
74 
75  /// Re-initializes the instance as a copy of the
76  /// other one and bypassing assignment control.
77  void
78  assignNoControl(
79  const BboThreshold& other)
80  {
81  threshold_ = other.threshold_;
82  enabled_ = other.enabled_;
83  }
84 
85 public:
86  /// Initializes BBO attribute (price, qty, etc) tracking.
87  ///
88  /// Optional setting group instance allows binding the given
89  /// set of settings to a particular group of settings.
91  const SettingGroup* group = NULL)
92  : group_(group ? *group : SettingGroup::null())
93  , threshold_(), enabled_(false)
94  {
95  }
96 
97  /// Initializes as a copy of the
98  /// other one.
99  ///
100  /// Attributes controlling value
101  /// assignment aren't cloned and
102  /// thus only settings are copied.
103  BboThreshold(
104  const BboThreshold& other)
105  : group_(
106  SettingGroup::null())
107  , threshold_(
108  other.threshold_)
109  , enabled_(
110  other.enabled_)
111  {
112  }
113 
114  /// Finalizes the group.
115  ~BboThreshold()
116  {
117  }
118 
119  /// Indicates whether tracking is enabled.
120  bool
121  enabled() const
122  {
123  return enabled_;
124  }
125 
126  /// Indicates whether tracking is enabled.
127  void
128  enabled(
129  bool value)
130  {
131  group_.
132  controlAssignment
133  (
134  "BBO Threshold Enable",
135  enabled_,
136  value
137  );
138  }
140  /// Threshold for the parameter being tracked.
141  const
142  Decimal&
143  threshold() const
144  {
145  return threshold_;
146  }
148  /// Updates threshold for the
149  /// parameter being tracked.
150  void
151  threshold(
152  const Decimal& value)
153  {
154  if (0 <= value.mantissa())
155  {
156  group_.
157  controlAssignment
158  (
159  "BBO Threshold",
160  threshold_,
161  value
162  );
163  }
164  else
165  {
167  }
168  }
169 
170  /// Re-initializes as a copy of the other one.
171  ///
172  /// Attributes controlling value assignment aren't
173  /// cloned and thus only settings are copied.
174  BboThreshold&
175  operator =(
176  const BboThreshold& other)
177  {
178  group_.
179  controlAssignment
180  (
181  "BBO Threshold Settings",
182  &BboThreshold::assignNoControl,
183  *this,
184  other
185  );
186 
187  return *this;
188  }
189 };
190 
191 /// Checks whether new value exceeds given
192 /// threshold in compare to the old value.
193 ONIXS_CONFLATEDUDP_EXPORTED
194 bool
196  const Decimal&,
197  const Decimal&,
198  const Decimal&);
199 
200 /// Checks whether new value exceeds given
201 /// threshold in compare to the old value.
202 ONIXS_CONFLATEDUDP_EXPORTED
203 bool
205  const Decimal&,
206  Int64,
207  Int64);
208 
209 /// Defines tracking for BBO in direct books.
212 {
213  BboThreshold price_;
214  BboThreshold quantity_;
215  BboThreshold numberOfOrders_;
216 
217 protected:
218  /// Lets grouping and value
219  /// assignment control functioning.
220  template<class>
221  friend
222  class
224 
225  /// Instance of the group of setting which
226  /// the given set of settings belongs to.
227  const
228  SettingGroup&
229  group() const
230  {
231  return price_.group();
232  }
233 
234  /// Re-initializes as a copy of the other instance
235  /// without involving value assignment control services.
236  void
237  assignNoControl(
238  const DirectBboTracking& other)
239  {
240  price_.assignNoControl(other.price_);
241  quantity_.assignNoControl(other.quantity_);
242  numberOfOrders_.assignNoControl(other.numberOfOrders_);
243  }
244 
245 public:
246  /// Initializes tracking with the
247  /// optional grouping services enabled.
249  const SettingGroup* group = NULL)
250  : price_(group)
251  , quantity_(group)
252  , numberOfOrders_(group)
253  {
254  }
255 
256  /// Initializes the instance
257  /// as a copy of the other one.
258  ///
259  /// Attributes controlling value
260  /// assignment aren't cloned and
261  /// thus only settings are copied.
263  const DirectBboTracking& other)
264  : price_(other.price_)
265  , quantity_(other.quantity_)
266  , numberOfOrders_(other.numberOfOrders_)
267  {
268  }
270  /// Finalizes the instance.
272  {
273  }
274 
275  /// Price tracking attributes.
276  const
277  BboThreshold&
278  price() const
279  {
280  return price_;
281  }
283  /// Price tracking attributes.
284  BboThreshold& price()
285  {
286  return price_;
287  }
288 
289  /// Quantity tracking attributes.
290  const
291  BboThreshold&
292  quantity() const
293  {
294  return quantity_;
295  }
297  /// Quantity tracking attributes.
298  BboThreshold& quantity()
299  {
300  return quantity_;
301  }
302 
303  /// Tracking for order quantity.
304  const
305  BboThreshold&
306  numberOfOrders() const
307  {
308  return numberOfOrders_;
309  }
310 
311  /// Tracking for order quantity.
312  BboThreshold&
313  numberOfOrders()
314  {
315  return numberOfOrders_;
316  }
317 
318  /// Indicates whether tracking enabled at all.
319  bool
320  enabled() const
321  {
322  return (
323  price_.enabled()
324  ||
325  quantity_.enabled()
326  ||
327  numberOfOrders_.enabled()
328  );
329  }
330 
331  /// Checks whether any of thresholds is exceeded.
332  bool
333  exceeded(
334  const DirectPriceLevel& previous,
335  const DirectPriceLevel& current) const
336  {
337  return
338  (
339  (price_.enabled() && thresholdExceeded(price_.threshold(), previous.price(), current.price()))
340  ||
341  (quantity_.enabled() && thresholdExceeded(quantity_.threshold(), previous.quantity(), current.quantity()))
342  ||
343  (numberOfOrders_.enabled() && thresholdExceeded( numberOfOrders_.threshold(), previous.numberOfOrders(), current.numberOfOrders()))
344  );
345  }
346 
347  /// Re-initializes instance as
348  /// a copy of the other one.
349  ///
350  /// Attributes controlling value
351  /// assignment aren't cloned and
352  /// thus only settings are copied.
354  operator =(
355  const DirectBboTracking& other)
356  {
357  group().
358  controlAssignment
359  (
360  "Direct BBO Tracking Settings",
361  &DirectBboTracking::assignNoControl,
362  *this,
363  other
364  );
365 
366  return *this;
367  }
368 };
369 
370 /// Serializes BBO tracking parameters into string.
371 ONIXS_CONFLATEDUDP_EXPORTED
372 void
373 toStr(
374  std::string&,
375  const DirectBboTracking&);
376 
377 /// Serializes BBO tracking parameters into string.
378 inline
379 std::string
381  const DirectBboTracking& tracking)
382 {
383  std::string str;
384 
385  toStr(str, tracking);
386 
387  return str;
388 }
389 
390 /// Parameters affecting book management machinery for
391 /// a particular book type (direct).
392 template
393 <
394  class BboTracking
395 >
396 class
398 {
399  // Indicates whether feature is enabled.
400  bool maintain_;
401 
402  // Parameters for tracking.
403  BboTracking bboTracking_;
404 
405 protected:
406  /// Lets grouping and value
407  /// assignment control functioning.
408  friend
410  (
412  );
413 
414  /// Instance of the group of setting which
415  /// the given set of settings belongs to.
416  const
417  SettingGroup&
418  group() const
419  {
420  return bboTracking_.group();
421  }
423  /// Re-initializes as a copy of the other instance
424  /// without involving value assignment control services.
425  void
426  assignNoControl(
427  const BaseBookManagement& other)
428  {
429  maintain_ =
430  other.maintain_;
431 
432  bboTracking_.
433  assignNoControl(
434  other.bboTracking_);
435  }
437 public:
438  /// Initializes instance with the default values
439  /// and setting validation facilities enabled.
441  const SettingGroup* group = NULL)
442  : maintain_(false), bboTracking_(group)
443  {
444  }
445 
446  /// Initializes the instance
447  /// as a copy of the other one.
448  ///
449  /// Attributes controlling value
450  /// assignment aren't cloned and
451  /// thus only settings are copied.
453  const BaseBookManagement& other)
454  : maintain_(other.maintain_)
455  , bboTracking_(other.bboTracking_)
456  {
457  }
458 
459  /// Finalizes the instance.
461  {
462  }
463 
464  /// Forces to build order book of a particular kind.
465  ///
466  /// Unless parameter is set to 'true', Handler doesn't
467  /// construct and doesn't process data blocks for the
468  /// books of given kind. If book isn't built, book snapshot
469  /// retrieval is not possible.
470  ///
471  /// @note Default value is 'false'.
472  bool
473  maintain() const
474  {
475  return maintain_;
476  }
477 
478  /// Forces Handler to maintain order books.
479  void
480  maintain(
481  bool value)
482  {
483  group().
484  controlAssignment
485  (
486  "Maintain",
487  maintain_,
488  value
489  );
490  }
491 
492  /// Parameters affecting BBO tracking for
493  /// books which given settings refer to.
494  const
495  BboTracking&
496  bboTracking() const
497  {
498  return bboTracking_;
499  }
500 
501  /// Parameters affecting BBO tracking for
502  /// books which given settings refer to.
503  BboTracking& bboTracking()
504  {
505  return bboTracking_;
506  }
507 
508  /// Re-initializes the instance
509  /// as a copy of other one.
510  ///
511  /// Attributes controlling value
512  /// assignment aren't cloned and
513  /// thus only settings are copied.
515  operator =(
516  const
517  BaseBookManagement& other)
518  {
519  group().
520  controlAssignment
521  (
522  "Base Book Management Settings",
523  &BaseBookManagement::assignNoControl,
524  *this,
525  other
526  );
527 
528  return *this;
529  }
530 };
531 
532 /// Parameters affecting book management machinery for
533 /// a particular book type (direct).
534 template
535 <
536  class BboTracking,
537  typename Depth
538 >
539 class
541 : public BaseBookManagement
542 <
543  BboTracking
544 >
545 {
546  // Lets grouping and value assignment control functioning.
547  friend
549  (
551  );
552 
553  // Alias for the base class.
554  typedef
556  <
557  BboTracking
558  >
559  Base;
560 
561  //
562 
563  Depth defaultDepth_;
564 
565  // Re-initializes as a copy of the other instance
566  // without involving value assignment control services.
567  void
568  assignNoControl(
569  const FixedDepthBookManagement& other)
570  {
571  Base::assignNoControl(other);
572 
573  defaultDepth_ =
574  other.defaultDepth_;
575  }
577 public:
578  /// Initializes instance with defaults
579  /// and optional grouping facilities.
581  const SettingGroup* group = NULL,
582  Depth defaultDepth = 0)
583  : Base(group)
584  , defaultDepth_(
585  defaultDepth)
586  {
587  }
588 
589  /// Initializes the instance
590  /// as a copy of the other one.
591  ///
592  /// Attributes controlling value
593  /// assignment aren't cloned and
594  /// thus only settings are copied.
596  const
598  : Base(
599  static_cast
600  <const Base&>
601  (other))
602  , defaultDepth_(
603  other.defaultDepth_)
604  {
605  }
606 
607  /// Finalizes the instance.
609  {
610  }
611 
612  /// Defines default depth of order book for
613  /// the security whose definition wasn't
614  /// received or had no corresponding data.
615  Depth
616  defaultDepth() const
617  {
618  return defaultDepth_;
619  }
620 
621  /// Defines default depth of order book for
622  /// the security whose definition wasn't
623  /// received or had no corresponding data.
624  void
625  defaultDepth(
626  Depth value)
627  {
628  this->
629  group().
630  controlAssignment
631  (
632  "Default Depth",
633  defaultDepth_,
634  value
635  );
636  }
637 
638  /// Re-initializes the instance
639  /// as a copy of the other one.
640  ///
641  /// Attributes controlling value
642  /// assignment aren't cloned and
643  /// thus only settings are copied.
645  operator =(
646  const
648  {
649  this->
650  group().
651  controlAssignment
652  (
653  "Fixed Depth Book Management Settings",
654  &FixedDepthBookManagement::assignNoControl,
655  *this,
656  other
657  );
658 
659  return *this;
660  }
661 };
662 
663 /// Defines book update notification strategies.
665 {
666  /// Integral type used as basement for constants.
667  typedef UInt32 Base;
668 
669  enum Enum
670  {
671  /// Book update event is raised once security id is changed in
672  /// sequence of market data entries being processed by the Handler.
673  ///
674  /// @warning Given strategy does not follow MDP policy
675  /// on exposing order books and thus can be used on own risk!
676  /// Also, books may not be in a valid state (especially consolidated),
677  /// as far as exposed earlier than data for entire market event
678  /// is processed.
680 
681  /// Book update event is raised at the end of market event.
682  ///
683  /// Direct books updates are raised at the end of real
684  /// quotes updates.
685  OnEndOfEvent
686  };
687 };
688 
689 /// Serializes book update notification policy into a string.
690 ONIXS_CONFLATEDUDP_EXPORTED
691 void
692 toStr(
693  std::string&,
695 
696 /// Serializes book update notification policy into a string.
697 inline
698 std::string
701 {
702  std::string str;
703 
704  toStr(str, strategy);
705 
706  return str;
707 }
708 
709 // Aliases for instantiations.
710 
711 /// Management and tracking parameters for direct books.
712 typedef
714 <
717 >
719 
720 /// Parameters affecting book management machinery.
723 {
724  // Lets grouping and value
725  // assignment control functioning.
726  friend
728  (
730  );
731 
732  // Subsets of parameters.
733 
734  DirectBookManagement directBooks_;
735 
736  BookUpdateNotification::Enum updateNotification_;
737 
738  // Casts the given instance to an
739  // instance of SettingGroup class.
740  const
741  SettingGroup&
742  group() const
743  {
744  return *this;
745  }
746 
747  // Re-initializes the given instance
748  // as a copy of the other one without
749  // involving assignment control service.
750  void
751  assignNoControl(
752  const BookManagement& other)
753  {
754  directBooks_.
755  assignNoControl(
756  other.directBooks_);
757 
758  updateNotification_ =
759  other.updateNotification_;
760  }
761 
762 public:
763  /// Initializes instance with default values.
766  controller = NULL)
767  : SettingGroup(controller)
768  , directBooks_(&group(), 10)
769  , updateNotification_(
771  OnEndOfEvent)
772  {
773  }
774 
775  /// Initializes the instance
776  /// as a copy of the other one.
777  ///
778  /// Attributes controlling value
779  /// assignment aren't cloned and
780  /// thus only settings are copied.
782  const BookManagement& other)
783  : SettingGroup()
784  , directBooks_(
785  other.directBooks_)
786  , updateNotification_(
787  other.updateNotification_)
788  {
789  }
790 
791  // Finalizes the instance.
792  ~BookManagement()
793  {
794  }
796  /// Management and tracking parameters for direct books.
797  const
799  directBooks() const
800  {
801  return directBooks_;
802  }
803 
804  /// Management and tracking parameters for direct books.
806  directBooks()
807  {
808  return directBooks_;
809  }
810 
811  /// Defines the way Handler raises onBookUpdated callbacks.
812  ///
813  /// @note Default is BookUpdateNotification::OnEndOfEvent.
815  updateNotification() const
816  {
817  return updateNotification_;
818  }
819 
820  /// Defines the way Handler raises order book update event.
821  void
822  updateNotification(
824  {
825  group().
826  controlAssignment
827  (
828  "Update Notification",
829  updateNotification_,
830  value
831  );
832  }
833 
834  /// Copies settings from the given instance.
835  ///
836  /// Attributes controlling value assignment aren't
837  /// cloned and thus only settings' values are copied.
839  operator =(
840  const BookManagement& other)
841  {
842  group().
843  controlAssignment
844  (
845  "Book Management Settings",
846  &BookManagement::assignNoControl,
847  *this,
848  other
849  );
850 
851  return *this;
852  }
853 };
854 
855 /// Serializes book management settings into string.
856 ONIXS_CONFLATEDUDP_EXPORTED
857 void
858 toStr(
859  std::string&,
860  const BookManagement&);
861 
862 /// Serializes book management settings into string.
863 inline
864 std::string
866  const BookManagement& settings)
867 {
868  std::string str;
869 
870  toStr(str, settings);
871 
872  return str;
873 }
874 
A real number with floating exponent.
Definition: Decimal.h:231
Parameters affecting book management machinery.
UInt32 Base
Integral type used as basement for constants.
bool enabled() const
Indicates whether tracking is enabled.
FixedDepthBookManagement< DirectBboTracking, MbpBookDepth > DirectBookManagement
Management and tracking parameters for direct books.
Int32 & numberOfOrders()
Updates total number of orders.
void throwBadBboThreshold()
Raises exception on invalid best bid/offer threshold value.
Defines book update notification strategies.
UInt8 MbpBookDepth
Market by price order book depth type.
Definition: MbpBookTraits.h:28
Mantissa mantissa() const
Returns mantissa of given decimal.
Definition: Decimal.h:290
Defines tracking for BBO in direct books.
void assignNoControl(const BboThreshold &other)
Handler&#39;s configuration settings.
UInt32 UInt32
uInt32.
Definition: Fields.h:261
#define ONIXS_CONFLATEDUDP_LTWT_CLASS_DECL(name)
Definition: Bootstrap.h:107
Encapsulates price level concept.
const SettingGroup & group() const
Defines tracking attributes for a particular BBO parameter.
#define ONIXS_CONFLATEDUDP_LTWT_STRUCT
Definition: Bootstrap.h:99
std::string toStr(const BookManagement &settings)
Serializes book management settings into string.
Base services for settings grouped by a certain criteria.
Definition: SettingGroup.h:123
Int64 quantity() const
Quantify for the given price.
#define ONIXS_CONFLATEDUDP_NAMESPACE_END
Definition: Bootstrap.h:157
bool value(Number &number, const MultiContainer &container, Tag tag)
const Decimal & threshold() const
Threshold for the parameter being tracked.
ONIXS_CONFLATEDUDP_EXPORTED bool thresholdExceeded(const Decimal &, Int64, Int64)
#define ONIXS_CONFLATEDUDP_LTWT_CLASS
Definition: Bootstrap.h:95
#define ONIXS_CONFLATEDUDP_NAMESPACE_BEGIN
Definition: Bootstrap.h:153