Sub topic 6
Liquidity risk: thin order books, slippage and illiquid tokens
This chapter assumes you know how to place buy and sell orders on an exchange and can read short Python programs. It builds on the earlier chapters on market risk and drawdowns. Market risk is the chance that the price falls. Liquidity risk is the chance that you cannot trade at the price you see, or cannot trade at all. This is educational material, not financial advice.
What liquidity means
An asset is liquid if you can buy or sell a meaningful amount quickly without moving the price much. Three properties describe it:
- Tightness: the gap between the best buy and sell prices is small.
- Depth: many units are offered near the current price.
- Resilience: the price recovers quickly after a large trade.
The price on a chart is the last trade, and it says little about what a large order will receive. A token can show a market capitalization of 50 million dollars while its order book holds only a few thousand dollars of real buy orders. Market capitalization is the price times the circulating supply, and you cannot sell the whole supply at that price.
Order books and the spread
Most centralized exchanges use an order book. It is a list of resting limit orders. Bids are orders to buy, and asks are orders to sell. The best bid is the highest price a buyer will pay. The best ask is the lowest price a seller will accept. The difference is the spread.
A market order takes whatever is available right now. A limit order names a price and waits. A market buy starts at the best ask. If the order is larger than the size at that price, it moves to the next ask, then the next. This is called walking the book.
Slippage
Slippage is the difference between the price you expected and the average price you got. It is usually quoted as a percentage of the expected price. The spread and slippage together are your cost of trading immediately.
The program below walks a small order book and reports the average fill price for three order sizes.
bids = [(99.5, 4.0), (99.0, 6.0), (97.0, 12.0)] # (price, size)
asks = [(100.0, 2.0), (100.5, 3.0), (101.5, 5.0), (104.0, 10.0)]
def market_buy_average(asks, quantity):
remaining = quantity
cost = 0.0
for price, size in asks:
take = min(remaining, size)
cost += take * price
remaining -= take
if remaining == 0:
return cost / quantity
raise ValueError("Order is larger than the whole book")
best_bid, best_ask = bids[0][0], asks[0][0]
mid = (best_bid + best_ask) / 2
print(f"Spread: {(best_ask - best_bid) / mid:.2%} of the mid price")
for qty in [1, 8, 20]:
avg = market_buy_average(asks, qty)
slippage = avg / best_ask - 1
print(f"Buy {qty:>2}: average {avg:.2f}, slippage {slippage:.2%}")The output is:
Spread: 0.50% of the mid price
Buy 1: average 100.00, slippage 0.00%
Buy 8: average 100.75, slippage 0.75%
Buy 20: average 102.45, slippage 2.45%Slippage grows faster than order size because each extra unit comes from a worse level. Selling works the same way in reverse, walking down the bids. A sell of 20 units here would exhaust the bids entirely, which is why the function raises an error when the book is too small.
Thin books and illiquid tokens
A thin book has little size near the best price. Small and new tokens are often thin for several reasons:
- Few market makers quote them, so spreads are wide.
- A handful of wallets hold most of the supply. If one of them sells, the price drops, and other holders may not find buyers.
- Trading volume is concentrated on one or two venues, so there is no second place to sell.
- Volume may be inflated by wash trading, where the same party trades with itself to look active. Reported volume can overstate real liquidity.
Useful indicators to check before buying:
| Indicator | What it tells you | Warning sign |
|---|---|---|
| Spread | Cost of a round trip | Spread of several percent |
| Depth within 1% to 2% of mid price | How much you can trade cheaply | Depth smaller than your order |
| 24-hour volume relative to market cap | How actively the supply trades | Volume under a fraction of a percent of market cap |
| Number of venues | Whether exits exist elsewhere | One exchange only |
| Holder concentration | Whether a few wallets can move the price | Top wallets hold a large share |
The "paper value" of a position can differ greatly from its exit value. If you hold 100,000 dollars of a token whose bids within 5% of the price total 8,000 dollars, selling all of it would take many hours or days, or would push the price down sharply.
Liquidity in decentralized exchanges
Many decentralized exchanges (DEXs) have no order book. They use an automated market maker (AMM), which holds a pool of two assets and sets the price by a formula. The simplest formula is the constant product rule: the pool's token amount x times its stablecoin amount y stays equal to a constant k. Each trade changes the balance, so the price moves with trade size relative to the pool.
token_pool = 1_000.0
usd_pool = 1_000_000.0
k = token_pool * usd_pool
spot = usd_pool / token_pool # 1000.0 per token
for sold in [1, 10, 100]:
new_tokens = token_pool + sold
new_usd = k / new_tokens
received = usd_pool - new_usd
average = received / sold
impact = 1 - average / spot
print(f"Sell {sold:>3} tokens: average {average:.2f}, price impact {impact:.2%}")The output is:
Sell 1 tokens: average 999.00, price impact 0.10%
Sell 10 tokens: average 990.10, price impact 0.99%
Sell 100 tokens: average 909.09, price impact 9.09%Selling 10% of the pool's tokens costs about 9%. This version ignores trading fees, which add to the cost. The lesson is that pool size relative to your trade determines your price impact. A token with a large market cap but a small pool is still illiquid.
A DEX pool adds one more risk. The people who supplied the pool can withdraw their funds. If they do, liquidity disappears. In the worst scams, the creators withdraw all of it, leaving holders unable to sell.
Liquidity is worst when you need it
Liquidity is not constant. In a sharp sell-off, market makers widen their quotes or pull them to avoid being run over. Bid depth falls at the same moment that many people want to sell. The effects add up:
- Spreads widen, so each trade costs more.
- Depth shrinks, so slippage per unit rises.
- Forced sellers, such as liquidated leveraged traders, push prices down further.
- Exchanges may pause withdrawals or trading under load, or their sites may go down.
The practical result is that drawdowns calculated from chart prices understate your real loss if you must sell in a crisis. Illiquid tokens often fall further and recover later than large coins. This also connects to leverage, covered in the next chapter, because liquidations are forced market orders.
Common errors
- Trusting the quoted price. A displayed price is for one unit, not for your full order.
- Using market orders on thin books. A limit order caps the price you accept, though it may not fill.
- Confusing volume with liquidity. High volume can be wash trading or a short burst of activity.
- Ignoring the exit. Planning only the purchase and not the sale is the usual failure.
- Setting DEX slippage tolerance too high. A wide tolerance lets bots trade ahead of you at a worse price and still have your order succeed.
Reducing liquidity risk
- Compare your order size with the depth near the price before trading.
- Use limit orders, and split large orders into pieces over time.
- Prefer assets and venues with deep books and several exchanges.
- Size positions in small tokens so that you can accept being stuck. The position-sizing chapter covers how to do that.
- For DEXs, check pool size, whether liquidity is locked or can be withdrawn, and how concentrated holders are.
Exercise
Using the ask levels from this chapter ((100.0, 2.0), (100.5, 3.0), (101.5, 5.0), (104.0, 10.0)), you place a market buy of 6 units. What is the average fill price and the slippage relative to the best ask?
Show answer
The order fills 2 units at 100.0 (200), 3 units at 100.5 (301.5) and 1 unit at 101.5 (101.5). The total cost is 603, so the average price is 603 / 6 = 100.50. Slippage is 100.50 / 100.0 - 1 = 0.50%.
Exercise
A DEX pool holds 500 tokens and 250,000 dollars, with no fees. Roughly what price impact would you expect when selling 50 tokens, and why is this a liquidity problem even if the token has a large market cap?
Show answer
The pool's k is 125,000,000. After selling 50 tokens the pool holds 550 tokens and 125,000,000 / 550 = 227,272.73 dollars, so you receive about 22,727.27 dollars. The average price is about 454.55 against a spot price of 500, an impact of about 9.09%. Your cost depends on the pool size, not on the market cap, so a large market cap does not protect you from a small pool.