?> QuantXpress – Deliver high performance automated trading and connectivity solutions



Market Data Event

BlitzTrader API enabled your strategy to stream real-time market data information for Level-I and Level-II data. Level-I information consists of only the real-time bid/offer quotes for tradable securities. The Level II data displays the highest bid prices and lowest ask prices along with their size for each Market participant for a given security. Level II Data is of interest to traders because it indicates the buying and selling pressure behind individual securities.

Market Depth

Market depth is Level-II information data and shows the supply and demand for stock at various prices and can be a key indicator of market sentiment. Following is the snapshot of ANZ Securities up to 5 level depths. In market depth information, you can see a summary of all orders that are currently in the market. The information is continuously updated as new orders arrive and existing orders are filled or being pulled from the market.

BID
ASK
Quantity No. Price Price No. Quantity
29536 31 243 243.50 1 16086
50000 1 242.50 244 3 45647
154800 2 242 245 4 92959
4000 1 240 245 1 31500
57018 2 239 246.50 1 10000

Bid and Ask

The bid is the price that someone is willing to pay for a security at a specific point in time, whereas the ask is the price at which someone is willing to sell.
"Bids" refers to the quantity of shares wanted to be purchased for a maximum price. The Bid price is also referred to as the "Buy" price.
"Asks" refers to the quantity of shares available to be sold at a minimum price. The Ask price is also referred to as the "Sell" or "Offer" price.
A trade occurs when the Bid price is raised to meet the Ask price or, alternatively, when the Ask price is lowered to meet the Bid price. During market trading hours, Bid prices are lower than Ask prices - thus creating a "price spread"

Spread

The difference between the highest Bid price and the lowest Ask prices. If you're trading highly liquid securities, the bid-ask spread will tend to be small, meaning that buyers and sellers generally agree about what the right price for a security should be. A large spread will exist when a market is not being actively traded.

BID
ASK
Quantity No. Price Price No. Quantity
29536 31 243 243.50 1 16086

The Spread is
SpreadPrice = AskPrice – BidPrice;
243.50 – 243 = 0.50

TickSize

A tick size is the smallest increment in price that equity, future, or other exchange-traded instrument is permitted to move. In a financial market, the tick size is the minimum allowable price variation that an equity, future, or other exchange-traded instrument is permitted to move. Futures markets often have specific tick sizes, but stock markets have a tick size of 0.01, which is the equivalent of $0.01 for US stock markets. Tick sizes and tick values are part of the contract specifications for all financial markets. For example, the EUR futures market has a tick size of 0.0001, which means that the smallest increment that the price can move from 1.2902, would be up to 1.2903, or down to 1.2901. The tick size is also known as the minimum price change.

Tick Value

A market's tick value is the cash value of one tick (one minimum price movement). For example, the EMinini S&P 500 futures market has a tick size 0.25 and tick value of $12.50, which means that for every 0.25 moves up or down, the profit or loss of a trade would increase or decrease by $12.50. The tick value is also known as the minimum price value.

Top of the book or Touchline


It usually represents the highest bid and lowest offer and also known as best bid and offer.

BID
ASK
Quantity No. Price Price No. Quantity
29536 31 243 243.50 1 16086

BlitzTrader API provides Event callback OnMarketDataEvent method in your strategy that developers need to override to get notification of change in market data information for subscribed instrument variable.

 
private IVObject _iv = new IVObject("Instrument", "Tradable Instrument", true,
InstrumentType.Futures | InstrumentType.Options, MarketDataType.All, OrderEventType.All);

....................
....................

protected override void OnMarketDataEvent(StrategyMarketDataEventArgs  
                                                 strategyMarketDataEventArgs)
{
    if (strategyMarketDataEventArgs.IVObject == _iv)
    {
        ITouchLineInfo touchLineInfo = 
strategyMarketDataEventArgs.MarketDataContainerInfo.TouchLineInfo;

        double bestBidPrice = touchLineInfo.BestBidPrice;
        int bestBidSize = touchLineInfo.BestBidSize;
        double bestAskPrice = touchLineInfo.BestAskPrice;
        int bestAskSize = touchLineInfo.BestAskSize;
        double lastPrice = touchLineInfo.LastPrice;
        int lastSize = touchLineInfo.LastSize;
        long lastTradedTime = touchLineInfo.LastTradedTime;
    }

}

Getting Touchline information

 
ITouchLineInfo touchLineInfo = 
strategyMarketDataEventArgs.MarketDataContainerInfo.TouchLineInfo;

double bestBidPrice = touchLineInfo.BestBidPrice;
int bestBidSize = touchLineInfo.BestBidSize;
double bestAskPrice = touchLineInfo.BestAskPrice;
int bestAskSize = touchLineInfo.BestAskSize;
double lastPrice = touchLineInfo.LastPrice;
int lastSize = touchLineInfo.LastSize;
long lastTradedTime = touchLineInfo.LastTradedTime;

LastTradedTime is represented in number format and its value is depend upon exchange segment of the instrument for which market data event notification is raised. For example in most exchange segment it is represented as numbers of seconds elapsed since epoch.

To get a actual DateTime object call a following utility method
 
DateTime lastTradedUTCDT = ExchangeCommon.GetDateTimeFromBaseDateElapsedSeconds(
                                    touchLineInfo.Instrument.ExchangeSegment, touchLineInfo.LastTradedTime);
DateTime lastTradedLocalDT = lastTradedUTCDT.ToLocalTime();
//To know if touchline represent a change in any attribute of Last trade
bool isLastPriceChange = touchLineInfo.IsLastPriceChange;
//To access a previous last price.
double lastPrice = touchLineInfo.PreviousLastPrice;

Getting MarketDepth information

 
IMarketDepthInfo marketDepthInfo = strategyMarketDataEventArgs.MarketDataContainerInfo.MarketDepthInfo;
double totalSumBidPrice = 0;
int totalBidSize = 0;
//  Calculating BuySide VWAP price till depth level 5;
for(int i=0; i< marketDepthInfo.MarketDepthLevel; i++)
{
    totalSumBidPrice += marketDepthInfo.GetBidPriceAt(i);
    totalBidSize += marketDepthInfo.GetBidSizeAt(i);

   if (i >= 5 || 
          marketDepthInfo.GetBidSizeAt(i) == 0 || 
          marketDepthInfo.GetBidPriceAt(i) <= 0)
       break;
}
double vwapBidPriceTill5Level = totalSumBidPrice / totalSize;

IMarketDepthInfo interface provides depth level price and size information.
To access the price and size at any depth level use a method:
 
int GetBidSizeAt(int depthIndex);
double GetBidPriceAt(int depthIndex);
int GetAskSizeAt(int depthIndex);
double GetAskPriceAt(int depthIndex);

Note: The depthIndex = 0 indicate the first level depth
IMarketDepthInfo interface also give access to indicator functions to return some calculated value related to market depth i.e
 
int GetTotalDepthQuantity(OrderSide side);
int GetTotalQuantityTillDepth(OrderSide side, int depthLevel);
int GetDepthIndexForAvailableQuantity(OrderSide side, int quantityToCheck);
double GetVWAP(OrderSide side);
double GetVWAPTillDepth(OrderSide side, int depthLevel);

Some price evaluation method

To convert any fractional value to a nereast price compatible with instrument tick size use a function RoundOffPriceToWholeTicks
 
double RoundOffPriceToWholeTicks(double orderPrice, OrderSide orderSide, IVObject ivObject)

double priceToReturn = bestBidPrice(1-percentBenchmark*0.01);
double priceToReturn = base.RoundOffPriceToWholeTicks(priceToReturn, optionOrderSide, _ivObject);

The best price on its order side can be evaluated based on order book state and your exiting order in the book. Here it is necessary that you should not become best of your own order. BlitzTrader provides easy to use API to evaluate the best bidding price using GetBestPrice method.

If order is new and you have no open order state, then use following method to evaluate best bidding price.
 
double GetBestPrice(IMarketDataContainerInfo marketDataContainer, OrderSide targetOrderSide)

If order is already in the bood and you need to evaluate best price based on changed market condition, use following method.

 
double GetBestPrice(IMarketDataContainerInfo marketDataContainer, IOrderExecutionReportData currentOrder)

Code Snippet

 
private IOrderCommand _entryOrderCommand = null;
..............................
..............................
if (_entryOrderCommand.CurrentOrder == null)
   entryOrderPrice = base.GetBestPrice(_ivInfo.MarketDataContainer, entrySide);
else if (entrySide == OrderSide.Sell)
   entryOrderPrice = base.GetBestPrice(_ivInfo.MarketDataContainer, _entryOrderCommand.CurrentOrder);

Access of Instrument information
IMarketDepthInfo marketDepthInfo = 
         strategyMarketDataEventArgs.MarketDataContainerInfo.MarketDepthInfo;

QX.Base.Common.InstrumentInfo.Instrument instrument = 
                         strategyMarketDataEventArgs.IVInstrument.Instrument;

if(instrument.InstrumentType == InstrumentType.Options)
{
    Options optionInstrument = (Options)instrument;
    double strikePrice = optionInstrument.StrikePrice;
    DateTime contractExpiration = optionInstrument.ContractExpiration;
}

Access of Instrument information


 
IMarketDepthInfo marketDepthInfo = 
         strategyMarketDataEventArgs.MarketDataContainerInfo.MarketDepthInfo;

QX.Base.Common.InstrumentInfo.Instrument instrument = 
                         strategyMarketDataEventArgs.IVInstrument.Instrument;

if(instrument.InstrumentType == InstrumentType.Options)
{
    Options optionInstrument = (Options)instrument;
    double strikePrice = optionInstrument.StrikePrice;
    DateTime contractExpiration = optionInstrument.ContractExpiration;
}