OnixS C++ CME Market Data Handler  4.8.0.10
API documentation
Pages/SelectingSecuritiesOfInterest.md
Go to the documentation of this file.
1 \addtogroup security-selection
2 
3 \brief Provides information on how to make Handler raise
4 security-related events for particular securities only.
5 
6 \section define-security-selection Defining Securities of Interest
7 
8 By default, the Handler processes market data for all securities available
9 in a particular market data channel. For certain channels, it may be a huge
10 amount of data which may cause the Handler to allocate a significant amount
11 of system resources (like a memory). From the other side, it often happens
12 that not all securities are the point of interest. For these reasons, the
13 Handler provides an ability to define a subset of securities for which it
14 monitors market data, maintains books and report about other market-related
15 events. The Handler fires no events for any security not present in the
16 defined subset. This feature is called *selecting securities or security
17 filtering*.
18 
19 Selecting securities is similar to the process of filling a bag with
20 apples. The OnixS::CME::MDH::InstrumentSelection class must be used to
21 gather securities into a collection for which the Handler must process
22 market data. There're no limits on the quantity of securities which can
23 be included into the selection.
24 
25 If at least one security is added to the filter, the Handler stops
26 raising events for all securities available in the market data channel.
27 Since that moment the Handler fires events only for securities included
28 in filtering.
29 
30 Securities can be filtered using security id, security group,
31 symbol, and asset attributes. For each of these attributes, the
32 OnixS::CME::MDH::InstrumentSelection class exposes the corresponding
33 member returning a collection of attribute values which can be
34 manipulated as the regular std::set.
35 
36 An empty (blank) security selection causes the Handler to process
37 market data and to trigger events for all securities on the channel.
38 
39 \note Selecting securities affects the OnixS::CME::MDH::SecurityListener
40 listener only. The Handler does not invoke listener members for securities
41 out of the selection scope. Other listeners are not affected by this feature.
42 
43 \warning **Filtering must be manipulated only when the
44 Handler is not processing market data or in bounds of the
45 OnixS::CME::MDH::HandlerListener::onEndOfInstrumentRecovery
46 callback with a successful recovery status. Once the Handler
47 begins market data processing or moves out of the noted callback
48 scope, security selection must not be modified.**
49 
50 \section security-filter-example Example
51 
52 The following code demonstrates how to instruct the Handler
53 to process data only for securities selected by the user:
54 
55 ~~~{.cpp}
56 
57 using namespace OnixS::CME::MDH;
58 
59 class
60 InteractiveSecuritySelector
61 : public SecurityListener
62 , public HandlerListener
63 {
64  InstrumentSelection selection_;
65 
66  template
67  <
68  class Definition
69  >
70  bool
71  userSelectedSecurity(
72  const Definition& definition)
73  {
74  // Given member asks user whether user wants
75  // to have market data for given instrument.
76  // Returned value indicates whether user
77  // selected instrument.
78 
79  return true;
80  }
81 
82 public:
83  InteractiveSecuritySelector()
84  {
85  }
86 
87  void
88  onDefinition(
89  Handler&,
90  const Security& security,
91  const InstrumentDefinitionFutureArgs& args)
92  {
93  if (userSelectedSecurity(args.message())
94  selection_.securityIds().insert(security.id());
95  }
96 
97  void
98  onDefinition(
99  Handler&,
100  const Security& security,
101  const InstrumentDefinitionSpreadArgs& args)
102  {
103  if (userSelectedSecurity(args.message())
104  selection_.securityIds().insert(security.id());
105  }
106 
107  void
108  onDefinition(
109  Handler&,
110  const Security& security,
111  const InstrumentDefinitionOptionArgs& args)
112  {
113  if (userSelectedSecurity(args.message())
114  selection_.securityIds().insert(security.id());
115  }
116 
117  void
118  onEndOfInstrumentRecovery(
119  Handler& handler,
120  const RecoveryCompletionArgs& args)
121  {
122  if (args.status() ==
123  RecoveryCompletionStatus::Succeeded)
124  {
125  handler.selectInstruments(selection_);
126  }
127  }
128 };
129 
130 Handler handler(settings);
131 
132 InteractiveSecuritySelector selector;
133 
134 handler.registerSecurityListener(selector);
135 handler.registerListener(selector);
136 
137 handler.start();
138 
139 ~~~