Lesson 0413 min
CANCEL · REPLACE · SELF-TRADE

Why Does a Price Change Rejoin the Queue?

Cancel and reprice an order, then observe time priority reset and self-trade prevention block a false fill.

ObjectivesAfter this lesson, you should be able to:
  • Explain why cancel-replace loses the old time priority
  • Observe self-trade prevention cancel a new remainder
  • Separate risk rejection, cancellation, and a real fill
COURSE POSITIONStep 4 of 4
  1. PREVIOUSWho Leaves the Spread Behind?
  2. CURRENTWhy Does a Price Change Rejoin the Queue?

    Cancel and reprice an order, then observe time priority reset and self-trade prevention block a false fill.

  3. NEXTFree sandbox
BEFORE YOU READ

Think about these questions first.

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

Q01Why lose queue priority when improving an order’s price?
SHORT ANSWER

Changing price changes the promise to the market and creates a new order. Keeping the old timestamp would let traders repeatedly edit while camping at the front of the queue.

Compared with your prediction:

A matching engine must do more than find a counterparty: it must reject unsafe state transitions. Cancel-replace, self-trade prevention, and frozen-asset rules decide whether a quote becomes a fill, a cancellation, or a risk rejection.

Changing price is not editing text

Place a bid at 100, then change it to 102. The system should not mutate the old order in place, because a new price must not inherit old time priority. Release the old frozen balance, close the old order, then enqueue a new order with a new sequence.

ENGINE RUNNINGLAB / credits
ORDERBOOK 001 · PRICE / TIME PRIORITY

LAB / credits

Limit orders enter the queue; only a crossed book turns them into fills.

Last tradecredits / LAB
Best bid98highest buy
Best ask102lowest sell
Spread4ticks
Traded0LAB
CANCEL · REPLACE · SELF-TRADE

Repricing is a new queue entry

Cancel-replace releases the old freeze and re-enters with a new sequence. If the new price crosses the book, self-trade protection still applies.

Current order NoneLast action System state Conserved, no crossing
Live order bookPrice / remaining / source
Asks (SELL)Bids (BUY)
1022A
1023B
1055A
983B
965A
Empty
Best ask: 102Best bid: 98
Coach

Read the book first: best ask is the lowest sell, best bid is the highest buy. Matching starts only when buy price reaches sell price.

Engine events1 EVENTS
  1. 01

    Book created: best ask 102 分(两个价位相同's 订单),best bid 98 .price and time priority must be preserved。

ACTION HISTORYExperiment timeline
1 state snapshots

Use the slider to return to an earlier step. Continuing from there replaces the later history with a new sequence.

Initial state
View experiment records →

Self-trade creates a false signal

If one account has a buy at 100 and a sell at 99, a naive loop lets the account trade with itself. No real risk transfers, but volume and last price change. The lab cancels the newer order’s remaining quantity, releases its freeze, and records the reason.

Expand: how this step works
replace(old, newPrice, newQuantity):
  release(old.remaining)
  close(old)
  new = enqueue(newPrice, newQuantity, nextSequence)
  match(new)

if buyer.trader == seller.trader:
  cancel(new.remaining)
  emit("SELF_TRADE_PREVENTED")

Risk controls are part of the state machine, not a post-processing decoration. Every rejection, cancellation, and fill should be replayable so an auditor can check balances, freezes, and book state.

KNOWLEDGE CHECK

Why must a replacement order receive a new time priority?

LESSON RECAPComplete the exercise and knowledge check first