Queue Position Modeling
Fill probability and expected fill time estimation for limit orders
Queue position modeling estimates where your limit order sits in the order book and how likely it is to fill before you need to cancel. Horizon uses Poisson arrival and cancellation processes to model queue dynamics, giving you a probabilistic view of execution rather than a binary “filled or not.”
API
QueueModel
python
model = hz.QueueModel()
# Feed it the current book state
model.update_book(
bids=[(99.50, 120), (99.45, 340), (99.40, 500)],
asks=[(100.00, 80), (100.05, 250), (100.10, 410)],
)
# Where are we in the queue at a given price level?
pos = model.queue_position(price=99.50, side="buy")
pos.ahead # shares/contracts ahead of us
pos.fill_prob # probability of fill before cancel
pos.expected_time # expected seconds to fill (given fill)
pos.arrival_rate # estimated order arrival rate (lambda)
pos.cancel_rate # estimated cancellation rate (mu)
Queue tracker
For live monitoring across multiple price levels:
python
tracker = hz.queue_tracker()
# Register interest in specific levels
tracker.watch(price=99.50, side="buy", our_size=10)
tracker.watch(price=100.00, side="sell", our_size=5)
# On each book update
tracker.on_book(bids, asks)
# Check all watched levels
for level in tracker.levels():
print(f"{level.price} {level.side}: "
f"fill_prob={level.fill_prob:.2f}, "
f"eta={level.expected_time:.1f}s")
Poisson model internals
The model treats the queue as a birth-death process:
- Arrivals (new orders joining behind you): Poisson with rate
lambda, estimated from recent book updates. - Cancellations (orders ahead of you leaving): Poisson with rate
mu, estimated from observed order removals. - Fills (market orders consuming the queue): Poisson with rate
phi, estimated from trade flow.
Fill probability at position k in a queue of depth N:
P(fill) = (phi / (phi + mu_self)) * product_{i=1}^{k} (phi + mu) / (phi + mu + lambda)
where mu_self is your own cancellation rate (set to 0 if you intend to hold).
When to use
- Passive execution: decide whether to post a limit order or cross the spread based on fill probability.
- Order placement optimization: compare fill probabilities at adjacent price levels to find the best queue position.
- Cancellation timing: monitor expected fill time and cancel orders whose queue position has deteriorated past a threshold.
- Market making: estimate how quickly your resting quotes will execute to calibrate inventory risk.
python
# Example: only post limit if fill probability > 60%
pos = model.queue_position(price=best_bid, side="buy")
if pos.fill_prob > 0.60:
hz.submit_limit(market_id, price=best_bid, size=10)
else:
hz.submit_limit(market_id, price=best_bid + 0.05, size=10) # improve price