Lesson 049 min
PRICE · TIME PRIORITY

How Matching Produces a Price

Make orders meet and watch resting prices, partial fills, and the bid–ask spread create a trade.

OBJECTIVESAfter this lesson, you should be able to:
  • Explain execution with price priority and time priority
  • Predict partial fills and the resting order price
COURSE POSITIONStep 4 of 6
  1. PREVIOUSHow Views Enter the Order Book
  2. CURRENTHow Matching Produces a Price

    Make orders meet and watch resting prices, partial fills, and the bid–ask spread create a trade.

  3. NEXT0.70 Is Not a Cosmic Truth
BEFORE YOU READ

Think about these questions first.

Choose an answer before opening the explanation. You can add anything unexpected to your review list.

Q01A buyer accepts 72 and a seller accepts 68. Why can the trade print at 68?
SHORT ANSWER

Many books execute at the resting order’s price. The earlier 68 ask already promised terms; the incoming 72 bid accepts them. This rewards posted liquidity and makes matching replayable.

Compared with your prediction:
Q02Why can one tiny fill change the displayed price for the whole market?
SHORT ANSWER

The last price records the latest marginal meeting, not a resale of every position. Interfaces revalue the market from it, so size, spread, and depth are needed to judge reliability.

Compared with your prediction:

An order book is a set of promises that have not met yet. The matching engine looks for a bid that is at least as high as an ask, then uses public priority rules to turn the pair into a trade.

Best bid, best ask, and spread

Buy orders sort from high to low; the highest is the best bid. Sell orders sort from low to high; the lowest is the best ask. The gap between them is the spread.

If the best bid is 58 and the best ask is 66, neither side accepts the other. A new BUY YES at 70 crosses the 66 ask and creates an executable match.

Matching consolePrice priority · time priority
YES implied price55/ 100

Best bid 45Best ask 65Spread 20

YES order bookPrice / quantity

BIDS

Alice451

ASKS

Bob651
BUY NO @ q appears as SELL YES @ 100−q
Event log3 EVENTS
  1. 03

    Bob submitted: BUY NO 1 shares, max 35 credits.

  2. 02

    Alice submitted: BUY YES 1 shares, max 45 credits.

  3. 01

    Market created: Will humans return to the Moon before 2028?

Watch the best quotes first, then submit an order that crosses the spread. The trade uses the price of the order that was resting earlier.

Why the trade uses the earlier order's price

Suppose Bob's ASK 65 has been resting in the book. Carol later submits BID 70. Any price from 65 through 70 could satisfy both, so the engine needs a deterministic rule.

Here the trade uses the resting order price: Bob committed to 65 first, so Carol crosses the spread at 65. She pays less than her limit and Bob receives the price he made public.

At one price, time decides

If Alice and Carol both bid 65 while Bob offers only 2 shares, the earlier order fills first. Price-time priority works as follows:

  1. Better prices have priority.
  2. Equal prices are ordered by sequence number.
  3. If quantity is insufficient, one order partially fills and the remainder waits.

The same rule also makes the system replayable: identical order input produces identical fills for every verifier.

Expand: how this step works
while bestBid.price >= bestAsk.price:
  maker = earlier(bestBid, bestAsk)
  quantity = min(bestBid.remaining, bestAsk.remaining)
  trade(price = maker.price, quantity)
  lockCollateral(quantity * 100)

After every fill, the engine checks again until the best bid is strictly below the best ask.

KNOWLEDGE CHECK

An ASK 65 rests first. A BUY YES @70 arrives later. What is the usual trade price?

State passed to the next lesson

The market now has trades and a latest price. Next we challenge a common shortcut: a last price of 70 does not mean the world has discovered an objective, permanent 70% probability.

LESSON RECAPComplete the exercise and knowledge check first