Drawing Order Book
A strategy from code can draw data on the Order Book panel similarly to the Order Book cube. For this, the following code needs to be written.
- Create a descendant of the IOrderBookSource interface, which Designer uses to identify the source. In the example case, the OrderBookSource class is used, which is the default implementation of the interface:
private static readonly OrderBookSource _bookSource = new OrderBookSource("SMA");
- Override the OrderBookSources property:
public override IEnumerable<IOrderBookSource> OrderBookSources
=> new[] { _bookSource };
Thus, the strategy will indicate to external code (in this case, the Order Book panel) which sources of order books are available. The multitude of sources occurs in the case when the strategy works with several order books (different instruments, or order books with various modifications, such as, for example, thinned order book).
- Add the initialization of the subscription to the order book in the strategy code. In the case of SmaStrategy, it is added to the end of the OnStarted method:
var bookSubscription = new Subscription(DataType.MarketDepth, Security);
bookSubscription
.WhenOrderBookReceived(this)
.Do(book =>
{
// drawing order book
DrawOrderBook(bookSubscription, _bookSource, book);
})
.Apply(this);
Subscribe(bookSubscription);
In the Do handler, a call is made to the DrawOrderBook method, which sends the order book for drawing.
- Add the Order Book panel and select the source created in code:
- After launching the strategy for testing, the order book will be filled with data: