OnixS C++ CME MDP Premium Market Data Handler 5.11.1
Users' manual and API documentation
Loading...
Searching...
No Matches
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
31
33
35
40
47{
48public:
54 : group_(group ? *group : SettingGroup::null())
55 , threshold_()
56 , enabled_(false)
57 {
58 }
59
66 : group_(SettingGroup::null())
67 , threshold_(other.threshold_)
68 , enabled_(other.enabled_)
69 {
70 }
71
73 ~BboThreshold() = default;
74
80 bool enabled() const noexcept
81 {
82 return enabled_;
83 }
84
91 BboThreshold& enabled(bool value)
92 {
93 group_.controlAssignment("BBO Threshold Enable", enabled_, value);
94
95 return *this;
96 }
97
102 const Messaging::Decimal& threshold() const noexcept
103 {
104 return threshold_;
105 }
106
115 {
116 if (0 <= value.mantissa())
117 {
118 group_.controlAssignment("BBO Threshold", threshold_, value);
119 }
120 else
121 {
123 }
124
125 return *this;
126 }
127
137 {
138 group_.controlChange("BBO Threshold Settings", &BboThreshold::assignNoControl, *this, other);
139
140 return *this;
141 }
142
143protected:
146
149
152
156 const SettingGroup& group() const
157 {
158 return group_;
159 }
160
163 void assignNoControl(const BboThreshold& other)
164 {
165 threshold_ = other.threshold_;
166 enabled_ = other.enabled_;
167 }
168
169private:
170 // Group which the given set of settings belongs to.
171 const SettingGroup& group_;
172
173 // Actual threshold value.
174 Messaging::Decimal threshold_;
175
176 // Indicates whether threshold must be used.
177 bool enabled_;
178};
179
190 const Messaging::Decimal& threshold, const Messaging::Decimal& previous, const Messaging::Decimal& current);
191
202
205{
206public:
212 : price_(group)
213 {
214 }
215
222 : price_(other.price_)
223 {
224 }
225
227 ~MboBboTracking() = default;
228
233 const BboThreshold& price() const noexcept
234 {
235 return price_;
236 }
237
242 BboThreshold& price() noexcept
243 {
244 return price_;
245 }
246
251 bool enabled() const noexcept
252 {
253 return (price_.enabled());
254 }
255
262 bool exceeded(const Order& previous, const Order& current) const
263 {
264 return (price_.enabled() && thresholdExceeded(price_.threshold(), previous.price(), current.price()));
265 }
266
274 {
275 group().controlChange("MBO BBO Tracking Settings", &MboBboTracking::assignNoControl, *this, other);
276
277 return *this;
278 }
279
280protected:
282 template <class>
283 friend class BaseBookManagement;
284
288 const SettingGroup& group() const
289 {
290 return price_.group();
291 }
292
296 {
297 price_.assignNoControl(other.price_);
298 }
299
300private:
301 BboThreshold price_;
302};
303
309void toStr(std::string& str, const MboBboTracking& tracking);
310
315inline ONIXS_CMEMDH_NODISCARD std::string toStr(const MboBboTracking& tracking)
316{
317 std::string str;
318
319 toStr(str, tracking);
320
321 return str;
322}
323
326{
327public:
333 : price_(group)
334 , quantity_(group)
335 {
336 }
337
344 : price_(other.price_)
345 , quantity_(other.quantity_)
346 {
347 }
348
351
356 const BboThreshold& price() const noexcept
357 {
358 return price_;
359 }
360
365 BboThreshold& price() noexcept
366 {
367 return price_;
368 }
369
374 const BboThreshold& quantity() const noexcept
375 {
376 return quantity_;
377 }
378
384 {
385 return quantity_;
386 }
387
392 bool enabled() const noexcept
393 {
394 return (price_.enabled() || quantity_.enabled());
395 }
396
403 bool exceeded(const ImpliedPriceLevel& previous, const ImpliedPriceLevel& current) const
404 {
405 return (
406 (price_.enabled() && thresholdExceeded(price_.threshold(), previous.price(), current.price()))
407 || (quantity_.enabled() && thresholdExceeded(quantity_.threshold(), previous.quantity(), current.quantity())
408 )
409 );
410 }
411
421 {
422 group().controlChange("Implied BBO Tracking Settings", &ImpliedBboTracking::assignNoControl, *this, other);
423
424 return *this;
425 }
426
427protected:
429 template <class>
430 friend class BaseBookManagement;
431
435 const SettingGroup& group() const
436 {
437 return price_.group();
438 }
439
443 {
444 price_.assignNoControl(other.price_);
445 quantity_.assignNoControl(other.quantity_);
446 }
447
448private:
449 BboThreshold price_;
450 BboThreshold quantity_;
451};
452
458void toStr(std::string& str, const ImpliedBboTracking& tracking);
459
464inline ONIXS_CMEMDH_NODISCARD std::string toStr(const ImpliedBboTracking& tracking)
465{
466 std::string str;
467
468 toStr(str, tracking);
469
470 return str;
471}
472
475{
476public:
483 , numberOfOrders_(group)
484 {
485 }
486
493 : ImpliedBboTracking(static_cast<const ImpliedBboTracking&>(other))
494 , numberOfOrders_(other.numberOfOrders_)
495 {
496 }
497
500
505 const BboThreshold& numberOfOrders() const noexcept
506 {
507 return numberOfOrders_;
508 }
509
515 {
516 return numberOfOrders_;
517 }
518
524 bool enabled() const noexcept
525 {
526 return (ImpliedBboTracking::enabled() || numberOfOrders_.enabled());
527 }
528
535 bool exceeded(const DirectPriceLevel& previous, const DirectPriceLevel& current) const
536 {
537 return (
538 ImpliedBboTracking::exceeded(previous, current)
539 || (numberOfOrders_.enabled()
540 && thresholdExceeded(numberOfOrders_.threshold(), previous.numberOfOrders(), current.numberOfOrders()))
541 );
542 }
543
553 {
554 group().controlChange("Direct BBO Tracking Settings", &DirectBboTracking::assignNoControl, *this, other);
555
556 return *this;
557 }
558
559protected:
562 template <class>
563 friend class BaseBookManagement;
564
568 {
570
571 numberOfOrders_.assignNoControl(other.numberOfOrders_);
572 }
573
574private:
575 BboThreshold numberOfOrders_;
576};
577
583void toStr(std::string& str, const DirectBboTracking& tracking);
584
589inline ONIXS_CMEMDH_NODISCARD std::string toStr(const DirectBboTracking& tracking)
590{
591 std::string str;
592
593 toStr(str, tracking);
594
595 return str;
596}
597
601template <class BboTracking>
603{
604public:
610 : maintain_(false)
611 , bboTracking_(group)
612 {
613 }
614
621 : maintain_(other.maintain_)
622 , bboTracking_(other.bboTracking_)
623 {
624 }
625
628
638 bool maintain() const noexcept
639 {
640 return maintain_;
641 }
642
650 {
651 group().controlAssignment("Maintain", maintain_, value);
652
653 return *this;
654 }
655
660 const BboTracking& bboTracking() const noexcept
661 {
662 return bboTracking_;
663 }
664
669 BboTracking& bboTracking() noexcept
670 {
671 return bboTracking_;
672 }
673
683 {
684 group().controlChange("Base Book Management Settings", &BaseBookManagement::assignNoControl, *this, other);
685
686 return *this;
687 }
688
689protected:
693
697 const SettingGroup& group() const
698 {
699 return bboTracking_.group();
700 }
701
705 {
706 maintain_ = other.maintain_;
707
708 bboTracking_.assignNoControl(other.bboTracking_);
709 }
710
711private:
712 // Indicates whether feature is enabled.
713 bool maintain_;
714
715 // Parameters for tracking.
716 BboTracking bboTracking_;
717};
718
723template <class BboTracking, typename Depth>
725{
726public:
734 : Base(group)
735 , defaultDepth_(defaultDepth)
736 {
737 }
738
745 : Base(static_cast<const Base&>(other))
746 , defaultDepth_(other.defaultDepth_)
747 {
748 }
749
752
760 Depth defaultDepth() const
761 {
762 return defaultDepth_;
763 }
764
773 {
774 this->group().controlAssignment("Default Depth", defaultDepth_, value);
775
776 return *this;
777 }
778
788 {
789 this->group().controlChange(
790 "Fixed Depth Book Management Settings", &FixedDepthBookManagement::assignNoControl, *this, other
791 );
792
793 return *this;
794 }
795
796private:
797 // Lets grouping and value assignment control functioning.
799
800 // Alias for the base class.
802
803 //
804
805 Depth defaultDepth_;
806
807 // Re-initializes as a copy of the other instance
808 // without involving value assignment control services.
809 void assignNoControl(const FixedDepthBookManagement& other)
810 {
812
813 defaultDepth_ = other.defaultDepth_;
814 }
815};
816
822template <class BboTracking, typename Depth>
824{
825public:
831 : Base(group)
832 {
833 }
834
841 : Base(static_cast<const Base&>(other))
842 {
843 }
844
854 {
855 this->group().controlChange(
856 "Any Depth Book Management Settings", &AnyDepthBookManagement::assignNoControl, *this, other
857 );
858
859 return *this;
860 }
861
862private:
863 // Lets grouping and value assignment control functioning.
865
866 // Alias for the base class.
868
869 Depth reserved_;
870
871 // Re-initializes as a copy of the other instance
872 // without involving value assignment control services.
873 void assignNoControl(const AnyDepthBookManagement& other)
874 {
876 }
877};
878
908
914void toStr(std::string& str, BookUpdateNotification::Enum strategy);
915
921{
922 std::string str;
923
924 toStr(str, strategy);
925
926 return str;
927}
928
929// Aliases for instantiations.
930
933
936
939
942
948{
949public:
959 : SettingGroup(controller)
960 , mboBooks_(&group())
961 , directBooks_(&group(), 10)
962 , impliedBooks_(&group(), 2)
963 , updateNotification_(BookUpdateNotification::OnEndOfEvent)
964 {
965 }
966
973 : SettingGroup()
974 , mboBooks_(other.mboBooks_)
975 , directBooks_(other.directBooks_)
976 , impliedBooks_(other.impliedBooks_)
977 , consolidatedBooks_(other.consolidatedBooks_)
978 , updateNotification_(other.updateNotification_)
979 {
980 }
981
983 ~BookManagement() = default;
984
989 const MboBookManagement& mboBooks() const noexcept
990 {
991 return mboBooks_;
992 }
993
999 {
1000 return mboBooks_;
1001 }
1002
1007 const DirectBookManagement& directBooks() const noexcept
1008 {
1009 return directBooks_;
1010 }
1011
1017 {
1018 return directBooks_;
1019 }
1020
1025 const ImpliedBookManagement& impliedBooks() const noexcept
1026 {
1027 return impliedBooks_;
1028 }
1029
1035 {
1036 return impliedBooks_;
1037 }
1038
1044 {
1045 return consolidatedBooks_;
1046 }
1047
1053 {
1054 return consolidatedBooks_;
1055 }
1056
1063 {
1064 return updateNotification_;
1065 }
1066
1074 {
1075 group().controlAssignment("Update Notification", updateNotification_, value);
1076
1077 return *this;
1078 }
1079
1089 {
1090 group().controlChange("Book Management Settings", &BookManagement::assignNoControl, *this, other);
1091
1092 return *this;
1093 }
1094
1095private:
1096 // Lets grouping and value
1097 // assignment control functioning.
1099
1100 // Subsets of parameters.
1101
1102 MboBookManagement mboBooks_;
1103
1104 DirectBookManagement directBooks_;
1105 ImpliedBookManagement impliedBooks_;
1106
1107 ConsolidatedBookManagement consolidatedBooks_;
1108
1109 BookUpdateNotification::Enum updateNotification_;
1110
1111 // Casts the given instance to an
1112 // instance of SettingGroup class.
1114 const SettingGroup& group() const
1115 {
1116 return *this;
1117 }
1118
1119 // Re-initializes the given instance
1120 // as a copy of the other one without
1121 // involving assignment control service.
1122 void assignNoControl(const BookManagement& other)
1123 {
1124 mboBooks_.assignNoControl(other.mboBooks_);
1125
1126 directBooks_.assignNoControl(other.directBooks_);
1127
1128 impliedBooks_.assignNoControl(other.impliedBooks_);
1129
1130 consolidatedBooks_.assignNoControl(other.consolidatedBooks_);
1131
1132 updateNotification_ = other.updateNotification_;
1133 }
1134};
1135
1141void toStr(std::string& str, const BookManagement& settings);
1142
1147inline ONIXS_CMEMDH_NODISCARD std::string toStr(const BookManagement& settings)
1148{
1149 std::string str;
1150
1151 toStr(str, settings);
1152
1153 return str;
1154}
1155
#define ONIXS_CMEMDH_NAMESPACE_BEGIN
Definition Bootstrap.h:69
#define ONIXS_CMEMDH_LTWT
Definition Bootstrap.h:61
#define ONIXS_CMEMDH_LTWT_CLASS_DECL(name)
Definition Bootstrap.h:63
#define ONIXS_CMEMDH_NAMESPACE_END
Definition Bootstrap.h:73
#define ONIXS_CMEMDH_EXPORTED
Definition Compiler.h:163
#define ONIXS_CMEMDH_NORETURN
Definition Compiler.h:164
#define ONIXS_CMEMDH_NODISCARD
Definition Compiler.h:165
Configures book management for variable-depth book types.
AnyDepthBookManagement(const SettingGroup *group=nullptr)
Initializes variable-depth book management settings.
AnyDepthBookManagement(const AnyDepthBookManagement &other)
Copies variable-depth book-management settings from another instance.
AnyDepthBookManagement & operator=(const AnyDepthBookManagement &other)
Copies variable-depth book-management settings from another instance.
Configures common book-maintenance settings for one book type.
~BaseBookManagement()=default
Finalizes the book-management settings.
BaseBookManagement(const SettingGroup *group=nullptr)
Initializes book management with maintenance disabled.
BaseBookManagement(const BaseBookManagement &other)
Copies book-management settings from another instance.
BaseBookManagement & maintain(bool value)
Enables or disables maintenance of this book type.
BboTracking & bboTracking() noexcept
Returns mutable BBO tracking settings for this book type.
bool maintain() const noexcept
Indicates whether the Handler maintains this book type.
BaseBookManagement & operator=(const BaseBookManagement &other)
Copies book-management settings from another instance.
const BboTracking & bboTracking() const noexcept
Returns read-only BBO tracking settings for this book type.
void assignNoControl(const BaseBookManagement &other)
Stores threshold tracking settings for one BBO attribute.
bool enabled() const noexcept
Indicates whether this threshold is active.
~BboThreshold()=default
Finalizes the threshold settings.
BboThreshold(const BboThreshold &other)
Copies threshold settings from another instance.
const SettingGroup & group() const
friend class DirectBboTracking
Lets grouping and value assignment control functioning.
BboThreshold & operator=(const BboThreshold &other)
Copies threshold settings from another instance.
friend class ImpliedBboTracking
Lets grouping and value assignment control functioning.
void assignNoControl(const BboThreshold &other)
friend class MboBboTracking
Lets grouping and value assignment control functioning.
BboThreshold & threshold(const Messaging::Decimal &value)
Updates the relative threshold for the tracked attribute.
BboThreshold(const SettingGroup *group=nullptr)
Initializes disabled tracking for a BBO attribute.
const Messaging::Decimal & threshold() const noexcept
Returns the relative threshold for the tracked attribute.
BboThreshold & enabled(bool value)
Enables or disables this threshold.
Aggregates all book management settings used by the Handler.
BookManagement & updateNotification(BookUpdateNotification::Enum value)
Sets the policy used to raise book update callbacks.
const ConsolidatedBookManagement & consolidatedBooks() const noexcept
Returns read-only management settings for consolidated books.
const DirectBookManagement & directBooks() const noexcept
Returns read-only management settings for direct books.
BookUpdateNotification::Enum updateNotification() const noexcept
Returns the policy used to raise book update callbacks.
DirectBookManagement & directBooks() noexcept
Returns mutable management settings for direct books.
BookManagement(const BookManagement &other)
Copies book management settings from another instance.
ImpliedBookManagement & impliedBooks() noexcept
Returns mutable management settings for implied books.
const ImpliedBookManagement & impliedBooks() const noexcept
Returns read-only management settings for implied books.
~BookManagement()=default
Finalizes the book management settings.
ConsolidatedBookManagement & consolidatedBooks() noexcept
Returns mutable management settings for consolidated books.
BookManagement(SettingChangeController *controller=nullptr)
Initializes book management settings with defaults.
const MboBookManagement & mboBooks() const noexcept
Returns read-only management settings for MBO books.
MboBookManagement & mboBooks() noexcept
Returns mutable management settings for MBO books.
BookManagement & operator=(const BookManagement &other)
Copies book management settings from another instance.
Configures BBO threshold tracking for direct books.
bool enabled() const noexcept
Indicates whether any direct-book BBO threshold is enabled.
const BboThreshold & numberOfOrders() const noexcept
Returns read-only order-count tracking settings.
void assignNoControl(const DirectBboTracking &other)
~DirectBboTracking()=default
Finalizes the tracking settings.
DirectBboTracking(const DirectBboTracking &other)
Copies direct-book BBO tracking settings from another instance.
bool exceeded(const DirectPriceLevel &previous, const DirectPriceLevel &current) const
Checks whether the configured direct-book thresholds are exceeded.
DirectBboTracking(const SettingGroup *group=nullptr)
Initializes disabled direct-book BBO tracking.
DirectBboTracking & operator=(const DirectBboTracking &other)
Copies direct-book BBO tracking settings from another instance.
BboThreshold & numberOfOrders() noexcept
Returns mutable order-count tracking settings.
Represents one direct book price level.
Messaging::Int32 & numberOfOrders() noexcept
Provides mutable access to the number of orders at the level.
Configures book management for a fixed-depth book type.
~FixedDepthBookManagement()=default
Finalizes the fixed-depth book-management settings.
FixedDepthBookManagement(const SettingGroup *group=nullptr, Depth defaultDepth=0)
Initializes fixed-depth book management settings.
FixedDepthBookManagement(const FixedDepthBookManagement &other)
Copies fixed-depth book-management settings from another instance.
FixedDepthBookManagement & defaultDepth(Depth value)
Sets the fallback depth for fixed-depth books.
FixedDepthBookManagement & operator=(const FixedDepthBookManagement &other)
Copies fixed-depth book-management settings from another instance.
Configures BBO threshold tracking for implied books.
ImpliedBboTracking(const ImpliedBboTracking &other)
Copies implied-book BBO tracking settings from another instance.
friend class BaseBookManagement
Lets grouping and value assignment control functioning.
void assignNoControl(const ImpliedBboTracking &other)
bool enabled() const noexcept
Indicates whether any implied-book BBO threshold is enabled.
const BboThreshold & price() const noexcept
Returns read-only price tracking settings.
const SettingGroup & group() const
const BboThreshold & quantity() const noexcept
Returns read-only quantity tracking settings.
bool exceeded(const ImpliedPriceLevel &previous, const ImpliedPriceLevel &current) const
Checks whether the configured implied-book thresholds are exceeded.
BboThreshold & price() noexcept
Returns mutable price tracking settings.
~ImpliedBboTracking()=default
Finalizes the tracking settings.
BboThreshold & quantity() noexcept
Returns mutable quantity tracking settings.
ImpliedBboTracking(const SettingGroup *group=nullptr)
Initializes disabled implied-book BBO tracking.
ImpliedBboTracking & operator=(const ImpliedBboTracking &other)
Copies implied-book BBO tracking settings from another instance.
Represents one implied book price level.
constexpr MbpBookQuantity quantity() const noexcept
Gets the aggregate quantity at the price level.
constexpr const Messaging::Decimal & price() const noexcept
Gets the price value.
Configures BBO threshold tracking for MBO books.
friend class BaseBookManagement
Lets grouping and value assignment control functioning.
bool enabled() const noexcept
Indicates whether any MBO BBO threshold is enabled.
const BboThreshold & price() const noexcept
Returns read-only price tracking settings.
void assignNoControl(const MboBboTracking &other)
MboBboTracking & operator=(const MboBboTracking &other)
Copies MBO BBO tracking settings from another instance.
const SettingGroup & group() const
MboBboTracking(const SettingGroup *group=nullptr)
Initializes disabled MBO BBO tracking.
BboThreshold & price() noexcept
Returns mutable price tracking settings.
bool exceeded(const Order &previous, const Order &current) const
Checks whether the configured MBO thresholds are exceeded.
~MboBboTracking()=default
Finalizes the tracking settings.
MboBboTracking(const MboBboTracking &other)
Copies MBO BBO tracking settings from another instance.
Represents an order in a Market By Order (MBO) book.
Definition Order.h:92
constexpr const Messaging::Decimal & price() const noexcept
Gets the order price.
Definition Order.h:143
Associates setting mutations with a change controller.
SettingGroup(SettingChangeController *controller=nullptr)
Creates a setting group that uses the specified controller.
void controlChange(const Messaging::Char *description, void(Changeable::*change)(), Changeable &changeable) const
Invokes a zero-argument member function as a guarded change.
void controlAssignment(const Messaging::Char *description, Assignee &assignee, Value value) const
Assigns a value while coordinating the change with the controller.
std::uint32_t UInt32
uInt32.
Definition Integral.h:35
FloatingPointDecimal< DecimalMantissa, DecimalExponent > Decimal
Universal decimal type.
FixedDepthBookManagement< ImpliedBboTracking, MbpBookDepth > ImpliedBookManagement
Management and tracking settings for implied books.
BaseBookManagement< ImpliedBboTracking > ConsolidatedBookManagement
Management and tracking settings for consolidated books.
FixedDepthBookManagement< DirectBboTracking, MbpBookDepth > DirectBookManagement
Management and tracking settings for direct books.
bool thresholdExceeded(const Messaging::Decimal &threshold, const Messaging::Decimal &previous, const Messaging::Decimal &current)
Checks whether a decimal value change exceeds a relative threshold.
AnyDepthBookManagement< MboBboTracking, SortedOrders::size_type > MboBookManagement
Management and tracking settings for MBO books.
void throwBadBboThreshold()
Throws the exception used for invalid BBO threshold values.
void toStr(std::string &str, BookState::Enum bookState)
Appends a string representation of a book state.
Defines when incremental book update callbacks are raised.
Enum
Available book update notification policies.
@ OnEndOfEvent
Raises book update callbacks at the end of a market event.
@ OnSecurityChange
Raises book update callbacks when the processed security changes.
Messaging::UInt32 Base
Integral type used to store notification values.
Coordinates changes to settings that belong to a setting group.