Basic Prerequisites: 01 · From Zero and Market Microstructure & Order Types.


1. Intuition & Practical Objective

The matching engine is not a price-matching device; it is a queue-management device. This page pins down exactly what queue you join, how your position changes, and what removes volume from in front of you. Get these mechanics right and the fill-probability models of pages 03–04 become bookkeeping.

Three mechanical facts to internalise:

  1. Two priority protocols dominate. Most equity venues use price-time (FIFO) - ties at a price break by arrival timestamp. Several interest-rate and Treasury futures markets use pro-rata - fills are allocated in proportion to order size, so a large order can leapfrog a small early order.
  2. Your position moves for three reasons only. Trades consume the front; cancellations ahead remove orders in front; incoming limit orders join behind you (they never help you). Births add depth but do not change .
  3. Cancellations are not your friend by default. Under the uniform-cancellation hypothesis a cancel removes a random live order, so it is ahead of you with probability . The same cancels that speed your fill in a quiet market vanish (or turn into even more trades) when you least want them - the mechanical origin of adverse selection.

2. Mathematical Ground Truth & Derivations

2.1 Price-time priority (FIFO)

Your order of size at position fills against cumulative outflow (trades plus cancels ahead) as

If is “one unit” (the empirical convention, Cont–Stoikov–Talreja take unit order size), this is simply the indicator .

2.2 Pro-rata allocation

Under pro-rata, when an incoming market order of size meets resting size at the price, each resting order gets

Consequence: size buys priority. A trader who posts a large order late can out-fill a small order posted early. Queue position (in orders) matters less than relative size - which is why pro-rata books reward over-posting and why FIFO is the cleaner model for queue-position economics.

2.3 Position dynamics and the mean-field ODE

Let be your position (orders ahead). In a small interval :

  • market orders arrive at rate and consume the front: ;
  • each of the orders ahead cancels at rate (per-order cancel hazard), giving ;
  • limit-order arrivals at rate join the back: no effect on (but they raise total depth ).

The expected position obeys the linear ODE

So the queue position decays exponentially toward the trade-driven floor ; with trades alone it crosses zero at the deterministic first-passage time

while cancel-only decay () is , which never reaches zero in finite mean - pure cancellations can only halve your wait, they never guarantee a fill. This is the analytic backbone of the birth–death view formalised on page 04.

2.4 Cancellations: uniform vs strategic

The uniform hypothesis is the tractable benchmark. Empirically cancels are not uniform - they cluster (deep-book orders are stickier; front-of-book orders are flighty). Under positive cancel-clustering at the front, your fill is slower than the uniform model predicts in quiet markets and faster in stressed markets - again the adverse-selection shape.


3. Computational Implementation - Gillespie simulation of one price level

We simulate a single FIFO queue exactly (Gillespie / kinetic Monte Carlo): market orders at rate consume the front, each of the orders ahead cancels at rate , and limit orders arrive at rate and join the back (leaving unchanged). We then check the simulation against the mean-field ODE.

Notice how faithfully the deterministic mean-field curve tracks the simulation: by s the ODE predicts the queue is nearly gone () and the simulated fill probability jumps to . The pure-cancel case is the punchline - with no trades, no finite horizon fills you; cancellations only erode the queue geometrically, halving in s.


4. Failure Modes & First-Principles Breakdowns

  1. Wrong priority protocol. Modelling a pro-rata futures book with a FIFO model (or vice versa) mis-attributes fills to queue position when the real driver is relative size. Always confirm the venue’s allocation rule before calibrating .
  2. Treating (depth) as (position). A deep book with a huge queue ahead of you is bad for fills, even though deep books are good for spreads. Conflating the two in a single “liquidity” number is the classic modelling shortcut that destroys fill forecasts.
  3. Ignoring the birth term’s asymmetry. Incoming limit orders refill the book behind you and never advance your position; only trades and front-cancels do. Models that let all book activity erode systematically overestimate fill speed.
  4. Deterministic queue assumption. is a random process (page 04). Using the mean-field curve to time cancellations/reposts ignores the variance - precisely the paths where you get stuck (queue did not clear) or picked off (it cleared too fast).

5. References

  • Cont, Stoikov & Talreja (2010)
  • Gould et al. (2013)
  • Foucault, Pagano & Roell, Market Liquidity

6. Connected Graph Bridges