OnixS C++ CME MDP Premium Market Data Handler  5.8.3
API Documentation
Selecting securities of interest

Selecting securities of interest

By default, the handler processes market data for all securities in a particular market data channel. A considerable amount of data may cause the handler to allocate many system resources (like memory) for specific channels. On the other side, it often happens that not all securities are the point of interest. The handler provides an ability to define a subset of securities for which it monitors market data, maintains books and report about other market-related events. The handler fires no events for any security does not present in the defined subset. This feature is called selecting securities or security filtering.

The OnixS::CME::MDH::InstrumentSelection class must be used to gather securities for which the Handler must process market data.

If at least one security is added to the filter, the Handler stops raising events for all securities in the market data channel. Since that moment, the Handler fires events only for selected securities.

Securities can be filtered using security id, security group, symbol, and asset. For each attribute, the OnixS::CME::MDH::InstrumentSelection class exposes the corresponding member returning a collection of attribute values which can be manipulated as a regular std::set.

An empty (blank) security selection causes the Handler to process market data and trigger events for all securities on the channel.

Note
Selecting securities affects the OnixS::CME::MDH::SecurityListener listener only. Other listeners are not affected by this feature.
Warning
Filtering must be manipulated only when the Handler is not processing market data and within the bounds of the OnixS::CME::MDH::HandlerListener::onEndOfInstrumentRecovery callback with a successful recovery status. Once the Handler begins market data processing or moves out of the noted callback scope, security selection must not be modified.

Example

The following code demonstrates how to instruct the Handler to process data only for selected securities:

class MySecuritySelector
: public SecurityListener
, public HandlerListener
{
public:
void onDefinition(Handler&, const Security& security, const InstrumentDefinitionFutureArgs& args) override
{
if (userSelectedSecurity(args.message()))
selection_.securityIds().insert(security.id());
}
void onDefinition(Handler&, const Security& security, const InstrumentDefinitionSpreadArgs& args) override
{
if (userSelectedSecurity(args.message()))
selection_.securityIds().insert(security.id());
}
void onDefinition(Handler&, const Security& security, const InstrumentDefinitionOptionArgs& args) override
{
if (userSelectedSecurity(args.message()))
selection_.securityIds().insert(security.id());
}
void onEndOfInstrumentRecovery(Handler& handler, const RecoveryCompletionArgs& args) override
{
if (RecoveryCompletionStatus::Succeeded == args.status())
handler.selectInstruments(selection_);
}
private:
InstrumentSelection selection_;
};
Handler handler;
MySecuritySelector selector;
handler.settings().listeners().security(&selector).handler(&selector);
handler.start();