"Snapshot data is provided to you right on subscription"
The code example on the docs shows creating and subscribing to the Update event and having the snapshot prices available immediately:
marketData = new MarketData(instrument); marketData.Update += OnMarketData; // Printing snapshot market data for the last price and time NinjaTrader.Code.Output.Process(marketData.Last.Price.ToString() + " " + marketData.Last.Time.ToString(), PrintTo.OutputTab1);
The output of consecutive clicks is as follows:
=============== NZDCAD Market Data Connect Snapshot: =============== SnapShot Last Price is: Null Snapshot Ask Price is: Null Snapshot Bid Price is: Null =========== NZDCAD OnMarketDataUpdate Ask #1 ============== SnapShot Last Price is: Null Snapshot Ask Price is: 0.9525 Snapshot Bid Price is: Null =========== NZDCAD OnMarketDataUpdate Bid #2 ============== SnapShot Last Price is: Null Snapshot Ask Price is: 0.9525 Snapshot Bid Price is: 0.95244 =========== NZDCAD OnMarketDataUpdate Last #3 ============== SnapShot Last Price is: 0.95244 Snapshot Ask Price is: 0.9525 Snapshot Bid Price is: 0.95244 ==================== DISCONNECTED ===================== =============== GBPJPY Market Data Connect Snapshot: =============== SnapShot Last Price is: Null Snapshot Ask Price is: Null Snapshot Bid Price is: Null =========== GBPJPY OnMarketDataUpdate Ask #1 ============== SnapShot Last Price is: Null Snapshot Ask Price is: 139.292 Snapshot Bid Price is: Null =========== GBPJPY OnMarketDataUpdate Bid #2 ============== SnapShot Last Price is: Null Snapshot Ask Price is: 139.292 Snapshot Bid Price is: 139.281 =========== GBPJPY OnMarketDataUpdate Last #3 ============== SnapShot Last Price is: 139.281 Snapshot Ask Price is: 139.292 Snapshot Bid Price is: 139.281 ==================== DISCONNECTED ===================== =============== EURCAD Market Data Connect Snapshot: =============== SnapShot Last Price is: Null Snapshot Ask Price is: Null Snapshot Bid Price is: Null =========== EURCAD OnMarketDataUpdate Ask #1 ============== SnapShot Last Price is: Null Snapshot Ask Price is: 1.40053 Snapshot Bid Price is: Null =========== EURCAD OnMarketDataUpdate Bid #2 ============== SnapShot Last Price is: Null Snapshot Ask Price is: 1.40053 Snapshot Bid Price is: 1.40044 =========== EURCAD OnMarketDataUpdate Last #3 ============== SnapShot Last Price is: 1.40044 Snapshot Ask Price is: 1.40053 Snapshot Bid Price is: 1.40044 ==================== DISCONNECTED =====================
You'll note that after Subscription, no snapshot data is available; all the data items are NULL in the MarketData instance. they only get updated as new OnUpdate events are fired one-by-one.
I have had to write an async MarketDataProxy using TaskCompletionSources and SemaphoreSlims to get around this and ensure that I have snapshot data available to me when I need it. However during times of low market volume there is sometimes a wait of a few seconds before I get the data.
After re-reading the docs; I don't think this class is working as it should; and certainly not in the manner illustrated in the code example....
Comment