Order book: algorithms
Order books in the S# are presented by the MarketDepth data type. A number of operations on the data in the order book can be performed with this type. For example, you can sparse or, vice versa, groupe the data by price levels.
Order book modifications
The creating of sparse order book from the normal one is carried out through the TraderHelper.Sparse(StockSharp.BusinessEntities.MarketDepth depth, StockSharp.Messages.Unit priceStep**)** method:
MarketDepth depth = ....; var sparseDepth = depth.Sparse();
All the Quote quotations in the resulting order book will have zero volume, and they will created with the Security.StepPrice step.
To combine the sparse order book with the original one (to connect the real and sparse quotations), you must call the TraderHelper.Join(StockSharp.BusinessEntities.MarketDepth original, StockSharp.BusinessEntities.MarketDepth rare**)** method:
var joinedDepth = sparseDepth.Join(depth);
The grouping of the order book by price levels is carried out through the TraderHelper.Group(StockSharp.BusinessEntities.MarketDepth depth, StockSharp.Messages.Unit priceRange**)** method:
MarketDepth depth = ....; // grouping of the order book by 10 points price levels var grouppedDepth = depth.Group(10.Points(depth.Security));
The result of the grouping will be the MarketDepth order book, consisting of quotations of the AggregatedQuote type. Through the AggregatedQuote.InnerQuotes property the real order book quotations can get, on which the grouping by price level was done.