Sub topic 2
Slippage and Market Depth
This chapter assumes you know how an exchange buy and sell screen works, that 1 basis point (bp) equals 0.01%, and that you can read short Python.
Slippage and Market Depth
Slippage is the difference between the price you expected and the average price you actually pay. Market depth is how much an order book holds at each price. A thin book causes more slippage, because a large market buy uses up several price levels.
Suppose the best ask is 100.00 for 2 units, then 100.50 for 3 units. A market buy of 4 units pays 2 at 100.00 and 2 at 100.50, an average of 100.25. That is 25 bp of slippage.
def market_buy_avg_price(asks, qty):
remaining, cost = qty, 0.0
for price, size in asks:
take = min(remaining, size)
cost += take * price
remaining -= take
if remaining == 0:
break
if remaining > 0:
raise ValueError("not enough liquidity")
return cost / qty
asks = [(100.0, 2.0), (100.5, 3.0), (101.0, 5.0)]
best_ask = 100.0
avg = market_buy_avg_price(asks, 4.0)
slippage_bps = (avg - best_ask) / best_ask * 10_000
print(avg, round(slippage_bps, 1)) # 100.25 25.0Instant Buy and Convert: Fees Built Into the Price
An instant buy shows one price with no separate fee line. That price usually includes a markup above the order book price. Compare the quote with the mid price of the book to find the true cost.
Fiat Deposit and Withdrawal Fees
Bank transfers and card deposits carry their own fees. Exchanges set these apart from trading fees, so add them to your total cost when you move money in or out.
What Network Fees Pay For
A network fee pays miners or validators to include your transaction in a block. The fee goes to the network, not to the exchange.
How Fee Markets Set the Price of Block Space
Each block holds a limited amount of data. Users bid with a fee rate, and the highest bids usually confirm first. When demand rises, the going rate rises with it.
Bitcoin Fees: Fee Rate Times Transaction Size
Bitcoin fee equals virtual size (vB) times fee rate (satoshis per vB). A typical 1-input, 2-output native SegWit transaction is about 141 vB. At 10 sat/vB, it costs 1,410 satoshis, or 0.0000141 BTC.
Exercise
Using the same order book, what is the average price of a market buy of 6 units, and what is its slippage in bp?
Show answer
The fills are 2 at 100.00, 3 at 100.50, and 1 at 101.00, totaling 602.50. The average is 602.50 / 6 = 100.42 (about 100.4167). Slippage is (100.4167 - 100.00) / 100.00 × 10,000 ≈ 41.7 bp.