/* Example of subscribing/unsubscribing to market depth from an Add On. */
public class MyAddOnTab : NTTabPage
{
private Instrument instrument;
public MyAddOnTab()
{
instrument = Instrument.GetInstrument("AMD");
if (instrument == null)
return;
// Follow this pattern to subscribe to MarketDepth events so they may be unsubscribed from the same instrument thread
if (!instrument.Dispatcher.HasShutdownStarted)
instrument.Dispatcher.InvokeAsync(() => instrument.MarketDepth.Update += OnMarketDepth);
// Print the Ask's price ladder
for (int i = 0; i < instrument.MarketDepth.Asks.Count; i++)
{
NinjaTrader.Code.Output.Process(string.Format("Position: {0} Price: {1} Volume: {2}", i,
instrument.MarketDepth.Asks[i].Price, instrument.MarketDepth.Asks[i].Volume), PrintTo.OutputTab1);
}
}
// This method is fired on market depth events and after the snapshot data is updated.
private void OnMarketDepth(object sender, MarketDepthEventArgs e)
{
return;
}
// Called by TabControl when tab is being removed or window is closed
public override void Cleanup()
{
// Follow this pattern to subscribe to MarketDepth events so they may be unsubscribed from the same instrument thread
if (instrument != null && !instrument.Dispatcher.HasShutdownStarted)
instrument.Dispatcher.InvokeAsync(() => instrument.MarketDepth.Update -= OnMarketDepth);
}
// Other required NTTabPage members left out for demonstration purposes. Be sure to add them in your own code.
}