Skip to content

OnMarketDataEvent Method

The Strategy always requires access to real-time market data and alerts on changes in data state to evaluate opportunities triggering the order flow to the exchange. The Blitz Strategy development framework facilitates streaming real-time market data information for Level-I and Level-II data.

To receive real-time market data events for subscribed Instruments mapped with Strategy-defined IVObject, the Strategy developer needs to implement the OnMarketDataEvent method. The framework invokes this method in real-time whenever there is a price update of Level-I or Level-II market data of Instruments bound to subscribed IVObject.

OnMarketDataEvent method is one the important method that all Strategy must implements and puts their Strategy invocation logic.

Here's a sample implementation of the OnMarketDataEvent method:

protected override void OnMarketDataEvent(StrategyMarketDataEventArgs eventArgs)
{
            if (this.ActivateProfiling)
            {
                TraceLogInfo(string.Format("OnMarketDataEvent. Instrument: {0}, Time: {1}, LTP: {2}, LTQ: {3}",
                   eventArgs.IVInstrument.Instrument.DisplayName, eventArgs.MarketDataContainerInfo.LastTradedTimeDT.ToString("dd-MM-yyyy HH:mm:ss"), eventArgs.MarketDataContainerInfo.LastPrice, eventArgs.MarketDataContainerInfo.LastSize));
            }

            if (!_isStrikesLoaded && _ivInfo.MarketDataContainer.LastPrice > 0)
            {
                TraceLogInfo(string.Format("Subscribing market data for 25 up and down strikes"));
                if (LoadOptions())
                    _isStrikesLoaded = true;
            }

            DateTime ltd = _ivInfo.MarketDataContainer.TouchLineInfo.LastTradedTimeDT;

            double ltp = eventArgs.MarketDataContainerInfo.TouchLineInfo.LastPrice;
            double ltq = eventArgs.MarketDataContainerInfo.TouchLineInfo.LastPrice;
            double priceAtLevel5 = _ivInfo.MarketDataContainer.GetAskPriceAt(4);
            double tickSize = _ivInfo.IVInstrument.Instrument.TickSize;
            int netPosition = _ivInfo.Statistics.NetPosition;
            if(_ivInfo.RealizedMTM < Input_MaxMTMLoss)
            {
                .
                .
            }
            ……..
            ……..
}

In this implementation: - The OnMarketDataEvent method is overridden to handle incoming market data events. - Inside the method, relevant information such as instrument name, bid price, ask price, and volume is extracted from the eventArgs parameter. - The extracted data is then used to perform strategy invocation logic based on the received market data. This could involve evaluating trading opportunities, adjusting strategy state, or any other relevant actions based on the market conditions.

MarketDataDelayNotifyTimeInSeconds Override Method

The Strategy developer sometimes needs an alert if real-time Market Data events are not reaching the Strategy for any reason.

They can utilize the MarketDataDelayNotifyTimeInSeconds method to specify the duration after which the alert mechanism will be invoked if market data is not received. In following example the alert mechanism is raised if market data event is not received for 10 seconds.

protected override int MarketDataDelayNotifyTimeInSeconds
{
    get { return 10; }
}
Additionally, they can override the OnMarketDataDelay method to handle the alert mechanism:
override  void OnMarketDataDelay(StrategyMarketDataDelayEventArgs eventArgs)
{
}
The OnMarketDataDelay callback provides the Strategy developer with an opportunity to manage system risk or raise alert mechanism if the Strategy is stalled due to failures in the market data channel from the exchange or data provider.

OnStrategyStatusQuery Override Method

Sometimes, the Quant requires informative updates on the state of a Strategy instance at any given time, triggered from the Trading Dashboard. The Blitz Trading Dashboard features a predefined command called Status Query, accessible via the context menu for each Strategy instance. Upon invocation from the Trading Dashboard, control is passed to the callback function OnStrategyStatusQuery within your Strategy Instance.

Developers have the flexibility to reflect the current state of the Strategy Instance using the TraceLogInfo function. Any text logged using TradeLogInfo will be displayed in the Log Window within the Trading Dashboard. This process facilitates the creation of informative states to be reflected in the Trading Dashboard as needed.

protected override void OnStrategyStatusQuery()
{
            TraceLogInfo ("OnStrategyStatusQuery.”);

            double straddleExecutionPrice = 0;
            double straddleMarketPrice = 0;

            foreach (IOrderCommandEx orderCommandEx in _orderExecutionMAP.Values)
            {
                if(orderCommandEx.IVInfo.Statistics.NetPosition != 0)
                {
                    straddleExecutionPrice += orderCommandEx.GetAverageExecutionPrice();
                    straddleMarketPrice += orderCommandEx.IVInfo.MarketDataContainer.LastPrice;

                    TraceLogInfo(string.Format("Options status. CallInstrument: {0}, Position: {1}, ExecutionPrice: {2}, LTP: {3}, InstrunctionType: {4}",
                        _callOptionsOrderCommandEx.IVInfo.InstrumentName,
                        _callOptionsOrderCommandEx.IVInfo.Statistics.NetPosition,
                        _callOptionsOrderCommandEx.GetAverageExecutionPrice(),
                        _callOptionsOrderCommandEx.IVInfo.MarketDataContainer.LastPrice,
                        _callOptionsOrderCommandEx.InstructionType.ToString()));
                }
            }

            TraceLogInfo (string.Format("StraddleExecutionPrice: {0}, StraddleMarketPrice: {1}, MTM: {2}",
                straddleExecutionPrice,
                straddleMarketPrice,
                base.UnrealizedMTM + base.RealizedMTM));
}
The provided code snippet collects crucial state information of the Strategy and relays it to the Trading Dashboard through TraceLogInfo.