OnixS ICE iMpact Multicast Feed Handler for C++  3.13.0.0
Manipulating market books

Market book in the Handler

Once 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: Full Order Depth, Top 5 Price Level, Top 10 Price Level and Top Of Book. 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::registerBookListener member.

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

Market book behavioural traits

An important aspect of book behaviour 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 new message from received from Multicast Price Feed. Therefore, instances can only be used to access information they store.

See Listening to Handler's events topic for more information concerning how to get notified about changes in the market books.

Example

Following sample demonstrates how book attributes can be processed by 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 first offer is "
<< book.offers().at(0).price
<< ". ";
}
if (book.bids().empty())
{
std::cout << "No bids available yet. ";
}
else
{
std::cout
<< "Price of first bid is "
<< book.bids().at(0).price
<< ". ";
}
std::cout << std::endl;
}
}

Behavioural 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. 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.