The Runtime Theory
SystemFoundationsexecution

Trace a Market Order Execution

Follow a market order as it arrives at the exchange, matches against the top of the order book, and produces a trade.

The Runtime Theory Team1 min read10 steps

trace spine

  1. 01 Trader submits a market order to buy 100 shares
  2. 02 Broker routes the order to the exchange matching engine
  3. 03 Matching engine receives the order into its memory
  4. 04 Engine checks the order book for the best available ask
  5. 05 Best ask at 100.05 × 30 shares — order matches
  6. 06 Engine fills 30 shares at 100.05 (remaining 70)
  7. 07 Engine moves to the next ask level at 100.06 × 200 shares
  8. 08 Engine fills 70 shares at 100.06 (order complete)
  9. 09 Trade records are written to the exchange's log
  10. 10 Confirmation sent back to the trader
▸ On this page

Trace: A Market Order Is Executed

The Flow

plaintext
Trader → Broker → Exchange → Matching Engine → Order Book → Trade Log → Confirmation

Step by Step

  1. Trader submits order — A trader's algorithm sends a market order: "BUY 100 shares of AAPL immediately."

  2. Broker routes the order — The broker acts as an intermediary, forwarding the order to the exchange via a low-latency network connection.

  3. Matching engine receives order — The exchange's matching engine (a high-performance C++ program) loads the order into memory.

  4. Engine checks the order book — The engine looks at the ask side (lowest sell orders first):

    • Level 1: 100.05 × 30 shares
    • Level 2: 100.06 × 200 shares
  5. First match — The market order buys all 30 shares at the best ask of 100.05. Remaining: 70 shares.

  6. Second match — The market order buys 70 shares at the next ask price of 100.06. Order is now complete.

  7. Trade log is written — Two fills are recorded:

    • 30 shares @ 100.05 = $3,001.50
    • 70 shares @ 100.06 = $7,004.20
    • Total: 100 shares for $10,005.70
  8. Confirmation sent back — The trader's system receives a confirmation: "BUY 100 AAPL at avg price 100.06."

Key Takeaways

  • A market order always fills at the best available prices.
  • Large orders sweep through multiple price levels — this is called market impact or slippage.
  • The matching engine must be fast — every millisecond matters in high-frequency trading.

Not started

Sign in to save your learning progress.

Sign in to save