OnixS C++ CME MDP Premium Market Data Handler  5.8.3
API Documentation
Setting up Feed Engine

The Feed Engine abstractions encapsulate data receiving aspects to let the handler focus on market data processing. It also provides advanced services for using system resources to achieve the best performance and latency characteristics.

Using the Feed Engine

The Feed Engine logic pushes received market data to the linked Handler instances.

The OnixS::CME::MDH::SocketFeedEngine is the default implementation of the Feed Engine for receiving live network data. It uses standard socket API.

The following code sample shows how to construct an instance of the Feed Engine, link it with the handler instance, and run the Feed Engine logic to let the handler process incoming market data and other events.

SocketFeedEngine dataProvider;
Handler handler;
// Selects the CME MDP channel and specifies the configuration file's location.
handler.settings().channel(310).connectivityConfigurationFile("config.xml");
// Binds the Handler to the Feed Engine.
handler.settings().feeds().engine(&dataProvider);
// Configures the processing session.
setSessionToAccurateLateJoin(handler.settings().session());
// Moves the Handler to the processing state.
handler.start();
// Runs the Feed Engine logic to receive live market data
// from the network and to push it to the Handler.
while (!userRequestedToEndLooping())
dataProvider.process();
// Stops the Handler.
handler.stop();
See also
Solarflare Feed Engine

Sharing the Feed Engine between multiple handlers

Multiple Handler instances can share a single instance of the Feed Engine:

void configure(HandlerSettings& settings, ChannelId channel, NetFeedEngine& dataProvider)
{
// Selects the CME MDP channel and specifies the configuration file's location
settings.channel(channel).connectivityConfigurationFile("config.xml").feeds().engine(&dataProvider);
setSessionToAccurateLateJoin(settings.session());
}
void runHandlers()
{
// Initializes the Feed Engine.
SocketFeedEngineSettings feedEngineSettings;
SocketFeedEngine dataProvider(feedEngineSettings);
// Initializes the Handlers.
Handler handlerForChannel310;
Handler handlerForChannel312;
// Configures Handlers.
configure(handlerForChannel310.settings(), 310, dataProvider);
configure(handlerForChannel312.settings(), 312, dataProvider);
// Moves the Handler to the processing state.
handlerForChannel310.start();
handlerForChannel312.start();
// Runs the Feed Engine logic to receive live market data
// from the network and to push it to handlers.
while (!userRequestedToEndLooping())
dataProvider.process();
// Stops the Handler.
handlerForChannel310.stop();
handlerForChannel312.stop();
}

Multi-threaded processing

If the Feed Engine implementation supports multithreaded processing, it is possible to distribute the Feed Engine logic across multiple threads instead of calling OnixS::CME::MDH::NetFeedEngine::process() from one thread only.

The SDK offers the OnixS::CME::MDH::FeedEngineThreadPool service that cyclically invokes the OnixS::CME::MDH::NetFeedEngine::process method of the associated OnixS::CME::MDH::NetFeedEngine instance from a set of threads. This service manages a thread pool. When a class instance is created, it creates working threads. The number of threads is defined by the OnixS::CME::MDH::ThreadPoolSettings::size parameter, which can be accessed via the OnixS::CME::MDH::FeedEngineThreadSettings::pool member. Each thread cyclically calls the OnixS::CME::MDH::NetFeedEngine::process member for the instance of the OnixS::CME::MDH::NetFeedEngine class given to the service instance at construction time.

All events exposed by the service are encapsulated into the OnixS::CME::MDH::FeedEngineThreadPoolListener class. Subscribing to events is done during the service construction.

class ThreadListener : public FeedEngineThreadPoolListener
{
public:
void onFeedEngineThreadIssue(const FeedEngineThreadPool&, const Char* issue) override
{
std::clog << issue << std::endl;
}
};
ThreadListener listener;
SocketFeedEngine dataProvider;
// Configures thread pool
FeedEngineThreadSettings threadSettings;
threadSettings.pool().size(2).affinity().cpus().insert(1);
FeedEngineThreadPool threads(dataProvider, threadSettings, &listener);
Handler handler;
handler.settings().feeds().engine(&dataProvider);
handler.start();
while (!userRequestedToStop())
CurrentThread::sleep();
handler.stop();
Note
The Feed Engine abstraction does not require implementations to support multithreaded execution. Therefore, the OnixS::CME::MDH::NetFeedEngine::process function may not support simultaneous invocation by multiple threads. Check the documentation of a particular implementation to see if it is safe to call OnixS::CME::MDH::NetFeedEngine::process simultaneously.

Custom Feed Engines

The Feed Engine abstraction is represented as a set of abstract classes. Implementing them allows users to build their logic by extracting market data from various sources, including networks, file-based stores, etc.

To implement a custom feed engine, please contact OnixS Support.