Reading the Order Book: Market Microstructure Basics

🌐 한국어

Most beginners watch the chart—the past, already executed. But what the market wants right now lives in the order book: intent that hasn't been executed yet. Once I started handling depth data in a bot, I began seeing things the chart alone never showed.

⚠️ This article is for educational and informational purposes. Reading the order book does not guarantee returns, and you alone are responsible for any losses.

1. Anatomy of the Order Book

The order book is a list of resting orders from people who want to buy (bids) and people who want to sell (asks). Korean brokerage real-time feeds typically give you ten levels on each side along with the size resting at each.

          price       size

Ask 10    10,050      1,200

 ...

Ask 2     10,010        800

Ask 1     10,005        300   ← buy now and you fill here

------- spread of 5 -------

Bid 1     10,000        500   ← sell now and you fill here

Bid 2      9,995        900

 ...

Bid 10     9,955      2,000

A real-time bot parses and holds that data like this—pulling the best ask, the best bid, and the size at each out of the KIS WebSocket depth feed (H0STASP0).

type RealtimeQuote struct {

    AskPrice float64 // best ask (what you pay to buy)

    BidPrice float64 // best bid (what you get to sell)

    AskQty   int64   // size resting at the best ask

    BidQty   int64   // size resting at the best bid

}

2. The Spread — A Floor on Transaction Cost

Spread = best ask − best bid. Buy now and sell immediately and you're down by exactly that much. The spread is therefore the minimum cost of a round trip, and the first measure of an instrument's liquidity.

spread := q.AskPrice - q.BidPrice

spreadPct := spread / q.BidPrice * 100

// Skip short-term entries outright when the spread is wide

if spreadPct > 0.30 {

    // Insufficient liquidity — execution cost eats the edge

    return skip

}

A tight spread (large caps, major ETFs) means you can move in and out cheaply at any time. A wide one (small caps, thin volume) means you're already behind the moment you enter.

3. What Resting Size Tells You — and How It Lies

If bid size is thicker than ask size, you can read it as buying pressure waiting. Order book imbalance is a hint about short-term direction.

imbalance := float64(q.BidQty-q.AskQty) / float64(q.BidQty+q.AskQty)

// near +1 → bid-side dominance, near -1 → ask-side dominance

But resting size is not a promise. A queued order can be cancelled at any moment, and size that looked like a solid wall sometimes evaporates right before it would have been hit (spoofing). So treat size as a supporting signal, never as sole justification. The flow of size building and clearing is more trustworthy than any single snapshot.

4. How a Bot Uses Depth

For a bot, the order book has three practical uses.

  • Estimating the real fill price: signals fire off the last price, but what you actually pay is the best ask. The bot uses AskPrice and BidPrice to compute the true entry cost up front. In arbitrage, that one-tick difference is the line between profit and loss.
  • Liquidity gate: if the spread is wide or the size at the best level is thinner than your order, skip the entry. Even a "good signal" is declined when it sits somewhere you can't get out of.
  • Order sizing: fit the quantity inside the size resting at the best level and slippage is minimized (covered in the slippage and fill quality article).
// Recompute the gap using the real fill price, not the last price

if q != nil && q.AskPrice > 0 && q.BidPrice > 0 {

    askNavGap = (q.AskPrice - nav) / nav * 100.0 // basis for buying

    bidNavGap = (q.BidPrice - nav) / nav * 100.0 // basis for selling

}

Summary

  • The chart is the past; the order book is present intent — a bot watches both
  • The spread is the minimum cost of a round trip and the first indicator of liquidity
  • Size imbalance is a hint, but it can be faked through cancellation and spoofing — read the flow instead
  • Bots use depth to decide real fill price, liquidity gating, and order size

Reading the order book isn't about predicting the future. It's about seeing honestly the actual terms on which you can buy and sell right here, right now. That honesty is what narrows the gap between backtest and live trading.

댓글

이 블로그의 인기 게시물

한국투자증권 KIS API로 실시간 시세 받기 (WebSocket 실전)

파이썬으로 업비트 API 연동하기 — 시세 조회부터 주문까지 기초

Go로 자동매매 신호봇 프레임워크 설계하기