Writing / Market structure
Who Gets Filled First? Price, Time, and Queue Priority
See how price, arrival order, and amendments determine queue priority, with worked fills and clearly scoped comparisons across trading venues.

Two sellers offer the same instrument at the same price. A buyer arrives for less than the combined quantity. Somebody waits.
The matching engine needs a rule that decides who trades first. A depth chart usually conceals that rule by adding everyone’s quantity together at each price.
To understand the fill, open the price level.
The queue beneath the number
Our fictional Harbor market trades a fictional instrument, BAG, in whole units at one-dollar price increments. Its order book holds buy and sell instructions waiting to trade. A resting order is one already waiting there; an incoming order can trade with compatible resting interest. Each completed trade is a fill.
All orders are displayed and belong to different owners. Better prices come first; among orders at the same price, earlier accepted orders come first. Execution uses the resting order’s price. A buy limit sets the most the buyer will pay; a sell limit sets the least the seller will accept. We study continuous trading on one venue, without routing, auctions, or fees.
Start with this book. The accepted sequence is Harbor’s processing order, with lower numbers coming first:
| Side | Order | Price | Remaining units | Accepted sequence |
|---|---|---|---|---|
| Buy | B1 | $99 | 6 | 100 |
| Sell | S1 | $100 | 4 | 101 |
| Sell | S2 | $100 | 3 | 102 |
| Sell | S3 | $101 | 5 | 103 |
The seven units offered at $100 are two separate interests. In Harbor’s queue, S1 is ahead of S2 because sequence 101 precedes 102.
For example, a five-unit buy at a $100 limit would take S1’s four units first and one from S2, leaving S2 with two. That completes the buyer’s order while showing why the seven-unit depth row is insufficient to explain which seller trades. Each comparison below starts again from the initial table.

Figure 2.1. At the $100 ask, S1 entered at sequence 101 with four units and S2 at 102 with three. A five-unit buy takes all four from S1 and one from S2, leaving two on S2. S3 at $101 is outside this buy limit.
An incoming buy order that can pay $101 still reaches the $100 sellers first. S3 cannot jump them by being older or larger. For the buyer, $100 is the better price. Time decides among orders at the same price after that price comparison.
Coinbase Exchange explicitly defines priority by price and the order in which its matching engine receives orders. That supports the simple model; it does not establish that a trader’s device timestamp controls the queue. Coinbase matching rules
The clock on your laptop does not assign the place
Suppose trader A clicks before trader B. A’s network stalls. B’s order reaches Harbor’s sequencing point first.
Our model gives B the earlier sequence. A screenshot of an earlier click does not reverse the order. The exchange cannot run a coherent queue from clocks supplied by unrelated clients.
Harbor uses a unique sequence to make the example unambiguous. A real venue may describe its ordering in timestamps, protocol sequencing, or more detailed rules. The question to ask is where that venue establishes priority and how it resolves ties.
Harbor processes one command completely before the next command changes this book. That is a model assumption about logical ordering, not a requirement that every exchange use one thread for its whole business.
Queue position is conditional
S2 has four units ahead of it at $100. That does not mean it will fill after four units trade anywhere in the market.
Those trades must consume the relevant sell queue. Trades at another venue do nothing to this queue. A seller canceling ahead can reduce the quantity before S2 without creating a trade. If B1 is first canceled, a new seller offering $99 can establish a better ask and get considered before the whole $100 level. With B1 still there, that $99 sell would instead cross its bid and trade immediately.
Even a precise queue position cannot guarantee a fill. Buyers may stop arriving. The best available price may move. The order may be amended or removed before it reaches the front.
In Harbor’s fully displayed book, an observer with a complete order-by-order feed could reconstruct the modeled queue. A price-level display showing seven at $100 is insufficient to establish how much is ahead of a specific order.
Editing an order can spend its waiting time
For Harbor, choose this explicit amendment policy:
| Change to an unfilled resting order | Harbor’s priority treatment |
|---|---|
| Reduce quantity, keep price | Keep position |
| Increase quantity, keep price | Move the entire amended order to the back at that price |
| Change price | Join the back of the queue at the new price, if a remainder rests |
| Cancel and submit a new order | New order gets new priority |
Consider S1 and S2 before any fills.
If S1 reduces its four units to two, S1 stays first and S2 now has only two units ahead. If S1 instead increases from four to six, S2 becomes first at $100 and S1 moves behind it. The extra size does not inherit the old place.

Figure 2.2. Under Harbor rules, reducing S1 from four to two retains its place ahead of S2. Increasing S1 from four to six moves the entire amended order behind S2. Bar lengths represent whole units, and each row is an independent reset.
These are deliberate Harbor rules, comparable to Kraken’s documented atomic-amend treatment of quantity and limit-price changes. Kraken also distinguishes that mechanism from its legacy edit operation, which uses cancel-new processing. An interface button labeled Edit does not tell you which operation the venue performs. Kraken spot atomic amends
For a live integration, check whether the quantity field means total order quantity or remaining quantity, particularly after partial execution. Then check which fields retain priority. Keeping an identifier and keeping queue position are separate properties.
Stocks and futures add other ranking rules
Nasdaq’s rulebook describes price/display/time priority. At an equal price, displayed interest takes priority over non-displayed interest; each category has its time ordering. An older hidden order therefore need not beat a newer displayed order at the same price. Our all-displayed Harbor example deliberately avoids that complication. Nasdaq Equity 4, Rules 4756(c)(3)(C) and 4757(a)(1)
CME documents several allocation algorithms, including FIFO and pro-rata combinations. FIFO prioritizes waiting order; pro-rata components allocate according to specified size-based rules. The applicable algorithm depends on the product. Do not infer it from a generic description of “the exchange.” CME matching algorithm overview
These are venue-specific comparisons. We are not adding hidden orders or pro-rata allocation to Harbor halfway through the walkthrough.
A fill discrepancy caused by an edit
Suppose S1’s owner increases its size, believes it kept first place, and sees S2 trade next. The user reports an unfair fill. An operator looks only at the creation timestamps and reaches the same conclusion.
Both miss the amendment.
To reconstruct Harbor’s decision, inspect the initial acceptance, the amendment that reset priority, the resulting queue, and the incoming order that caused the fill. Sorting by original creation time produces the wrong answer after a priority-changing event.
There is another possible outcome: the amendment never succeeded. A local request is not a confirmed book change. The investigation needs the venue’s response and the order’s actual revised parameters.
For an integration, retain the amendment history alongside fills. If an order moves to another price, preserve that new priority event. A creation timestamp alone cannot explain the order’s whole life.
Educational research. Not financial advice.