OnixS C++ CME MDP Conflated UDP Handler  1.1.2
API documentation
SessionSettings.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 
27 
29 
30 /// Defines type of recovery to be done
31 /// by Handler at the time it joins market.
34 {
35  /// Integral type serving as
36  /// basement for given enumeration.
37  typedef UInt32 Base;
38 
39  /// Defines type of recovery to be done
40  /// by Handler while it joins market.
41  enum Enum
42  {
43  /// No recovery is to be done at join time.
44  /// Handler will switch to real-time data
45  /// processing immediately.
47 
48  /// Instructs Handler to recover instruments before
49  /// switching to real-time (incremental data) processing.
51 
52  /// Instructs Handler to perform full recovery (both instruments
53  /// and market state (books, last trades, statistics, etc))
54  /// before switching to real-time (incremental) data processing.
55  InstrumentsAndMarketState
56  };
57 };
58 
59 /// Serializes join recovery option.
60 ONIXS_CONFLATEDUDP_EXPORTED
61 void
62 toStr(
63  std::string&,
65 
66 /// Serializes join recovery option.
67 inline
68 std::string
71 {
72  std::string str;
73 
74  toStr(str, recovery);
75 
76  return str;
77 }
78 
79 /// Defines the way Handler has to handle
80 /// gap in real-time (incremental) data.
83 {
84  /// Integral type serving as
85  /// basement for given enumeration.
86  typedef UInt32 Base;
87 
88  /// Defines the way Handler has to handle
89  /// gap in real-time (incremental) data.
90  enum Enum
91  {
92  /// Handler recovers market state from snapshots.
94 
95  /// Handler recovers instruments and market state afterwards.
97 
98  /// Handler continues processing of real-time market data.
99  ContinueProcessing
100  };
101 };
102 
103 /// Serializes gap and error handling option.
104 ONIXS_CONFLATEDUDP_EXPORTED
105 void
106 toStr(
107  std::string&,
109 
110 /// Serializes gap and error handling option.
111 inline
112 std::string
115 {
116  std::string str;
117 
118  toStr(str, handling);
119 
120  return str;
121 }
122 
123 /// Defines different ways of instrument definition recovery.
126 {
127  /// Integral type used as basement for constants.
128  typedef UInt32 Base;
129 
130  enum Enum
131  {
132  /// The given strategy tells the Handler to recover instruments
133  /// in the most accurate way. In particular, the Handler processes
134  /// instrument definitions from the beginning of a recovery loop.
135  /// If the Handler joins instrument recovery feed in the middle
136  /// of a recovery loop, incoming data is ignored until a new loop
137  /// begins. Also, if the Handler detects gap in a sequence of
138  /// incoming packets, it will stop processing instrument definitions
139  /// till the end of a loop and restart the recovery from the beginning
140  /// of a new loop.
141  /// The given way to recover instruments is highly recommended for
142  /// the channels, where user-defined instruments are frequently added
143  /// or removed during the trading week.
144  /// Accurate recovery may take longer due to necessity to wait for
145  /// the beginning of a new loop caused by join at the middle of a
146  /// prior loop or data loss.
148 
149  /// The fast mode allows to start processing instrument definitions
150  /// from the middle of a recovery loop without waiting for the beginning
151  /// of the next loop. In case of data loss, missing definitions are
152  /// recovered from the next loops. The given approach allows to recover
153  /// quickly. However, the recovered set of instruments may not be accurate
154  /// because of differences in the recovery loops from where the recovery
155  /// data was taken.
156  Fast
157  };
158 };
159 
160 /// Serializes instrument definition recovery strategy.
161 ONIXS_CONFLATEDUDP_EXPORTED
162 void
163 toStr(
164  std::string&,
166 
167 /// Serializes instrument definition recovery strategy.
168 inline
169 std::string
172 {
173  std::string str;
174 
175  toStr(str, option);
176 
177  return str;
178 }
179 
181 (
183 );
184 
185 /// Collection of session settings related to TCP recovery.
188 {
189  /// Lets grouping and value assignment control functioning.
190  friend
192  (
194  );
195 
196  //
197 
198  const SettingGroup& group_;
199 
200  TcpRecoveryService* service_;
201 
202  UInt32 attempts_;
203  UInt32 servingTimeLimit_;
204 
205  // Re-initializes the instance as a copy of the
206  // other one and bypassing assignment control.
207  void
208  assignNoControl(
209  const
211  {
212  service_ =
213  other.service_;
214 
215  attempts_ =
216  other.attempts_;
217 
218  servingTimeLimit_ =
219  other.servingTimeLimit_;
220  }
221 
222 public:
223  /// Initializes the instance with the default values.
224  ///
225  /// Optional group parameter lets to make the
226  /// instance belonging to a given group of settings.
228  const SettingGroup* group = NULL)
229  : group_(
230  group
231  ? *group
232  : SettingGroup::null())
233  , service_(NULL)
234  , attempts_(1)
235  , servingTimeLimit_(10)
236  {
237  }
238 
239  /// Initializes the instance as a copy
240  /// of the other one. Grouping and value
241  /// assignment control services are not
242  /// copied.
244  const TcpRecoverySessionSettings& other)
245  : group_(SettingGroup::null())
246  , service_(other.service_)
247  , attempts_(other.attempts_)
248  , servingTimeLimit_(
249  other.servingTimeLimit_)
250  {
251  }
252 
253  /// Finalizes the instance.
255  {
256  }
257 
258  /// An instance of the TCP recovery
259  /// service if there's any associated.
260  ///
261  /// Null instance indicates no service is
262  /// associated and thus TCP recovery is disabled
263  /// during market data processing session.
265  service() const
266  {
267  return service_;
268  }
269 
270  /// Associates the instance of the TCP Recovery
271  /// service to be used by a Handler during market
272  /// data processing session.
273  void
274  service(
275  TcpRecoveryService* service)
276  {
277  group_.
278  controlAssignment
279  (
280  "TCP Recovery Service Instance",
281  service_,
282  service
283  );
284  }
285 
286  /// Number of times a Handler must try to recover
287  /// missing data using the TCP recovery before it
288  /// switches to recover market state from snapshots
289  /// or resumes incremental data processing by natural
290  /// refresh.
291  UInt32
292  attempts() const
293  {
294  return attempts_;
295  }
296 
297  /// Updates number of times a Handler must try
298  /// to recover missing data using the TCP recovery
299  /// before it switches to recover market state from
300  /// snapshots or resumes incremental data processing
301  /// by natural refresh.
302  void
303  attempts(
304  UInt32 qty)
305  {
306  group_.
307  controlAssignment
308  (
309  "TCP Recovery Attempt Quantity",
310  attempts_,
311  qty
312  );
313  }
314 
315  /// Amount of time allocated to process a
316  /// recovery request. TCP recovery service
317  /// interrupts request processing if it can't
318  /// be accomplished within given time frame.
319  ///
320  /// Interval is measured in seconds.
321  ///
322  /// @note Default value is '10'.
323  UInt32
324  servingTimeLimit() const
325  {
326  return servingTimeLimit_;
327  }
328 
329  /// Amount of time allocated to process a
330  /// recovery request. TCP recovery service
331  /// interrupts request processing if it can't
332  /// be accomplished within given time frame.
333  ///
334  /// Interval is measured in seconds.
335  void
336  servingTimeLimit(
337  UInt32 servingTimeLimit)
338  {
339  group_.
340  controlAssignment
341  (
342  "TCP Recovery Serving Time Limit",
343  servingTimeLimit_,
344  servingTimeLimit
345  );
346  }
348  /// Re-initializes as a copy of the other one. Grouping
349  /// and value assignment control services aren't copied.
351  operator =(
352  const
354  {
355  group_.
356  controlAssignment
357  (
358  "TCP Recovery Session Settings",
359  &TcpRecoverySessionSettings::assignNoControl,
360  *this,
361  other
362  );
363 
364  return *this;
365  }
366 };
367 
368 /// Serializes market recovery option.
369 ONIXS_CONFLATEDUDP_EXPORTED
370 void
371 toStr(
372  std::string&,
373  const
375 
376 /// Serializes market recovery option.
377 inline
378 std::string
380  const
381  TcpRecoverySessionSettings& settings)
382 {
383  std::string str;
384 
385  toStr(str, settings);
386 
387  return str;
388 }
389 
390 /// Basic set of parameters affecting behavior of the
391 /// Handler when the market data processing is performed.
392 ///
393 /// @note The given class exists to provide backward compatibility
394 /// with the previous releases. Use 'AdvancedSessionSettings' instead.
396 {
397  JoinRecoveryOptions::Enum joinRecovery_;
398  GapAndErrorHandlingOptions::Enum gapAndErrorHandling_;
399 
400  InstrumentRecoveryOptions::Enum instrumentRecovery_;
401 
402 protected:
403  /// Instance of the group to which
404  /// the given settings belongs.
405  const
406  SettingGroup&
407  group() const
408  {
409  return *this;
410  }
411 
412  /// Re-initializes the instance as a copy of the
413  /// other one and bypassing assignment control.
414  void
416  const SessionSettings& other)
417  {
418  joinRecovery_ =
419  other.joinRecovery_;
420 
421  gapAndErrorHandling_ =
422  other.gapAndErrorHandling_;
423 
424  instrumentRecovery_ =
425  other.instrumentRecovery_;
426  }
427 
428 public:
429  /// Initializes parameters with default values.
432  controller = NULL)
433  : SettingGroup(controller)
434  , joinRecovery_(
436  InstrumentsAndMarketState)
437  , gapAndErrorHandling_(
439  RecoverMarketState)
440  , instrumentRecovery_(
442  Accurate)
443  {
444  }
445 
446  /// Re-initializes settings as copies of
447  /// the other ones omitting group belonging.
449  const SessionSettings& other)
450  : SettingGroup()
451  , joinRecovery_(
452  other.joinRecovery_)
453  , gapAndErrorHandling_(
454  other.gapAndErrorHandling_)
455  , instrumentRecovery_(
456  other.instrumentRecovery_)
457  {
458  }
459 
460  /// Cleans everything up.
462  {
463  }
464 
465  /// Defines aspects of recovery
466  /// to be done at market join stage.
467  ///
468  /// @note Default value is
469  /// JoinRecovery::InstrumentsAndMarket.
471  joinRecovery() const
472  {
473  return joinRecovery_;
474  }
475 
476  /// Defines aspects of recovery
477  /// to be done at market join stage.
478  void
480  JoinRecoveryOptions::Enum recovery)
481  {
482  group().
483  controlAssignment
484  (
485  "Join Recovery Strategy",
486  joinRecovery_,
487  recovery
488  );
489  }
490 
491  /// Defines what Handler should do in case
492  /// of gap in real-time (incremental) data.
493  ///
494  /// @note Default value is
495  /// GapAndErrorHandling::RecoverMarketState.
498  {
499  return gapAndErrorHandling_;
500  }
501 
502  /// Defines what Handler should do in case
503  /// of gap in real-time (incremental) data.
504  void
507  {
508  group().
509  controlAssignment
510  (
511  "Gap And Error Handling Strategy",
512  gapAndErrorHandling_,
513  handling
514  );
515  }
516 
517  /// Indicates how instrument definitions are recovered.
518  ///
519  /// @note Default value is InstrumentRecoveryOptions::Accurate.
522  {
523  return instrumentRecovery_;
524  }
525 
526  /// Defines how instrument definitions are recovered.
527  void
530  {
531  group().
532  controlAssignment
533  (
534  "Instrument Recovery Strategy",
535  instrumentRecovery_,
536  recovery
537  );
538  }
539 
540  /// Copies settings from the given instance.
541  ///
542  /// Attributes controlling value assignment aren't
543  /// cloned and thus only settings' values are copied.
545  operator =(
546  const SessionSettings& other)
547  {
548  group().
549  controlAssignment
550  (
551  "Session Settings",
552  &SessionSettings::assignNoControl,
553  *this,
554  other
555  );
556 
557  return *this;
558  }
559 };
560 
561 /// Serializes market data processing session settings.
562 ONIXS_CONFLATEDUDP_EXPORTED
563 void
564 toStr(
565  std::string&,
566  const SessionSettings&);
567 
568 /// Serializes market data processing session settings.
569 inline
570 std::string
572  const SessionSettings& settings)
573 {
574  std::string str;
575 
576  toStr(str, settings);
577 
578  return str;
579 }
580 
581 /// Full set of parameters affecting behavior
582 /// of the Handler when market data is processed.
585  : public SessionSettings
586 {
587  // Lets grouping and value assignment control functioning.
589 
590  TcpRecoverySessionSettings tcpRecovery_;
591 
592  // Re-initializes the instance as a copy of the
593  // other one and bypassing assignment control.
594  void
595  assignNoControl(
596  const AdvancedSessionSettings& other)
597  {
598  SessionSettings::assignNoControl(other);
599 
600  tcpRecovery_.assignNoControl(other.tcpRecovery_);
601  }
602 
603 public:
604  /// Initializes parameters with default values.
607  controller = NULL)
608  : SessionSettings(controller)
609  , tcpRecovery_(&group())
610  {
611  }
612 
613  /// Re-initializes settings as copies of
614  /// the other ones omitting group belonging.
616  const AdvancedSessionSettings& other)
617  : SessionSettings(
618  static_cast
619  <const SessionSettings&>
620  (other))
621  , tcpRecovery_(
622  other.tcpRecovery_)
623  {
624  }
625 
626  /// Cleans everything up.
628  {
629  }
630 
631  /// Set of TCP recovery settings.
632  const
634  tcpRecovery() const
635  {
636  return tcpRecovery_;
637  }
638 
639  /// Editable set of TCP recovery settings.
642  {
643  return tcpRecovery_;
644  }
645 
646  /// Copies settings from the given instance.
647  ///
648  /// Attributes controlling value assignment aren't
649  /// cloned and thus only settings' values are copied.
651  operator =(
652  const AdvancedSessionSettings& other)
653  {
654  group().
655  controlAssignment
656  (
657  "Advanced Session Settings",
658  &AdvancedSessionSettings::assignNoControl,
659  *this,
660  other
661  );
662 
663  return *this;
664  }
665 };
666 
667 /// Serializes market data processing session settings.
668 ONIXS_CONFLATEDUDP_EXPORTED
669 void
670 toStr(
671  std::string&,
672  const AdvancedSessionSettings&);
673 
674 /// Serializes market data processing session settings.
675 inline
676 std::string
678  const
679  AdvancedSessionSettings& settings)
680 {
681  std::string str;
682 
683  toStr(str, settings);
684 
685  return str;
686 }
687 
688 // Various functions helping in configuring session in the desired way.
689 
690 /// Updates session settings to tell the Handler
691 /// to recover instruments using accurate strategy
692 /// each time instrument recovery is performed.
693 inline
694 void
696 (
697  SessionSettings& settings
698 )
699 {
700  settings.
701  instrumentRecovery(
703  Accurate);
704 }
705 
706 /// Updates session settings to tell the Handler
707 /// to recover instruments using fast strategy each
708 /// time instrument recovery is performed.
709 inline
710 void
712 (
713  SessionSettings& settings
714 )
715 {
716  settings.
717  instrumentRecovery(
719  Fast);
720 }
721 
722 /// Updates session settings to tell the Handler
723 /// to skip join-time recovery and switch processing
724 /// incremental (real-time) data.
725 inline
726 void
728 (
729  SessionSettings& settings
730 )
731 {
732  settings.
733  joinRecovery(
735  Disabled);
736 }
737 
738 /// Updates session settings to tell the Handler
739 /// to recover instruments and market state before
740 /// it switches processing incremental data.
741 inline
742 void
744  SessionSettings& settings)
745 {
746  settings.
747  joinRecovery(
749  InstrumentsAndMarketState);
750 }
751 
752 /// Updates session settings to tell the
753 /// Handler to recover instruments and market
754 /// state (books) in case of gap or other issue.
755 inline
756 void
758 (
759  SessionSettings& settings
760 )
761 {
762  settings.
763  gapAndErrorHandling(
765  RecoverInstrumentsAndMarketState);
766 }
767 
768 /// Updates session settings to tell the
769 /// Handler to recover market state (books)
770 /// in case of gap or other issue.
771 inline
772 void
774 (
775  SessionSettings& settings
776 )
777 {
778  settings.
779  gapAndErrorHandling(
781  RecoverMarketState);
782 }
783 
784 /// Updates session settings to tell the Handler
785 /// continue processing incremental (real-time)
786 /// data in case of gap or other issue.
787 inline
788 void
790 (
791  SessionSettings& settings
792 )
793 {
794  settings.
795  gapAndErrorHandling(
797  ContinueProcessing);
798 }
799 
800 // Complex (one-call) setup.
801 
802 /// Configures session to maintain order books
803 /// accurately and without performing initial
804 /// (late-join) recovery thus considering market
805 /// data processing is started from the beginning
806 /// of weekly session.
807 inline
808 void
810 (
811  SessionSettings& settings
812 )
813 {
815  (
816  settings
817  );
819  (
820  settings
821  );
823  (
824  settings
825  );
826 }
827 
828 /// Configures session to maintain order
829 /// books accurately and considering market
830 /// data processing is started at the middle
831 /// of weekly session (late join).
832 inline
833 void
835 (
836  SessionSettings& settings
837 )
838 {
840  (
841  settings
842  );
844  (
845  settings
846  );
848  (
849  settings
850  );
851 }
852 
853 /// Configures session settings to maintain
854 /// order books using natural refresh. Startup
855 /// recovery is not performed and thus only
856 /// real-time processing takes place.
857 inline
858 void
860  SessionSettings& settings)
861 {
863  (
864  settings
865  );
867  (
868  settings
869  );
870 }
871 
872 // Deprecated way of session setup.
873 
874 #if !defined (ONIXS_CONFLATEDUDP_NO_DEPRECATED)
875 
876 /// Settings for session with accurate book
877 /// maintenance and considering market data
878 /// processing is started from the beginning
879 /// of weekly session.
883 {
884  /// Configures session settings
885  /// according to specialization.
887  {
889  }
890 };
891 
892 /// Settings for session with accurate book
893 /// maintenance and considering market data
894 /// processing is started at the middle of
895 /// weekly session (late join).
899 {
900  /// Configures session settings
901  /// according to specialization.
903  : SessionSettings()
904  {
906  }
907 };
908 
909 /// Configures session settings to maintain
910 /// order books using natural refresh. Startup
911 /// recovery is not performed and thus only
912 /// real-time processing takes place.
916 {
917  /// Configures session settings
918  /// according to specialization.
920  : SessionSettings()
921  {
923  }
924 };
925 
926 #endif // ONIXS_CONFLATEDUDP_NO_DEPRECATED
927 
AdvancedSessionSettings(SettingAssignController *controller=NULL)
Initializes parameters with default values.
JoinRecoveryOptions::Enum joinRecovery() const
void setSessionToRecoverBooksUponRealtimeIssues(SessionSettings &settings)
GapAndErrorHandlingOptions::Enum gapAndErrorHandling() const
const TcpRecoverySessionSettings & tcpRecovery() const
Set of TCP recovery settings.
Handler&#39;s configuration settings.
void instrumentRecovery(InstrumentRecoveryOptions::Enum recovery)
Defines how instrument definitions are recovered.
void setSessionToAccurateLateJoin(SessionSettings &settings)
const SettingGroup & group() const
UInt32 UInt32
uInt32.
Definition: Fields.h:261
void setSessionToRecoverInstrumentsFast(SessionSettings &settings)
#define ONIXS_CONFLATEDUDP_LTWT_CLASS_DECL(name)
Definition: Bootstrap.h:107
void setSessionToLateJoin(SessionSettings &settings)
Defines different ways of instrument definition recovery.
#define ONIXS_CONFLATEDUDP_EXPORTED_CLASS_DECL(typeName)
Definition: Bootstrap.h:47
TcpRecoverySessionSettings & tcpRecovery()
Editable set of TCP recovery settings.
#define ONIXS_CONFLATEDUDP_LTWT_STRUCT
Definition: Bootstrap.h:99
void assignNoControl(const SessionSettings &other)
InstrumentRecoveryOptions::Enum instrumentRecovery() const
void gapAndErrorHandling(GapAndErrorHandlingOptions::Enum handling)
void setSessionToJoinInPreopening(SessionSettings &settings)
Base services for settings grouped by a certain criteria.
Definition: SettingGroup.h:123
#define ONIXS_CONFLATEDUDP_NAMESPACE_END
Definition: Bootstrap.h:157
UInt32 Base
Integral type used as basement for constants.
void joinRecovery(JoinRecoveryOptions::Enum recovery)
AdvancedSessionSettings(const AdvancedSessionSettings &other)
void setSessionToContinueRealtimeProcessingUponIssues(SessionSettings &settings)
SessionSettings(SettingAssignController *controller=NULL)
Initializes parameters with default values.
std::string toStr(const AdvancedSessionSettings &settings)
Serializes market data processing session settings.
#define ONIXS_CONFLATEDUDP_LTWT_CLASS
Definition: Bootstrap.h:95
void setSessionToFullRecoverUponRealtimeIssues(SessionSettings &settings)
SessionSettings(const SessionSettings &other)
#define ONIXS_CONFLATEDUDP_NAMESPACE_BEGIN
Definition: Bootstrap.h:153
void setSessionToAccuratePreopening(SessionSettings &settings)
void setSessionToRecoverInstrumentsAccurately(SessionSettings &settings)
Collection of session settings related to TCP recovery.
void setSessionToNaturalRefresh(SessionSettings &settings)