forwardReplaying Log Files   Table of ContentOptional Fieldsforward
Working with Books

Once the subscription is started, the Handler builds and synchronizes the books for each market based on the previously set product definition.

Book Abstraction and Supported Types of Books

The book abstraction is exposed by the Book class.

There are two types of books currently supported by the Handler: Full Order Depth and Price-Level. The Handler is capable of building and maintaining the book of any or both types simultaneously for the subscribed markets.

Obtaining Book Instances

The Handler passes instances of the Book class to the handlers of the BookUpdated event through the Book property of the BookUpdatedEventArgs instance.

Note Note
The instances are passed by the Handler for the subscribers of the BookUpdated event. They represent temporary objects. The next time, when the Handler fires the BookUpdated event for the same market, it will pass another instance of the Book class.
Accessing Book Information

There are two major members which are exposed by the Book class:

  • the GetOrders(Side) member which provides an access to the market orders data exposed as instances of the Order class. The only parameter side of this member instructs whether bids or offers must be returned;
  • the GetPriceLevels(Side) member which provides an access to price levels information represented as instances of the PriceLevel class. The only parameter side of this member instructs whether price levels of bids or offers must be returned.

Note Note
An important aspect of the book behavior is that not all its members are available for all types of books. In particular, the GetOrders(Side) member works only for Full Order Depth books.
Example

The following sample demonstrates how to process book attributes by the appropriate handler.

C#
class BookChangeTracer
{
    private Dictionary<int, FuturesProductDefinitionEventArgs> productDefinitions_;

    public BookChangeTracer(
        Handler handler,
        Dictionary<int, FuturesProductDefinitionEventArgs> definitions)
    {
        handler.BookChanged += OnBookChanged;
        productDefinitions_ = definitions;
    }

    private void OnBookChanged(object sender, BookChangedEventArgs args)
    {
        FuturesProductDefinitionEventArgs productDefinition = null;

        if (productDefinitions_.TryGetValue(
            args.MarketId, out productDefinition))
        {
            Console.Write(
                "Changes detected in {0} book for the market {1}: ",
                args.Book.Type, args.MarketId);

            IList<PriceLevel> offers =
                args.Book.GetPriceLevels(Side.Offer);

            if (0 == offers.Count)
            {
                Console.Write("No offers are available yet. ");
            }
            else
            {
                Console.Write(
                    "Price of first offer is {0}. ",
                    GetRealPrice(
                        offers[0].Price,
                        productDefinition.OrderPriceDenominator));
            }

            IList<PriceLevel> bids =
                args.Book.GetPriceLevels(Side.Bid);

            if (0 == bids.Count)
            {
                Console.Write("No bids are available yet. ");
            }
            else
            {
                Console.Write(
                    "Price of the first bid is {0}. ",
                    GetRealPrice(
                        bids[0].Price,
                        productDefinition.OrderPriceDenominator));
            }

            Console.WriteLine();
        }
    }

    private static double GetRealPrice(long price, int denominator)
    {
        return (double)price / Math.Pow(10.0, (double)denominator);
    }
}