Sub topic 3
Limit Orders: Naming Your Price
This chapter assumes you know basic crypto exchange screens, trading pairs such as BTC/USDT, and simple Python. A limit order is an instruction to buy or sell a specific quantity at a price you choose, or at a better price.
Limit orders give you price control. They do not guarantee that your trade will happen.
How a limit order works
Suppose BTC/USDT has this order book:
| Side | Price | Available BTC |
|---|---|---|
| Ask | 100.0 | 2.0 |
| Ask | 100.5 | 3.0 |
| Bid | 99.5 | 4.0 |
A bid is an offer to buy. An ask is an offer to sell. If you submit a limit buy for 4 BTC at 100.2 USDT, the exchange can match only asks priced at 100.2 or lower.
It fills 2 BTC at 100.0. The remaining 2 BTC cannot fill immediately because the next ask is 100.5. That remaining quantity becomes a bid at your limit price of 100.2.
If the market later falls to 100.2, a seller may trade with your order. If the market never reaches that price, the order may remain open or expire, depending on its settings.
A limit order that waits on the book is called a resting order. A limit order that immediately trades with orders already in the book is called a crossing order. A limit order can therefore act like a marketable order while still imposing a worst acceptable price.
For a limit sell, the logic is reversed. It can match bids at or above your limit price. Any unfilled quantity rests as an ask.
Worked example in Python
The function below walks through available asks for a limit buy:
asks = [(100.0, 2.0), (100.5, 3.0), (101.0, 5.0)]
def limit_buy(asks, limit_price, qty):
"""Return immediate fills and quantity that would rest on the book."""
fills = []
remaining = qty
for price, size in asks:
if price > limit_price or remaining == 0:
break
take = min(remaining, size)
fills.append((price, take))
remaining -= take
return fills, remaining
print(limit_buy(asks, 100.2, 4.0))
# ([(100.0, 2.0)], 2.0)
print(limit_buy(asks, 100.5, 4.0))
# ([(100.0, 2.0), (100.5, 2.0)], 0.0)The first order has a 2 BTC remainder. The second order fills completely because its limit includes the 100.5 ask. It does not pay 100.5 for every unit: it pays the available price at each level.
Price-time priority
A matching engine is the exchange component that pairs compatible buy and sell orders. For orders at the same price, it commonly uses price-time priority:
- Better prices execute first. A higher bid has priority over a lower bid. A lower ask has priority over a higher ask.
- At the same price, the order submitted first usually executes first.
This means placing a bid at an already crowded price may leave you waiting behind earlier orders. Cancelling and replacing it can move you to the back of that queue.
When to use a limit order
Use a limit order when controlling price matters more than immediate execution. It can help you:
- Avoid paying above a chosen maximum price.
- Sell only at or above a chosen minimum price.
- Provide liquidity while waiting for another trader to accept your price.
- Reduce unexpected execution during a fast or thin market.
The trade-off is execution uncertainty. A limit order can be partially filled, remain open, or expire without any fill. Check the exchange's minimum quantity, price increment, and order expiration rules before submitting it.
Exercise
The best ask is 100.0 for 1 BTC, and the next ask is 100.5 for 3 BTC. What happens to a limit buy for 3 BTC at 100.2?
Show answer
It immediately buys 1 BTC at 100.0. The remaining 2 BTC rests as a bid at 100.2 and may fill later.