OnixS C++ CME MDP Premium Market Data Handler  5.8.3
API Documentation
Constructing and copying order books

The handler can manage order books internally and exposes book instances through the callbacks. The SDK also provides the ability to construct and manipulate order books explicitly.

Constructing order book instances

Constructing "Market By Price" (MBP) order books

MBP books are limited in size (depth). The CME MDP platform provides information on book depth via "Instrument Definitions" messages. Therefore, Handler knows the book's depth as soon as it receives a definition for an instrument.

The SDK optimises memory allocation and data layout for MBP books to make book operations efficient. Therefore, the construction of MBP books and further lifetime management are performed through special factory classes. The table below maps factory classes to corresponding book types.

Book Class Factory Class
Direct OnixS::CME::MDH::DirectBookFactory
Implied OnixS::CME::MDH::ImpliedBookFactory
Consolidated OnixS::CME::MDH::ConsolidatedBookFactory

Each factory class represents an instantiation of the OnixS::CME::MDH::MbpBookFactory template class, which provides the following key members:

Member Description
OnixS::CME::MDH::MbpBookFactory::construct Constructs an instance of an order book of a particular type.
OnixS::CME::MDH::MbpBookFactory::destruct Destroys an instance of an order book of a particular type and disposes of allocated resources.
OnixS::CME::MDH::MbpBookFactory::calcSize Calculates the memory block size required to store an instance of the order book of a given depth.
OnixS::CME::MDH::MbpBookFactory::inplaceConstruct Constructs an instance of an order book in place of a given memory block.

Constructing "Market By Order" (MBO) order books

MBO books, in contrast to MBP ones, are not limited by depth and may contain an arbitrary number of bids and offers. Therefore, an order book instance data layout cannot be optimised. For this reason, there are no factory classes for constructing MBO book instances. Instead, OnixS::CME::MDH::MboBook instances are ordinarily built.

Copying order book content

The SDK offers the OnixS::CME::MDH::copy routine to copy book content across instances.

A template version of the given routine copies price levels and other MBP book data. Also, the routine has an optional parameter limiting the number of price levels to copy:

void onBookUpdate(Handler&, const Security&, const DirectBook& book) override
const DirectBook::Depth CloneDepth = 3;
/// Allocate memory and construct the book to be cloned to.
DirectBook* const clone = DirectBookFactory::construct(CloneDepth);
// Make a copy of the first 'CloneDepth' levels of the book.
copy(*clone, book, CloneDepth);
// Use the clone (it could also use outside the callback).
std::clog << toFormattedStr(*clone);
// Destroy the clone and frees the memory block (it could also use outside the callback).

Overload of the OnixS::CME::MDH::copy routine for MBO books represents a wrapper over the OnixS::CME::MDH::MboBook assignment operator.