Aperiodic/Markets from First Principles
Markets from First Principles/Part 1, How a price is made

Lesson 2 of 10

Why there's a gap

Why does buying cost more than selling at the same moment?

DMBy Daniel and Mark
10 min

So far: People arrive one at a time. Each trades with a note already waiting, at its price, or pins one and waits, and the waiting notes stack into a book with a best bid, a best ask, a spread between them and a mid in the middle (lesson 1).

Look at any book and the best ask is above the best bid. Buy and sell again straight away, and you lose the difference. So why doesn't someone close the gap?

You run the stall

Suppose you run a stall that always quotes both sides: you'll buy a sack a little under the going price of 50 and sell one a little over. People who don't want to wait for their note to be taken come to you instead, and the difference between your two prices is how you get paid. This job is called market making.

Most of your customers just need grain, or need to sell some, and each one earns you your gap. But some have read tomorrow's newspaper. They know the price is about to move by 5 coins, and they only come to you when your price is about to be wrong. Each of them costs you the move minus your gap.

Step 1 of 2

Set your gap and how many customers know tomorrow's price, then open the stall. Watch your ledger fill up.

1.5
20%

The stall is closed. You quote 48.5 to buy and 51.5 to sell. Open the stall and watch who comes.

coins per customer, on average-20246802468your gapbreak-even 1.0

With nobody informed, every customer earns you your gap. Let one customer in five know tomorrow's price, and a gap of 1 only breaks even: you earn 1 from four of them and lose 4 to the fifth. The more customers know something, the wider the gap you need.

Set the gap above break-even and you make money, until another stall across the square quotes a narrower one and takes your customers. With enough competition the gap ends up where market makers just break even: wide where many customers know something, narrow where few do. Lawrence Glosten and Paul Milgrom worked this out in 1985, and it's still where economists start when they explain the spread.

Market makers also charge for holding stock they didn't want and for their own running costs, but the informed customers are why the gap widens when news is coming: everyone knows some of the people trading in the next minute know more than they do.

The maths

With a gap h either side of the price, a share π of informed customers and a news move J larger than the gap, the stall earns on average, per customer:

(1 − π) · h − π · (J − h) = h − π · J

It breaks even when the gap is h = π · J.

Bitcoin's gap, in basis points

In the bar from lesson 1, the gap on Binance's bitcoin perpetual was 10 cents on a coin worth 103,805.65 dollars. A basis point is a hundredth of a percent, so that's 0.0096 basis points. Ten cents is the smallest step this market allows, so at that moment nobody could have quoted a narrower gap.

The Cost Index is this number, the spread in basis points, as a median over the last day, for every perpetual we cover. Its board puts bitcoin next to thinner markets, where the gap is wider. Every bar's spread is in ƒL1 Liquidity.

Binance BTC-USDT perpetual, the five-minute bar from 14:00 UTC on 14 May 2025, from Aperiodic's free sample. Prices in US dollars; each value is the book's state at the end of the bar.

A better mid

The mid price treats both sides of the book as equal. They often aren't. If ten people wait to buy at 49 and two wait to sell at 51, the next trade is far more likely to clear out the two sellers than the ten buyers, and once the sellers are gone the best ask moves up.

So a better guess at the fair price leans toward the thin side. Weight each side's price by the size waiting on the other side and you get the weighted mid. Drag the queues and watch it move.

Step 2 of 2

Drag the two queues. Watch the weighted mid lean toward the shorter one.

4849505152weighted mid 50.67mid 50
10
2
Live: Weighted mid 50.67
Mid
50.00
Weighted mid
50.67
Imbalance
+8

With 10 waiting to buy at 49 and 2 waiting to sell at 51, the weighted mid is 50.67: closer to 51, the side that is about to run out.

The difference between the sizes on the two sides is the book's imbalance. Martin Gould and Julius Bonart found that the imbalance at the best prices predicts the direction of the next price move.

The maths

With best bid b and best ask a, and sizes B and A waiting at them:

weighted mid = (b · A + a · B) / (A + B), imbalance = B − A

Bitcoin's queues

SidePriceWaitingIn dollars
best ask103,805.77.712 BTC$800,550
best bid103,805.67.266 BTC$754,251

In the same bar, 7.266 bitcoin waited at the best bid and 7.712 at the best ask: an imbalance of -0.446 bitcoin, a slight lean toward the sellers. With a spread of one step, the weighted mid comes to 103,805.65, the mid to the cent. Every bar's imbalance is in ƒL1 Imbalance, and its weighted mid in ƒL1 Price.

Binance BTC-USDT perpetual, the five-minute bar from 14:00 UTC on 14 May 2025, from Aperiodic's free sample. Prices in US dollars; each value is the book's state at the end of the bar.

What you learned

Market making
Quoting a price to buy and a price to sell at once, and earning the gap between them.
Informed customers
Customers who know where the price is going. They trade only when the quote is about to be wrong.
Break-even gap
The gap where a market maker earns nothing. It grows with the share of informed customers and the size of the move.
Weighted mid
Each side's price weighted by the size waiting on the other side. It leans toward the thin side.
Imbalance
The size waiting to buy minus the size waiting to sell at the best prices.

Check yourself

  1. 1. One customer in five knows tomorrow's price, which will move by 5 coins. Which gap breaks even?

  2. 2. Ten people wait to buy at 49 and two wait to sell at 51. Where is the weighted mid?

  3. 3. News is coming, and more of the people trading know something. What happens to the spread?

Lesson 2 of 10.

Next

Lesson 3: Who's pushing

Every trade has a buyer and a seller. Which one moved the price, and was it a crowd or one big player?

Read lesson 3All lessons

Your progress stays in this browser. A free account keeps it on any device and lets you pull the data behind these lessons yourself: every metric for 2025 on BTC, ETH, SOL and 10 RWA perps, on an API key of your own. Get the data

Read every lesson on one page

10 min left
  1. Why there's a gap
  2. You run the stall
  3. A better mid
  4. What you learned
  5. Check yourself
Aperiodic

Built from hundreds of terabytes of raw data and distilled into point-in-time metrics you can pull as parquet files. Plus the raw trades, quotes and derivatives data behind them.

Use Cases
  • Improve your backtest
  • Find new alpha
  • Execute smarter
Indices
  • All indices
  • Aperiodic Cost Index
  • Aperiodic Depth Index
  • Aperiodic Impact Index
Metrics
  • Metrics library
  • Data Catalog
  • Free data
  • Live markets dashboard
  • Every perp, A–Z
  • Global Liquidity
  • Unusual activity
  • Order Flow
  • L1 & L2
  • Derivatives
  • RWA
  • Live funding rates
  • Raw Data
Developers
  • Docs
  • API Docs
  • MCP Server
  • Notebooks
  • Integrations
  • For AI Agents
  • Atlas Security Master
  • TParquet
  • Binance OI history API
  • OKX history APIs
  • Pre-flight
  • Changelog
  • Roadmap
  • llms.txt
Learn
  • Markets from First Principles
  • Replays
  • Microstructure Guide
  • Architecture
  • Research Blog
  • FAQ
Compare
  • All vendors
  • Pricing compared
  • vs. Tardis
  • vs. CoinGlass
  • vs. Kaiko
  • vs. Amberdata
  • vs. Crypto Lake
  • vs. Laevitas
  • vs. Coinalyze
  • vs. Binance public data
  • vs. Hyperliquid data
  • Binance archive
  • Hyperliquid data
Company
  • Team
  • Pricing
  • Contact
  • Book a call
  • Terms of Service
  • Privacy Policy
  • Licensing
  • SLA

© Copyright 2026 Aperiodic. All Rights Reserved.

Aperiodic Limited · Registered in Ireland · Company No. 815273 ·
136 Capel Street, Dublin D01 T2C9, Ireland