Replaying Log Files | Table of Content | Optional Fields |
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.
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.
The Handler passes instances of the Book class to the handlers of the BookUpdated event through the Book property of the BookUpdatedEventArgs instance.
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. |
There are two major members which are exposed by the Book class:
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. |
The following sample demonstrates how to process book attributes by the appropriate handler.
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); } }