Erik Rigtorp

Estimating order queue position

When developing algorithmic trading strategies for FIFO markets it is beneficial to know our orders queue position in the order book. We use the queue position to calculate the intrinsic value of the order. When an orders intrinsic value is less than 0 we cancel it.

The method of estimation is highly dependent on the particular rules and technology of the exchange in question. Some exchanges provide direct API access to your order queue positions. Most US and European equity exchanges distribute a market-by-order data feed where you can infer exactly where your order is in the limit order book. Futures exchanges usually provide market data through a market-by-level feed where you receive the price and aggregate volume at the nn topmost price levels.

Obviously if you have direct API access to queue positions or a market-by-order feed it is theoretically trivial to know your order queue position, but it can be technically challenging to implement. For the market-by-level feeds it’s necessary to devise a method to estimate the queue position. I will describe a simple method to do just that.

First we estimate the initial queue position of a newly inserted order. We then monitor the market data feed and revise this estimate in response to market data updates:

  1. We insert an order of size SS at price PP at time t0t_0. An initial estimate V^(t0)\hat{V}(t_0) of the queue position is Q(t0)Q(t_0), the current aggregate size at price PP at time t0t_0 when we send our order. Alternatively we can use the size Q(t1)Q(t_1) at price PP at the time t1t_1 our order is acknowledged or an average of the two data points. Depending on if the market data feed coalesces updates we might see a size increase ΔQ(t3)\Delta Q(t_3) of SS at price PP at time t3∈(t0,t0+δ)t_3 \in (t_0, t_0+\delta), we can then update our estimate V^(t3)=Q(t3)−S\hat{V}(t_3)=Q(t_3)-S. The time offset δ\delta is chosen to be a multiple of the delay between sending an order and observing it on the market data feed.

  2. Now in event time scale: For every decrease ΔQ(n)<0\Delta Q(n) < 0 in the size Q(n)Q(n) at price PP we revise our estimate V^(n)\hat{V}(n). If the feed allows us to discriminate between order cancellations and order fills we update V^(n+1)=max⁡(V^(n)+ΔQ(n),0)\hat{V}(n+1)=\max(\hat{V}(n)+\Delta Q(n),0) for each order fill at price PP. For other updates we use a model to determine the probability p(n)p(n) that the update affects V^(n)\hat{V}(n). This model can be conditionally dependent on the relative size in front of and behind our order, properties of the order book and other factors. We then update

    V^(n+1)=max⁡(V^(n)+p(n)ΔQ(n),0). \hat{V}(n+1)=\max(\hat{V}(n) + p(n) \Delta Q(n), 0).

One useful family of models can be constructed as

p(n)=f(V^(n))f(V^(n))+f(max⁡(Q(n)−S−V^(n),0)) p(n)=\frac{f(\hat{V}(n))}{f(\hat{V}(n))+f(\max(Q(n)-S-\hat{V}(n), 0))}

where f(x)f(x) is an increasing function, for example ln⁡(1+x)\ln(1+x) or the identity function. The function f(x)f(x) would ideally be estimated using data from our own fills.