OnixS ICE iMpact Multicast Price Feed Handler C++ library  8.5.1
API documentation
Manipulating Order Books

Market book in the Handler

Once a subscription is started Handler builds and synchronizes books for each market for which product definition was previously received.

Book abstraction is exposed by the OnixS::ICE::iMpact::MarketData::OrderBook class.

There were several types of books currently supported by the Handler:

The Handler is capable to build and maintain books of any type for the subscribed markets.

Handler passes instances of OnixS::ICE::iMpact::MarketData::OrderBook class to the listeners of book changes registered through the Handler's OnixS::ICE::iMpact::MarketData::Handler::registerOrderBookChangeListener member.

OnixS::ICE::iMpact::MarketData::OrderBook class exposes two major members to access market orders and price-levels:

Market book behavioral traits

An important aspect of book behavior is that not all its members available for all types of books. In particular, OnixS::ICE::iMpact::MarketData::OrderBook::bidOrders (OnixS::ICE::iMpact::MarketData::OrderBook::offerOrders) members works only for full order depth books. Therefore, it will return an empty array in case of price-level book. For this reason, when accessing members of OnixS::ICE::iMpact::MarketData::OrderBook instance it's necessary to check its type using OnixS::ICE::iMpact::MarketData::OrderBook::depth member.

Also, since books are changed in time, do not store references to obtained orders and price levels. Any instance exposed by book through OnixS::ICE::iMpact::MarketData::OrderBook::bidOrders (OnixS::ICE::iMpact::MarketData::OrderBook::offerOrders) or OnixS::ICE::iMpact::MarketData::OrderBook::bids and OnixS::ICE::iMpact::MarketData::OrderBook::offers members is valid only in bounds of handling routine being called by the Handler to process changes in book. It may be deleted right after handling accomplished as a response to a new message from received from Multicast Price Feed. Therefore, instances can only be used to access the information they store.

See Event Listeners topic for more information concerning how to get notified about changes in the market books.

Example

The following sample demonstrates how book attributes can be processed by the appropriate listener:

virtual void onBookUpdated(const OrderBook& book, const MessageInfo& msgInfo)
{
ProductDefinitionsConstEntry foundDefinition = productDefinitions_.find(book.marketId());
if (productDefinitions_.end() != foundDefinition)
{
const ProductDefinition& definition = foundDefinition->second;
std::cout
<< "Changes detected in "
<< BookDepth::toString (book.depth())
<< " book for market "
<< marketId
<< ": "
<< std::endl;
if (book.offers().empty())
{
std::cout << "No offers available yet. ";
}
else
{
std::cout
<< "Price of the first offer is "
<< book.offers().at(0).price
<< ". ";
}
if (book.bids().empty())
{
std::cout << "No bids available yet. ";
}
else
{
std::cout
<< "Price of the first bid is "
<< book.bids().at(0).price
<< ". ";
}
std::cout << std::endl;
}
}

Behavioral Traits

Handler constructs books for each security since the moment it receives definition for that security. Books are changed in time and their members are not thread-safe. The Handler uses own synchronization strategies while updating the books. Therefore, do not access price levels information outside of book-related event handling as well as do not store references to any book instance and data returned by its members like asks and bids collections. This is because Handler may change internal book structures at the same time. If any data exposed by the OnixS::ICE::iMpact::MarketData::OrderBook class instance must be used outside of event handling, it must be copied before later use.