What is the bid-ask spread? The cost your bot pays every trade
The bid-ask spread is the most overlooked cost in automated trading. It is the small gap between the best price to buy and the best price to sell — and every time your bot crosses it with a market order, you pay it. On a deep market it is tiny; on a thin one, or for a high-turnover bot, it quietly becomes the single biggest drag on returns, often larger than exchange fees. This guide explains why the spread exists, why high-frequency strategies die on it, and how to measure and minimise it with code.
What the bid-ask spread is
The bid is the highest price a buyer will pay; the ask is the lowest price a seller will accept. The spread is the gap between them. If BTC shows a bid of 60,000 and an ask of 60,006, the spread is 6 — and a market buy fills at the ask while a market sell fills at the bid, so a round trip costs you the spread before the price moves at all.
Why the spread exists
The spread is the market maker’s compensation for providing liquidity and bearing inventory risk. Tight competition and deep liquidity shrink it; thin markets and uncertainty widen it. It is the price of immediacy: you pay the spread to trade right now instead of waiting in the book.
The cost you actually pay
A 0.05% spread sounds trivial — until a bot trades 20 times a day. That is roughly 1% a day lost to the spread alone, before fees and slippage. The more often you cross the spread, the more it dominates your P&L, which is why high-turnover strategies need an enormous gross edge just to break even.
Why high-frequency bots die on it
A scalping or HFT strategy aims for tiny per-trade gains, so the spread can be larger than the profit it targets. Unless the bot is a maker (posting limit orders and earning the spread rather than paying it), the spread is fatal. This is why retail high-frequency bots almost always lose.
How to minimise it
Trade liquid pairs with tight spreads, use limit orders to join the book as a maker instead of crossing as a taker, trade less often so the spread is amortised over a larger move, and avoid thin markets and volatile news windows when spreads blow out.
Measuring the spread in code
python · spread.pyimport ccxt
ex = ccxt.binance()
book = ex.fetch_order_book('BTC/USDT')
bid = book['bids'][0][0]
ask = book['asks'][0][0]
spread_pct = (ask - bid) / ((ask + bid) / 2) * 100
print(f'spread: {spread_pct:.4f}%')
if spread_pct > 0.1:
print('spread too wide — skip this trade')
Always include the spread in your backtest cost model — ignoring it is the fastest way to turn a losing strategy into one that only looks profitable.
Frequently asked questions
What is the bid-ask spread?
The bid-ask spread is the gap between the highest price a buyer will pay (the bid) and the lowest price a seller will accept (the ask). A market buy fills at the ask and a market sell fills at the bid, so completing a round trip costs you the spread before the price moves at all. It is a guaranteed, often-overlooked cost.
Why does the bid-ask spread exist?
The spread compensates market makers for providing liquidity and bearing inventory risk. It is the price of immediacy — you pay it to trade right now instead of waiting in the order book. Deep liquidity and tight competition shrink the spread, while thin markets, low volume and uncertainty widen it.
How does the spread affect a trading bot?
It is a per-trade cost that compounds with turnover. A 0.05% spread is trivial once, but a bot trading 20 times a day can lose around 1% daily to the spread alone, before fees and slippage. High-turnover and scalping strategies often target profits smaller than the spread, which is why they usually lose unless they post maker orders.
How do I minimise the bid-ask spread cost?
Trade liquid pairs with naturally tight spreads, use limit orders to join the book as a maker and earn the spread instead of paying it, trade less frequently so the spread is amortised over a larger move, and avoid thin markets and volatile news windows when spreads blow out. Always model the spread in your backtest.