Sub topic 4
Market Orders: Trading Now at the Available Price
This chapter assumes you understand trading pairs such as BTC/USDT, can read a basic order book, and can follow simple Python. A market order prioritizes execution speed over a guaranteed price. It tells the exchange to trade immediately against the liquidity currently available in the book.
What a market order does
For a market buy, the matching engine takes orders from the ask side, starting with the lowest ask. For a market sell, it takes orders from the bid side, starting with the highest bid.
A market order does not specify the maximum price you will pay or the minimum price you will accept. Its execution price is therefore determined by the resting orders available when the exchange processes it.
Consider this ask side:
| Ask price | Available size |
|---|---|
| 100.00 | 2 |
| 100.50 | 3 |
| 101.00 | 5 |
A market buy for 4 units consumes 2 units at 100.00 and 2 units at 100.50. The average fill price is:
(2 × 100.00 + 2 × 100.50) / 4 = 100.25
The order did not fill entirely at the best ask because only 2 units were available there.
Slippage and market impact
Slippage is the difference between the expected price and the actual average fill price. For a buy, comparing the average fill with the best ask gives:
(100.25 - 100.00) / 100.00 × 100 = 0.25%
The size of the order matters. A small order may consume only the first level. A large order may consume many levels, moving its average price farther from the best quote. This effect is called market impact.
# Ask side: (price, size), sorted from lowest price upward
asks = [(100.0, 2.0), (100.5, 3.0), (101.0, 5.0)]
def market_buy(asks, qty):
remaining = qty
cost = 0.0
for price, size in asks:
take = min(remaining, size)
cost += take * price
remaining -= take
if remaining == 0:
break
filled = qty - remaining
average_price = cost / filled if filled else None
return filled, average_price
filled, average = market_buy(asks, 4.0)
print(filled, average) # 4.0 100.25Execution certainty and limits
A market order usually provides a high probability of immediate execution, but it does not guarantee one price. In a rapidly moving or thin market, the displayed order book can change before your order reaches the matching engine.
If available liquidity is insufficient, exchange behavior varies. The order may receive a partial fill, or the venue may reject or cancel the remaining quantity. Check the exchange's rules rather than assuming every market order behaves identically.
Some exchanges provide a maximum slippage setting or allow a market order to be represented as a protected limit order. These controls reduce unexpected prices but can leave the order unfilled.
Fees and when to use one
A market order normally removes liquidity, so it is charged the exchange's taker fee. The total cost includes both the trading fee and any slippage.
Use a market order when immediate execution matters more than price control, such as closing a risky position quickly. Avoid using a large market order in a thin book without estimating its depth first. For price control, use a limit order instead, accepting that it might not fill.
Exercise
The best ask is 50.00 for 1 unit, and the next ask is 50.50 for 3 units. What is the average price of a market buy for 2 units?
Show answer
It fills 1 unit at each level, so the average price is (50.00 + 50.50) / 2 = 50.25.