Small Group Tutorials

Here to help students catch up, keep up, and move ahead. Book a consultation here.

How Electronic Market-Matching Algorithms Allocate Trades: Price Priority, FIFO, Pro-Rata, Auctions, Rounding and Tie-Breakers

Reader question: If several buyers and sellers are willing to trade at compatible prices at the same time, how does an electronic exchange decide which orders trade, how much each receives, and at what price — without letting allocation become arbitrary?

The short answer is that an exchange runs a rule-governed state machine. It maintains an order book, identifies prices that can trade, applies price priority, and then uses a product-specific allocation algorithm such as first-in-first-out (FIFO), pro-rata, or a documented hybrid to divide executable quantity among resting orders. At an opening or closing auction, a different algorithm may select one clearing price by maximising executable volume and then applying explicit tie-break rules.

The central mathematical idea is not “predict the market.” It is deterministic allocation under constraints: given the same valid starting state, the same ordered event stream and the same rule configuration, the engine should produce the same trades.

What this page owns — and what it does not

This page owns the mathematics and computational logic of order matching and trade allocation. It does not replace the page on market-making algorithms, which asks how a liquidity provider chooses quotes and manages inventory; market-surveillance algorithms, which look for suspicious behaviour; securities-settlement algorithms, which take over after execution; or transaction reconciliation, which checks records afterwards.

This is public computational-finance education. It is not an execution strategy, a recommendation for order placement, or personalized financial advice.

The order book is a state, not a list of predictions

A simplified limit order book contains bids to buy and offers to sell. Each resting order can be represented by fields such as:

o = (side, price, remaining quantity, priority state, timestamp or sequence number, order attributes).

For an ordinary buy limit order, a higher price is more aggressive: the buyer is willing to pay more. For an ordinary sell limit order, a lower price is more aggressive: the seller is willing to accept less.

If the highest bid remains below the lowest offer, no ordinary limit-order match exists. If an incoming order crosses the opposite side, the engine determines the best executable price level and then allocates quantity according to the venue’s rules.

First rule: better price normally comes before worse price

Suppose the sell book contains:

Offer price Resting quantity
100.00 40
100.01 70
100.03 90

An incoming buy order for 50 units with a limit of 100.03 can execute against all three price levels, but it should not skip the 100.00 offer to fill a worse-priced 100.03 offer first under an ordinary price-priority design.

The first 40 units therefore consume the best offer at 100.00. Ten units remain. The engine then proceeds to the next executable price level, 100.01.

This is price priority. The more difficult allocation problem starts when several resting orders share the same price.

FIFO: time breaks the tie

Under a pure FIFO or price-time allocation rule, orders at the same price are queued by priority time or sequence. The earliest resting order receives executable quantity first, then the next, and so on.

Suppose three sell orders rest at 100.01:

Order Arrival sequence Quantity
A 1 20
B 2 30
C 3 50

An incoming buyer needs 35 units at that price. FIFO gives 20 to A, then 15 to B. C receives nothing from this match.

The algorithm can be written as a simple loop over the priority queue:

filli = min(qi, Qremaining)

and then:

Qremaining ← Qremaining − filli.

Stop when the aggressing quantity is exhausted or the price level has no remaining liquidity.

Why “timestamp” is more subtle than a wall clock

A matching engine needs a total ordering of accepted events. Two network messages can arrive extremely close together; distributed clients may also have unsynchronised clocks. Exchanges therefore cannot safely let each trader’s local computer declare its own queue position.

The authoritative system needs its own sequencing or priority mechanism. Product rules also specify what happens when an order is modified. Increasing size, changing price, refreshing displayed quantity or other amendments can preserve or lose priority depending on the venue and order type.

This gives us a key diagnostic principle: priority is an exchange-defined state variable, not merely the visible time printed on a trader’s screen.

Pro-rata: divide by displayed or working size

FIFO rewards being earlier. A pro-rata algorithm instead allocates a match approximately in proportion to the quantities of eligible resting orders at the price level.

If eligible orders have quantities q1, …, qn and incoming executable quantity is Q, a basic ideal allocation is:

ai* = Q × qi / Σqj.

But real contracts generally trade in whole units or lots. If the result is 7.83 contracts, the engine cannot allocate 0.83 of a contract. A documented rounding rule is therefore part of the matching algorithm, not a trivial implementation detail.

A small pro-rata example

Suppose three eligible resting orders at the same price have quantities 20, 30 and 50. Their total is 100. An incoming order can execute 37.

The ideal proportional shares are:

  • A: 37 × 20/100 = 7.4;
  • B: 37 × 30/100 = 11.1;
  • C: 37 × 50/100 = 18.5.

If the rule rounds each initial allocation down to whole lots, the first pass gives 7 + 11 + 18 = 36. One lot remains unallocated.

That remaining lot needs another rule. It might go through FIFO, a leveling step, another documented allocation stage, or some other venue-specific residual process. Without that rule, “pro-rata” is incomplete.

CME Globex shows why matching algorithms are sequences of steps

CME Group’s public Globex documentation describes multiple matching algorithms rather than one universal rule. Its supported set includes FIFO, pro-rata and configurable or hybrid constructions. CME describes matching as determining executable prices and quantity at the best price, then allocating that quantity according to the product’s market algorithm.

Its public algorithm-step documentation is especially instructive: an allocation algorithm can contain TOP, pro-rata, FIFO, lead-market-maker and leveling stages in a specified sequence. Pro-rata allocations are rounded down, so a later step is required to allocate residual quantity.

This is the deeper computational lesson. A production matching rule is often not one formula. It is a pipeline of allocation operators applied to the remaining quantity:

Q0 → step 1 → Q1 → step 2 → … → Qk = 0

or until no executable resting quantity remains.

Why hybrid rules exist

Different markets value different incentives. FIFO strongly rewards early queue position. Pro-rata gives larger displayed orders a larger share of incoming flow. Hybrid rules can combine incentives for price improvement, displayed liquidity, designated market making and time priority.

There is no theorem saying one allocation rule is universally best. The choice affects market behaviour. Participants adapt their displayed quantities, cancellation patterns and queue-management decisions to the rule, so mechanism design and trader incentives interact.

That interaction is also why changing a matching rule is not merely a software refactor. It can change economic behaviour even if the set of permissible prices and order types remains unchanged.

Continuous matching and auctions solve different problems

Continuous trading processes incoming events one after another. An opening or closing call auction accumulates interest and then searches for a single clearing price at a specified event time.

Suppose candidate price p implies:

B(p) = total buy quantity willing to trade at p or higher

and:

S(p) = total sell quantity willing to trade at p or lower.

The maximum executable volume at that price is:

M(p) = min(B(p), S(p)).

A natural auction objective is to choose a price maximising M(p). But multiple prices can maximise the same executable volume, so an auction needs explicit tie-break rules.

Nasdaq’s Cross makes tie-breaking visible

Nasdaq describes its Opening and Closing Crosses as single-price price-discovery facilities. Its published FAQ explains a sequence for determining the Cross price that begins by:

  1. maximising the number of shares executed;
  2. minimising the imbalance of Cross orders; and
  3. minimising the distance from the Nasdaq inside bid-ask midpoint.

The exact production rulebook contains additional definitions and order-type details, but the mathematical structure is clear: optimise one criterion, then use secondary criteria to break ties.

This is lexicographic optimisation. Candidate prices are not averaged together. They are ranked through an ordered decision rule.

A toy auction example

Suppose three candidate prices all execute 1,000 shares. The first criterion cannot distinguish them. One candidate leaves a 500-share imbalance, another 100, and another zero. The zero-imbalance candidate wins under the second criterion.

If two candidates still tie, the next rule compares their distance from the relevant reference price or midpoint. The important point is not the toy numbers but the architecture: ties are resolved by rules defined before the auction sees the actual outcome.

Inputs and outputs

A matching engine can require inputs such as:

  • order side, price and quantity;
  • order type and time-in-force;
  • displayed and hidden quantity where supported;
  • product-specific matching-algorithm configuration;
  • exchange-assigned priority or sequence state;
  • minimum allocation parameters;
  • auction eligibility flags;
  • market status such as continuous, pre-open, halt or close;
  • reference prices and imbalance data used by an auction; and
  • cancellation, modification and self-match-prevention instructions where applicable.

Outputs should include execution price, allocated quantity for each order, remaining quantity, updated priority state, trade identifiers, order-status changes and an auditable event sequence.

Core invariants: simple checks that catch deep mistakes

Quantity conservation. For a match, total buyer execution must equal total seller execution.

No overfill. An order cannot execute more than its eligible remaining quantity.

Limit-price protection. A buy limit order should not execute above its permitted limit; a sell limit order should not execute below its permitted limit, subject to the exact order and auction rules.

Priority consistency. If FIFO applies to two otherwise equivalent resting orders, the later one cannot consume quantity that the earlier eligible order should have received.

Allocation closure. If pro-rata rounding leaves residual executable quantity and the rule specifies a residual step, that quantity must be routed through the next step rather than disappearing.

Deterministic replay. The same initial state, ordered valid input events and rule version should reproduce the same fills.

Evidence polarity: what supports confidence?

Evidence for a correct matching implementation includes deterministic replay, agreement with published exchange examples, conservation of quantity, correct price-level traversal, stable queue ordering, exact reproduction of pro-rata rounding and residual rules, and auction results that satisfy the stated primary and tie-break objectives.

Evidence against confidence includes unexplained nondeterminism; negative remaining quantity; fills at worse price levels while better eligible liquidity remains; residual lots that vanish; order modifications that retain or lose priority contrary to the rulebook; auctions selecting a price that does not maximise executable volume when that is the stated first objective; or replay logs that cannot reproduce a disputed execution.

Counterexample: “same price means equal treatment” is false

Two orders can rest at the same visible price and still receive very different allocations. Under FIFO, the earlier order can receive the entire match while the later order receives nothing. Under pro-rata, both can receive fills based on size. Under a hybrid, a top-priority or designated participant stage can run first.

So price equality does not imply allocation equality. The market’s priority rule is part of the contract between venue and participant.

Counterexample: pro-rata does not eliminate priority

It is tempting to describe pro-rata as “everyone shares proportionally.” Real implementations may include minimum allocations, priority orders, designated market-maker allocations, rounding, leveling or FIFO residual stages.

CME’s public documentation is a direct counterexample to the oversimplification. The word pro-rata can describe one stage inside a larger matching algorithm rather than the entire allocation rule.

Counterexample: more displayed size can change the system around the formula

In a simple pro-rata formula, increasing displayed quantity increases ideal allocation share. But that does not mean continuously posting the largest possible order is a free advantage. Larger displayed size can carry market risk, information leakage, cancellation constraints, position consequences and surveillance implications.

The allocation formula is therefore not a trading recommendation. It is only one mechanism in a larger market and risk system.

Hidden and refreshed quantity make state more complicated

Some venues support reserve, iceberg or display-quantity orders. The visible size can be smaller than the total quantity. When displayed quantity is exhausted and refreshed, the exchange’s rulebook determines how the refreshed portion is prioritised.

This creates an important test case: an implementation must not assume that “order creation time” is the only priority timestamp that can ever matter. Priority state can evolve after partial fills, refreshes or modifications.

Rounding is part of the economics

Suppose hundreds of small orders each earn an ideal pro-rata share below one lot. Rounding all of them down can allocate nothing in the pro-rata stage. A minimum-allocation parameter can exclude tiny calculated shares. A later FIFO or leveling rule can then distribute the residual quantity to a much smaller subset of orders.

Two mathematically similar proportional formulas can therefore produce different realised fills once integer constraints and residual rules are applied. Any analysis that stops at continuous fractions is incomplete.

Latency is not the same thing as matching priority

Low latency can affect when an order reaches the venue, but the matching engine still applies its own acceptance, sequencing and priority rules. A participant’s send time, network arrival time, gateway processing time and authoritative book-priority state are not interchangeable concepts.

This distinction is essential for diagnostics. If a participant claims “my message was sent first,” the relevant question for queue allocation is whether the venue accepted and sequenced it first under the applicable rules.

Failure modes and weak links

Event-order race. Different processing threads observe events in inconsistent orders and produce nondeterministic book states.

Wrong priority reset. An order modification incorrectly preserves or destroys queue position.

Integer-rounding leak. Pro-rata fractions are rounded but residual quantity is not passed onward correctly.

Stale product configuration. A product is matched using the wrong algorithm or parameter set after a rule change.

Hidden-quantity bug. Displayed and reserve states are confused, producing incorrect allocation or public-book quantities.

Price traversal bug. The engine skips executable better-priced liquidity.

Auction tie-break bug. Candidate prices tie on the primary objective but are resolved using the wrong secondary metric.

Self-match-control interaction. Preventing or modifying a potential self-match can alter available quantity and subsequent allocations; testing must include the venue’s exact rule rather than assuming the ordinary path still applies unchanged.

Replay gap. The audit log lacks enough state or configuration information to reproduce an execution after the fact.

Diagnostics: test the mechanism, not only final trade counts

  • Single-order test: one resting order and one compatible aggressor should produce the obvious fill.
  • Price-priority test: place liquidity at several prices and verify better prices are consumed first.
  • FIFO tie test: use equal-price orders with known acceptance sequence and exhaust only part of the queue.
  • Pro-rata exact-divisibility test: choose quantities that create whole-number allocations.
  • Pro-rata rounding test: deliberately create fractional allocations and verify the documented residual stage.
  • Minimum-allocation test: put calculated shares just below, exactly at and just above the configured threshold.
  • Modify-order test: change price and quantity in ways that should preserve or reset priority and verify each case.
  • Display-refresh test: exhaust displayed quantity and verify reserve refresh and priority treatment.
  • Replay test: process the same event sequence independently and compare every state transition.
  • Auction brute-force test: enumerate every candidate clearing price in a small book, compute executable volume and imbalance directly, and compare the engine’s selected price.
  • Conservation test: sum all executions and remaining quantities before and after every event.
  • Configuration-version test: replay an old event stream with the historical rule version and confirm the result differs from a new rule only where expected.

What would falsify confidence?

Confidence in the implementation should be withdrawn if the same event log produces different trades on repeated replay; if fills violate price or quantity constraints; if FIFO results contradict authoritative sequence; if pro-rata residuals vanish; if a product uses an allocation configuration inconsistent with the exchange reference data; if an auction price fails the documented lexicographic objectives; or if a disputed execution cannot be reconstructed from preserved state and rule versions.

Alternatives are market designs, not merely coding styles

Price-time, pro-rata, size priority, designated-market-maker preferences and hybrid schemes change the incentive structure of the order book. Call auctions differ from continuous matching because they pool orders across a time interval and solve a clearing-price problem. Request-for-quote systems, dealer markets and bilateral negotiation solve different matching problems again.

The correct algorithm therefore depends on the market mechanism being implemented. Replacing FIFO with pro-rata while calling the behaviour “equivalent” would be like changing the rules of a queue and claiming only the software changed.

How this connects to the surrounding knowledge estate

Matching is the execution hinge between intention and post-trade reality. A market maker decides what orders or quotes to expose; the matching engine decides which compatible orders become trades; surveillance interprets the event stream for misconduct signals; settlement turns executed obligations into final transfers; and reconciliation checks whether records agree. These are connected layers but not interchangeable owners.

Verification and update triggers

Preserve the exchange or venue, product, matching-algorithm identifier, parameter set, order-type rules, priority-reset rules, auction rules, effective date, software version and event-sequencing format. Revalidate after an exchange rule filing or matching-parameter change, introduction of new order types, changes to reserve-order behaviour, gateway or sequencing redesign, auction methodology updates, precision or lot-size changes, surveillance-control changes that affect order handling, or any production incident involving disputed priority or allocation.

Primary and high-quality references

Educational boundary: This article explains public exchange mechanism design and matching mathematics. It does not advise how to place, size, time or cancel real orders and does not provide personalized investment or trading advice.

Discover more from Bukit Timah Tutor

Subscribe now to keep reading and get access to the full archive.

Continue reading