Aperiodic/Markets from First Principles

All 10 lessons on one page · One lesson per page

Markets from First Principles

How markets work, from a village market square to perpetual futures and the data behind them. Every figure is one you can play with.

By Daniel and Mark

Lesson 1 of 10

From a square to a book

What happens when a crowd wants to trade, and they can't all be there at the same time?

12 min

Market day

Every trade needs a buyer and a seller whose prices overlap. Each has a limit: the most the buyer will pay, the least the seller will take. When the buyer's limit is at or above the seller's, some price suits them both and they can trade. When it is below, no price does.

Now it's market day. Through the day, 22 people come into the square one at a time, buyers through one gate and sellers through the other, each wanting to buy or sell a sack of grain, each with their limit.

Nobody haggles. In the middle of the square, people who are waiting stand in line with a note saying their price. Whoever arrives reads the notes. If a waiting note suits their limit, they trade with its owner at once, at the price on the note. If none does, they join the line at their own price and wait.

Step 1 of 4

Let people in one at a time. Each one either trades the moment they arrive, or has to wait. Watch who, and at what price.

Nobody here yet. 22 people will come in one at a time, each with the most they'll pay or the least they'll take.

The first seller found nobody and waited at 47. The next person, a buyer who would have paid 60, bought at 47: the price was set by whoever was already waiting. By evening six sacks have changed hands, at prices from 47 to 52, and ten people are still in line.

This is how the markets in this guide trade, around the clock. Orders arrive one at a time, and each one either trades with an order that is already waiting or waits itself. There is no single price for the day: each trade has its own, set by whoever was waiting.

Taking and making

Here are the notes the day left on the board: five to sell and five to buy. Arrive in a hurry and you don't need to wait. Read the board and take the best note: the cheapest sell note if you want to buy, the highest buy note if you want to sell.

Step 2 of 4

How many sacks do you need right now? Pick a number and buy them. Then see what being in a hurry cost you.

Notes to sell
58sell 1
55sell 1
54sell 1
53sell 1sell 1
spread 2 · mid 52
51buy 1
50buy 1buy 1
48buy 1
45buy 1
Notes to buy
3

Nothing bought yet. The ringed notes are the ones you would take: the cheapest first. The mid is 52.

Whoever takes a note is a taker: they pay the price on the board for not having to wait. Everyone who traded on market day was a taker, the moment they arrived. You can also be on the other side, and wait, with a note of your own.

Step 3 of 4

Pin a note to buy one sack at your price, then let the hours pass. See how long you wait, and what you pay compared with buying in a hurry.

Notes to sell
58sell 1
55sell 1
54sell 1
53sell 1sell 1
spread 2 · mid 52
51buy 1
50buy 1buy 1
48buy 1
45buy 1
Notes to buy
51

No note pinned. Pick your price and pin it. Then let the hours pass until someone in a hurry sells to you.

Whoever leaves a note is a maker: they make the board, and they wait for a taker. Notes at the same price are taken in the order they were pinned, so being early counts. Many exchanges charge makers a lower fee than takers (Hyperliquid's fee schedule is one example), because the notes on the board are what let anyone trade at all.

The book

Pin up thousands of notes and the board is too long to read one by one. Add up the notes at each price and you get the order book: the buy notes on one side, called bids, and the sell notes on the other, called asks.

Step 4 of 4

Switch from the notes to the book. The four numbers underneath are what the book tells you.

Notes to sell
58sell 1
55sell 1
54sell 1
53sell 1sell 1
spread 2 · mid 52
51buy 1
50buy 1buy 1
48buy 1
45buy 1
Notes to buy
Live: Ten notes, one card each
Best bid
51
Best ask
53
Spread
2
Mid
52

Switch to the book to see the notes added up at each price.

The highest bid is the best bid, the lowest ask is the best ask, and the gap between them is the spread. The point halfway between is the mid price: one number for where the market stands between trades.

The maths

A buyer with limit L arrives at a book whose best ask is a. A seller with limit L arrives at a best bid b:

buyer: trades at a if a ≤ L, otherwise waits as a bid at L

seller: trades at b if b ≥ L, otherwise waits as an ask at L

For a book with best bid b and best ask a:

spread = a − b, mid = (a + b) / 2, spread in bps = spread / mid × 10,000

In real data

The top of bitcoin's book

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

At the end of the five minutes from 14:00 UTC on 14 May 2025, the best bid on Binance's bitcoin perpetual was 103,805.6 dollars and the best ask 103,805.7. The spread was 10 cents, one tick, and the mid sat halfway between, at 103,805.65.

About $1.55 million was waiting at those two prices. The Depth Index is that number, averaged over the last day, for every perpetual we cover. Each bar's best bid, best ask and mid are in ƒL1 Price, and the dollars waiting 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.

What you learned

Limit
The most a buyer will pay, or the least a seller will take.
Taker
Someone who trades the moment they arrive, with the best note already waiting, at its price.
Maker
Someone who pins a note and waits for a taker, often for a better price.
Order book
Every note still waiting, added up by price: bids to buy on one side, asks to sell on the other.
Best bid, best ask
The highest price anyone will pay, and the lowest anyone will sell at.
Spread and mid
The gap between the best bid and the best ask, and the point halfway between them.

Check yourself

  1. 1. A seller is waiting with a note to sell at 47. A buyer arrives who would pay up to 60. At what price do they trade?

  2. 2. You want a sack right now. Which note do you take?

  3. 3. The best bid is 51 and the best ask is 53. What are the spread and the mid?

Lesson 2 of 10

Why there's a gap

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

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 3 of 10

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?

12 min

So far: A market maker quotes both sides and earns the gap between them, and the gap has to widen when more of the people trading know where the price is going (lesson 2).

Every trade has a buyer and a seller. Each sack bought is a sack sold, so a market can never have more buying than selling, counted in trades. Yet prices do rise when people are keen to buy. To see how, you have to ask of each trade which of the two chose to trade right then.

Who crossed

Go back to the board lesson 1 left behind, with the best bid at 51 and the best ask at 53. A maker pinned a note and waited. A taker arrived, read the board and took that note at its price. The trade needed both of them, but only the taker decided it should happen now, and crossed the spread to make it happen.

Exchanges record this. Next to each trade's time, price and size, the tape says which side the taker was on. In a taker buy, the buyer crossed and took a note at the best ask; in a taker sell, the seller crossed and took one at the best bid. Add them up over a minute and you get taker buy volume and taker sell volume. Buys minus sells is the ƒvolume delta.

Below, forty takers arrive at that board, each wanting one sack straight away, while makers keep two sacks waiting at every price. You choose how many of the takers are buying and how many selling, and watch the price.

Step 1 of 3

Set how many takers in every ten are buying, then send them in. Watch the price follow the gap between buys and sells.

3242526272price+80−8taker buys minus taker sells, so fartakers, in the order they arrive
5 of 10

No takers yet. 40 takers will each buy or sell one sack straight away, 5 in every ten of them buying.

Forty sacks change hands whatever you choose, so the volume is the same every time. With five buyers in every ten, takers bought 20 and sold 20, and the price ended at 52, where it started. With seven in ten, they bought 28 and sold 12, a volume delta of +16, and the price ended 10 higher, at 62.

Each taker buy removes a sack from the ask side. When buys outrun sells, the asks run out faster than makers replace them, and the best ask has to move up, taking the price with it. The volume says how much traded. The delta says which way the people in a hurry were leaning, and the price follows the lean.

A crowd or one big player

The same delta can come from very different people. Twenty-six sellers might each sell one sack, a few at a time, with buyers cutting in between them. Or one seller might want 12 sacks gone at once.

An order to sell 12 sacks takes the first note at the best bid, then the next, and keeps going down the board until it has all of them. The exchange prints one trade for every note it fills, so the tape shows 12 trades of one sack, all sells, all at the same moment, between the buys of everyone else.

Step 2 of 3

Switch between a crowd of sellers and one big seller. Both sell the same amount, so look at the runs on the tape.

4346495255orders, as they arrivethe tape, one square per trade2 buys in a row4 sells in a row
Live: A crowd: 40 takers, one sack each
Volume delta
−12
Longest buy run
2
Longest sell run
4
Run imbalance
−0.33

Most of the crowd sold, but buyers kept cutting in, so no run of sells lasted more than 4 trades.

Both tapes hold 14 taker buys and 26 taker sells, a volume delta of −12, and both leave the price at 45. Counted trade by trade, the sizes match too: every trade is one sack, because each fill is the size of the note it took. What gives the big seller away is the order of the trades.

A run is a streak of trades in a row whose takers were on the same side. In the crowd, the longest run of sells was 4 trades. The big seller's order printed 12 in a row. The ƒtrade run imbalance puts the longest run on each side against each other: the longest buy run minus the longest sell run, divided by the two added together. It goes from −1, when only sellers ever kept at it, to 1. The crowd's tape scores −0.33, the big seller's −0.71.

The maths

With Lbuy the longest run of taker buys in a bar and Lsell the longest run of taker sells:

run imbalance = (L_buy − L_sell) / (L_buy + L_sell)

The crowd: (2 − 4) / (2 + 4) = −0.33. The big seller: (2 − 12) / (2 + 12) = −0.71.

Flow that hurts

Lesson 2's stall lost money to customers who knew where the price was going. Those customers trade in a recognisable way: they all want the same side, and they come just before the price moves. So flow that piles up on one side while the price jumps around suggests that the people taking a market maker's notes know something. Market makers call such flow toxic, the word David Easley, Marcos López de Prado and Maureen O'Hara used for it in 2012.

The ƒflow toxicity score puts a number on it, a minute at a time. It takes two counts for the minute: the volume delta, and how much the price moved around inside the minute. It measures each against every minute of the day so far as a z-score, where 0 is an ordinary minute and 2 or −2 is far from ordinary. Then it multiplies the two.

Pick one of four minutes below and see where it lands on each count, against a toy morning of 30 ordinary ones.

Step 3 of 3

Try all four minutes. The score only grows when the orange square is far from the grey ones on both lines.

How one-sided: taker buys minus taker sells, in sacks

15 more sold15 more boughtaverageabout usual

z = −0.1: right by the average

How busy: how far the price moved around, in coins

02468 coinsaverageabout usual

z = 0.0: right by the average

How one-sided−0.1×How busy0.0=Flow toxicity score0
Live: Neither count is unusual
Volume delta
0 sacks
Price moved around
3 coins
The score points to
Neither side

Takers bought as much as they sold, and the price moved around the usual amount, so the score is 0.

Take a minute when takers sold 12 sacks more than they bought: far from usual, a z-score of −2.8. If its price moved around an ordinary 3 coins, a z-score of 0.0, the score comes to 0. If its price moved around 6 coins, a z-score of 2.5, the score drops to −7. A large score needs both: flow leaning hard to one side, in a minute when the price is busier than usual. Then the sign says who was pushing, below zero for sellers and above zero for buyers.

The maths

For each minute, with d its taker buys minus taker sells and r each trade-to-trade return inside it:

busyness v = √(Σ r²)

z(x) = (x − mean) / standard deviation, over the day's minutes so far, this one included

flow toxicity score = z(d) × z(v)

In real data

A minute when the sellers pushed

From 14:38 to 14:39 UTC on 11 June 2025, takers on Binance's bitcoin perpetual sold $68.0 million and bought $25.1 million, a volume delta of −$42.9 million, across 11,692 trades. The price fell from 110,169.3 to 109,927.0 dollars. Point at the chart to follow the two together.

Loading the minute's trades
  • price
  • taker buys minus taker sells, so far
  • a millisecond with $1 million or more of taker selling

The selling came in bursts. In 13 separate milliseconds, takers sold $1 million or more and bought nothing, between 24 and 194 trades at a time: $22.5 million in all, a third of the minute's selling. Each looks like one large order filling a long line of waiting notes at once. The longest run of sells was 339 trades and the longest run of buys 124, a run imbalance of −0.46.

Against the day's 879 minutes up to and including it, the minute's volume delta was 6.3 standard deviations below average, and only one minute that day had more net selling. Its price moved around ten times as much as the day's average minute, but that counts as only 1.9 standard deviations: five minutes earlier that day had moved even more, the wildest at 12:30 UTC, and they widen the standard deviation it is measured in. Multiply the two and the flow toxicity score for the minute was −11.8.

Every minute's taker buys and sells, volume delta and toxicity score are in ƒFlow Metrics, and its runs in ƒTrade Run Structure.

Binance BTC-USDT perpetual, all 11,692 trades from 14:38 to 14:39 UTC on 11 June 2025, from Aperiodic's raw trades, with the flow and run outputs for that minute and the 879 minutes of the day up to it. Prices in US dollars.

What you learned

Taker buy, taker sell
A trade where the buyer crossed the spread and took an ask, or where the seller crossed it and took a bid.
Volume delta
Taker buys minus taker sells. The price follows the delta, not the volume.
Run
A streak of trades in a row whose takers were all on the same side.
Trade run imbalance
The longest buy run against the longest sell run, from −1 to 1. One large order shows up as one long run.
Flow toxicity score
A minute's volume delta and how much its price moved around, each against the day so far, multiplied. Large when the flow leans hard while the price is busy.

Check yourself

  1. 1. In one minute, takers bought 30 bitcoin and sold 50. What was the volume delta?

  2. 2. One order sells 12 sacks against a board with one sack on each note. How many trades does the tape show?

  3. 3. Which minute gets the most negative flow toxicity score?

Lesson 4 of 10

What the candle leaves out

What does a five-minute candle throw away?

11 min

So far: Every trade is labelled by its taker, the side that crossed the spread. Taker buys minus taker sells is the volume delta, the price follows it, and long runs of one side point to a single large order (lesson 3).

Most price charts don't show trades. They show candles, one for every five minutes, or every hour, or every day, each a box with a line through it.

One candle, three stories

A candle keeps five numbers from a stretch of trading: the first price, called the open; the highest and the lowest, the high and the low; the last, the close; and how much traded, the volume. The box runs from the open to the close, and the line through it reaches up to the high and down to the low.

Five numbers can't hold everything that happened. Here are three toy tapes from the board you know, each with 60 sacks traded. Play them, and watch the price, who was buying and selling, and the candle each one leaves.

Step 1 of 3

Pick a tape and play it. Then play the other two, and compare the candle each one leaves.

44464850the trades inside this candlehigh 51open 50close 45low 44the candlesacks in each trade

Nothing played yet. Every tape here leaves this candle: open 50, high 51, low 44, close 45, 60 sacks. Play this one to see the trades inside it.

All three leave the same candle: open 50, high 51, low 44, close 45, 60 sacks. Yet in the slide, sellers kept coming, mostly one sack at a time, and the price stepped down a coin at a time. The jump had ten quiet trades, then one seller who took 24 sacks at 44 in a single trade. And in the tug of war, buyers and sellers took turns, three sacks at a time, while the price kept turning on its way down. Someone reading only the candle can't tell which of these happened.

What the tape keeps

Measures built from the trades themselves keep some of what the candle throws away. An ƒuptick is a trade at a higher price than the trade before it, and a downtick one at a lower price; the rest print at an unchanged price. Counting them says how the price got from the open to the close: in a few steps or many, and how often it turned back.

An uptick isn't the same as a taker buy. A taker buy that fills at the same price as the trade before is a buy and an unchanged tick. The side says who crossed the spread; the tick says whether the price moved.

ƒTrade sizes sort trades by the money in each: here, small under 100 coins, medium up to 1,000, and large from 1,000. The catalog uses the same cuts in dollars. And ƒflow entropy says how mixed the taking was. Take the share of the money that went through taker buys, and the share through taker sells: the entropy is 0 when one side did all the taking and 0.69 when they split it evenly.

Read each tape three ways: by its ticks, by the size of its trades, and by taker buys against taker sells.

Step 2 of 3

Pick a tape, then read it three ways: how the price stepped, how big the trades were, and who did the taking.

44464850high 51open 50close 45low 44the candlesacks in each trade
Live: A steady slide, by tick
Upticks
2
Downticks
7
Unchanged
22
Trades
32

The price moved 9 times, a coin at a time, nearly always down.

The slide had 7 downticks and only 2 upticks. The tug of war had 9 downticks and 4 upticks: the same distance travelled, with more turning back. In the jump, one large trade carried 38% of the money. And sellers did 88% of the taking in the slide, so its flow entropy is 0.36, while the jump and the tug of war, with both sides active, come to 0.63 and 0.67.

A jump or a slide

The candle can't say whether the fall from 50 to 44 came in one trade or in many. The ƒjump ratio can. It compares two ways of adding up how much the price moved from trade to trade.

The first is realised variance: square every move and add them up. Squaring makes big moves count much more than small ones. The second is bipower variation, which multiplies each move by the move before it instead, and scales the sum by π/2 so the two agree when the price moves in steady small steps. A big move next to small ones, or next to a trade at an unchanged price, adds little or nothing to it. The jump ratio is the share of realised variance that bipower variation leaves unexplained, the jump part.

Step 3 of 3

Move more of the six-coin fall into a single trade. Watch bipower variation fall behind realised variance.

44464850realisedbipowerjump partsix one-coin moves
none
Live: Jump ratio 0.21
Moves
6
Biggest move
1 coin
Bipower ÷ realised
79%
Jump ratio
0.21

Six one-coin moves, mostly in pairs. Bipower variation finds a partner for most of them, so the jump ratio stays low.

With the fall spread over six one-coin moves, the jump ratio is 0.21. Put four coins of it into one trade and it is 0.92; all six at once and it is 1. The three tapes from before score 0.14 for the slide, 0.93 for the jump and 0.13 for the tug of war.

Even six small moves score above zero. Wherever a trade at an unchanged price sits next to a move, that move loses a partner in bipower variation, so part of it counts toward the jump part. On a real tape, where most trades print at the price before them, that happens all the time, so read the jump ratio against other bars of the same market rather than against zero.

The maths

With pi the price of trade i, each move is a log return:

r_i = ln(p_i / p_(i−1))

realised variance RV = Σ r_i²

bipower variation BV = (π/2) · Σ |r_i| · |r_(i−1)|

jump ratio = (RV − BV) / RV

With p the share of the money that went through taker buys:

flow entropy = −p · ln p − (1 − p) · ln(1 − p)

In real data

One real candle, and what was inside it

From 14:38 to 14:39 UTC on 11 June 2025, Binance's bitcoin perpetual left this candle: it opened at 110,169.3 dollars, which was also its high, fell as low as 109,863.9 and closed at 109,927.0, with 846.5 bitcoin traded, worth $93.1 million.

What the candle keeps

Open and high
110,169.3
Low
109,863.9
Close
109,927.0
Volume
846.5 BTC, $93.1M

What its 11,692 trades show

Trades11,692
Upticks1,597
Downticks3,355
At an unchanged price6,739
Money in large trades97.9%
Jump ratio0.42
Flow entropy0.58

Inside it were 11,692 trades. 3,355 were downticks and 1,597 upticks, and 6,739, more than half, printed at the same price as the trade before. None was small by the catalog's cut, since the smallest was worth $109.86; the 4,812 large trades carried 97.9% of the money.

The jump ratio was 0.42: a good part of the minute's movement came in moves that stood out from the trades around them. The flow entropy was 0.58, short of an even split's 0.69, because takers sold 73% of the money. Every minute's counts are in ƒUp / Down Tick Metrics, ƒTrade Size, ƒReturns & Volatility and ƒFlow Metrics.

Binance BTC-USDT perpetual, the minute from 14:38 to 14:39 UTC on 11 June 2025: the pipeline's outputs for all 11,692 trades, from Aperiodic's raw trades. Prices in US dollars.

What you learned

Candle
The open, high, low, close and volume of a stretch of trading. Many different tapes leave the same one.
Upticks and downticks
Trades priced above or below the trade before. They count the steps the price took, and how often it turned back.
Trade sizes
Trades sorted by the money in each, small, medium or large. One large trade can carry much of the volume.
Jump ratio
The share of realised variance that bipower variation leaves unexplained. Near 1 when one move made up most of the movement.
Flow entropy
How mixed the taking was between buyers and sellers: 0 when one side did it all, about 0.69 for an even split.

Check yourself

  1. 1. Two five-minute candles are identical. Were the trades inside them the same?

  2. 2. A price falls six coins, four of them in a single trade. Is its jump ratio nearer 0 or nearer 1?

  3. 3. Taker buys took half the money in a minute and taker sells the other half. What is its flow entropy?

Lesson 5 of 10

Walking the book

What does it cost to buy more than the best ask holds?

11 min

So far: A five-minute candle keeps four prices and a volume, and many different runs of trades leave the same one: their sizes, their order and every step the price took are gone (lesson 4).

Past the best ask

In lesson 1 you bought one sack from the cheapest note to sell, and the next buyer paid a little more. Now buy more than the best ask holds. The rest of your order doesn't wait: it takes the next cheapest price, then the next, until it is filled. Traders call this walking the book.

Here is a deeper book, with toy numbers: a unit costs about 100 coins, and prices move one tick, 0.01, at a time. Each column is one level, as tall as the units waiting there: bids on the left, asks on the right, 25 levels of asks in all. Pick a size and send your order.

Step 1 of 3

Pick an order size and send it. Watch it take the asks level by level, and see where its average price lands.

mid
99.95100.00100.05100.10100.15100.20
40

Nothing sent yet. The best ask holds 10 units at 100.00. Send 40 units and see how far up the book they reach.

An order of 40 takes all 10 units at the best ask, then 6 at 100.01, 8 at 100.02, 6 at 100.03, 8 at 100.04 and the last 2 at 100.05. Each fill is a trade of its own, at its level's price. They average 100.0205, which is 2.05 basis points over the best ask. That difference is the order's ƒslippage.

Slippage is measured from the best price you could see when you sent the order: the best ask for a buy, the best bid for a sell. An order the best level can hold has none. Double the order to 80 units and the slippage more than doubles, to 4.48 basis points. Paid on twice as many units, the extra over the best ask comes to more than four times as much: 3.58 coins against 0.82.

The maths

An order of Q units fills q1 at p1, q2 at p2, and so on:

average price = (q1 · p1 + q2 · p2 + …) / Q

slippage of a buy, in bps = (average − best ask) / best ask × 10,000

slippage of a sell, in bps = (best bid − average) / best bid × 10,000

Thin and thick

How far an order walks depends on how much waits at each level. A book with plenty at every price is called deep, or thick, and one with little is thin. The figure sets the book from above next to one with half as much at every level. Move your order and compare.

Step 2 of 3

Drag the order size. Compare what the same order pays on a thick book and on a thin one.

Thick book
average
100.00100.05100.10100.15100.20
Thin book, half at every level
average
100.00100.05100.10100.15100.20
051015bps050100150 unitsthickthin
40
Live: 40 units on each book
Slippage, thick
2.05 bps
Slippage, thin
4.48 bps
Levels, thick
6
Levels, thin
10

With half as much at every level, the same 40 units walk 10 levels instead of 6, and pay 4.48 basis points instead of 2.05: 2.2 times as much.

Halve the depth and the slippage roughly doubles. At 40 units the thin book charges 4.48 basis points against the thick book's 2.05, and the order walks 10 levels instead of 6. The thick book's line also bends: past 118 units the order reaches the wall of 40 units at 100.13, and the line flattens, because every unit in the wall costs the same.

So a trader who needs to buy a lot can split the order and send the pieces minutes apart, and each piece meets a book that has had time to refill. Whether it refills, and at what price, is the next lesson.

Which side is heavier

Lesson 2 compared the queues at the best bid and the best ask. With 25 levels a side you can ask the same question at any depth: add up the first 5 levels of each side, or 10, 20 or 25, and compare. The ƒbook imbalance is the difference over the total. It runs from −1 when only asks wait to +1 when only bids do.

Step 3 of 3

Add up the first 5, 10, 20 or 25 levels on each side. Watch which side comes out heavier.

mid
99.7599.8099.8599.9099.95100.00100.05100.10100.15100.20
bids 60asks 38
Live: The first 5 levels of each side
Bids
60 units
Asks
38 units
Imbalance
+0.22
Heavier side
bids

Near the price the bids are heavier. The next small trades meet these levels first.

In this book the answer depends on how far you look. On the first five levels the bids are heavier, 60 units against 38, an imbalance of +0.22. Across all 25 levels the asks hold twice as much, 312 against 156, an imbalance of −0.33. Both readings are right, and they answer different questions. The first levels are what the next small trades will meet. The deeper ones are what a large order would meet, and they are further from trading: whoever placed them can move or cancel them before the price gets there.

The maths

Over the first N levels of each side, with B units of bids and A units of asks:

imbalance = B − A, imbalance ratio = (B − A) / (B + A)

In real data

Bitcoin's book, 25 levels deep

First levelsBidsAsksImbalance ratio
57.29 BTC7.85 BTC−0.038
107.41 BTC8.16 BTC−0.048
207.61 BTC8.55 BTC−0.059
257.69 BTC8.67 BTC−0.060

At the end of the five minutes from 14:00 UTC on 14 May 2025, 7.29 bitcoin waited on the first five bid levels of Binance's bitcoin perpetual, and 7.85 on the first five ask levels. Going out to 25 levels added only 0.40 to the bids and 0.82 to the asks: more than nine tenths of what waited within 25 levels sat in the first five. A buy of more than 7.85 BTC, about $0.82 million, would have walked past the fifth level into a much thinner book.

The asks were heavier at every depth, and a little more so further out: the imbalance ratio was −0.038 on five levels and −0.060 on 25. Here the near and far levels agreed.

Over the same five minutes the median trade paid nothing beyond the quote it met: at least half filled at the best bid or ask. The mean slippage was 0.16 basis points, sells 0.17 and buys 0.14, and one trade in twenty paid 0.81 or more, about $8.40 a bitcoin. Some of that is walking the book, and some is the quote moving between its last update and the trade.

Each bar's depth at 5, 10, 20 and 25 levels is in ƒL2 Order Book Liquidity, its imbalance at each depth in ƒL2 Order Book Imbalance, and how far each trade filled from the quote in ƒSlippage.

Binance BTC-USDT perpetual, the five-minute bar from 14:00 UTC on 14 May 2025, from Aperiodic's free sample. Depth and imbalance are the book at the end of the bar; slippage covers every trade in it. Sizes in bitcoin.

What you learned

Level
One price in the book, with everything waiting there added up.
Walking the book
An order bigger than the best level takes the next level, then the next, each at a worse price.
Slippage
How far an order's average price lands from the best quote it met, in basis points: over the best ask for a buy, under the best bid for a sell.
Depth
How much waits on the first 5, 10, 20 or 25 levels of a side. The thinner the book, the further an order walks.
Book imbalance
Bids minus asks over the same levels, divided by their sum: positive when more waits to buy. Near and far levels can lean opposite ways.

Check yourself

  1. 1. The best ask holds 10 units. You buy 8. What is your slippage?

  2. 2. Halve what waits at every level. What happens to the slippage of the same order?

  3. 3. On the first five levels, 60 units wait to buy and 40 to sell. What is the book imbalance?

Lesson 6 of 10

Every trade leaves a mark

After a big order, how much of the move stays?

13 min

So far: An order bigger than the best level walks the book, taking each price in turn, and the further it walks the more it pays over the best quote: its slippage (lesson 5).

Walking the book costs the buyer, and it leaves the price higher for whoever comes next. How far a big order moves the price, and how much of the move comes back once the book refills, can be measured from trades alone.

The peak, and what stays

Send 60 units into lesson 5's thick book and the order walks eight levels. Afterwards the best ask is 100.07 and the best bid still 99.99, so the mid has jumped from 99.995 to 100.03. That jump is the peak of the order's impact.

Then the makers come back. New asks appear below 100.07, new bids above 99.99, and the spread narrows again. Where the mid settles depends on what the makers conclude from the order. Someone just bought 60 units in a hurry. Maybe they knew something. Makers can't tell, so they shade their prices up a little: in this toy, a quarter of a tick for every 10 units bought.

Send the order and watch. The book is on the left, asks above and bids below, with outlines where your order took. The chart follows the mid for 30 seconds.

Step 1 of 3

Set an order size and how fast makers refill, then send it. Watch how far the mid jumps, and how much of the jump is still there 30 seconds later.

60
4 s

Nothing sent yet. The best bid is 99.99 and the best ask 100.00. Send 60 units and watch the mid for 30 seconds.

With the figure's starting settings, 60 units lift the mid 3.5 basis points. Makers refill, and it slides back to 1.5 above where it started, and stays there. The 2 basis points that came back are the temporary impact: the cost of emptying the book, paid by the buyer and gone once the book refills. The 1.5 that stayed is the permanent impact, a change in what everyone thinks the price is.

Slow the makers down and something else shows. If they close half the gap every 20 seconds, the same order still shows 2.2 basis points after 30 seconds, of which only 1.5 will stay. Measured then, more of the move looks permanent than really is. How much of a move stays depends on when you look, and every measure of it has to pick a moment.

The maths

With the mid at m0 before the order and m1 at its peak, a permanent rise P, and makers closing half the gap every h seconds, the mid t seconds after the order has filled is:

mid(t) = m0 + P + (m1 − m0 − P) · 2^(−t / h)

In the toy, P is 0.025 ticks for every unit bought.

One slope for a market

You rarely see one big order on its own. You see thousands of trades of every size, buys and sells mixed, each moving the price a little. Albert Kyle's 1985 model of trading gives a way to read them together. In it, makers move the price by a fixed amount for every unit bought or sold in a hurry. Plot each trade's size against the move that came with it, and the slope of the line through the dots is that amount. It is called ƒKyle's lambda.

The figure plots 120 toy trades. Each dot is one: its size across, counted plus for a buy and minus for a sell, and the move that came with it up the side. Make the book thinner or thicker.

Step 2 of 3

Make the book thinner or thicker. Watch every trade's move grow or shrink, and the line's slope with them.

−3−2−10+1+2+3−20−10+10+20sellsbuys, unitsbps
10
Live: 10 units waiting at each level
Kyle's lambda
0.053 bps
A 10-unit buy moves it
0.53 bps
Amihud, per 10,000 coins
0.91 bps

With 10 units at each level, every unit traded comes with 0.053 bps of move. Thin the book and the line steepens; thicken it and the line flattens.

With 10 units at every level, the slope is 0.053 basis points per unit: a 10-unit buy comes with about half a basis point. Halve the depth to 5 and the slope doubles, to 0.106. Quadruple it to 40 and the slope falls to 0.013. A steep line means a thin market, where every unit traded pushes the price further.

Yakov Amihud proposed a coarser measure in 2002, for stocks, a day at a time: take how far the price moved over the period, whichever way, and divide by how much traded. ƒAmihud illiquidity needs nothing but prices and volume. On the toy it reads the same way as the slope: 0.91 basis points for every 10,000 coins traded with 10 units at each level, twice that with 5. Its blind spot is a period where buyers and sellers cancel out. The price barely moves over it, so it looks liquid however thin the book is.

The maths

For trades with prices p and sizes q, counted plus for a taker buy and minus for a taker sell, each trade's return is r = p / p_before − 1, and:

Kyle's lambda = covariance(r, q) / variance(q)

Amihud = |p_last / p_first − 1| / (sum of every trade's p · |q|)

Five trades later

Lambda and Amihud say how hard trades push. Neither says how much of the push comes back. For that, watch the price after the biggest trades. The ƒlarge-trade reversal takes the biggest tenth of trades by value, looks five trades ahead of each, and averages the return from the big trade's price to the later one.

Here is a toy tape of 50 trades on lesson 5's book. Five are big buys of 60 units, ringed. Choose how many trades ahead to look.

Step 3 of 3

Change how many trades ahead to look. Watch where the price was by then, after each big buy.

99.98100.00100.02100.04100.06100.08100.10trade 11121314150−1.1−2.8−1.4−1.7−1.3
5
Live: Five trades ahead, as the measure looks
Average return after
−1.67 bps
Big buys over the mid
+3.80 bps
Came back
44%
Big trades
5

Five trades after the big buys, the price was on average 1.67 bps below where they printed. They printed 3.80 bps above the mid before them, so about 44% of that had come back.

One trade on, the price sits about 1 basis point below where the big buys printed. Five trades on, it is 1.67 below. The big buys printed 3.8 basis points above the mid before them, half the spread plus the walk, so by five trades on about 44% of that had come back.

A negative number after big buys, or a positive one after big sells, means part of the move came back. The measure doesn't flip sells around, so a minute with big trades on both sides can average out to nothing. Read it next to which side the big trades were on.

In real data

One minute of bitcoin, measured

FieldStoredIn plain units
Kyle Lambda1.90e-60.019 bps per bitcoin, about 21 cents
Amihud Illiquidity2.36e-110.24 bps per $1 million traded
Impact per Notional5.12e-110.51 bps per $1 million of net flow
Large Trade Reversal2.37e-7+0.0024 bps, a quarter of a tick

From 14:38 to 14:39 UTC on 11 June 2025, 11,692 trades took Binance's bitcoin perpetual from $110,169.3 to $109,927.0, down 22 basis points, on $93.1 million traded. Taker sells outweighed taker buys by $42.9 million.

The minute's Kyle Lambda says each bitcoin of a trade, plus for a buy and minus for a sell, came with a move of 0.019 basis points: about 21 cents at that price, or two ticks. Its Amihud Illiquidity reads better as 0.24 basis points of move for every million dollars traded. Divide the same move by the net flow instead of all of it and you get 0.51 per million: its Impact per Notional.

Its Large Trade Reversal is +0.0024 basis points. Five trades after the minute's biggest tenth of trades, 1,170 trades of $19,892 or more, the price was on average a quarter of a tick higher. But 836 of them were sells. Split by side, the price five trades on was about two ticks lower after a big buy and about one tick higher after a big sell. Within five trades, a big trade's push came back by a tick or two, whichever way it went.

Every interval's Kyle Lambda, Amihud Illiquidity, Impact per Notional and Large Trade Reversal are in ƒImpact Metrics.

Binance BTC-USDT perpetual, every trade from 14:38 to 14:39 UTC on 11 June 2025, from Aperiodic's raw trades, and the pipeline's impact fields for that minute. Prices in US dollars; one tick is 10 cents.

What you learned

Peak impact
How far the price moves while an order empties the book, before anyone refills it.
Temporary impact
The part of the move that comes back once makers refill: the cost of emptying the book.
Permanent impact
The part that stays, because makers now think the price is higher, or lower after a sale.
Kyle's lambda
The slope of each trade's price move against its size, counted plus for buys and minus for sells. Steeper means a thinner market.
Amihud illiquidity
How far the price moved over a period, whichever way, divided by how much traded in it.
Large-trade reversal
The average return five trades after the biggest tenth of trades. Read it next to the side those trades were on.

Check yourself

  1. 1. A buy lifts the mid 3.5 basis points. Once the book refills, the mid sits 1.5 above where it started, and stays there. How much of the impact was temporary?

  2. 2. Market A's Kyle's lambda is twice market B's. A 10-unit buy in A moves the price…

  3. 3. Five trades after the biggest buys, the price is on average below where they printed. What does that say?

Lesson 7 of 10

A contract that never expires

How do you trade bitcoin without ever holding any, and what happens when everyone borrowed to do it?

14 min

So far: Every trade pushes the price a little and a big one pushes it more; part of the push fades and part of it stays (lesson 6).

You can trade bitcoin without ever owning one, through a contract that pays as if you held the coin: when bitcoin rises by 100 dollars, the buyer of a contract for one coin makes 100 dollars and the seller loses them.

The classic contract of this kind is a futures contract: a promise to buy something on a set date at a price agreed today. Its price can drift away from the price of the thing itself, the spot price, until the date pulls it back: on the day, a contract to buy bitcoin right now is worth exactly what bitcoin is worth.

A perpetual is a futures contract with the date taken away, so nothing on the calendar pulls its price to spot. Something else has to.

Funding

Every contract has two sides. Whoever bought it is long and gains when the price rises; whoever sold it is short and gains when the price falls, without ever having owned a coin.

The perpetual is measured against an index, a price for the coin built from spot exchanges. At set times the two sides settle up with a payment called funding: every eight hours by default on Binance, every hour on Hyperliquid. When the perpetual trades above the index, longs pay shorts. When it trades below, shorts pay longs.

Step 1 of 4

Move the perpetual's price above and below its index. Watch which way the payment flows.

99.799.899.9100.0100.1100.2100.3perpetual 100.10index 100.00
Longspay
$10 to shorts
Shortsreceive
100.10
Live: Longs pay shorts
Premium over the index
+0.10%
Funding rate
+0.10%
A $10,000 long pays
$10

The perpetual costs more than the coin, so longs pay shorts: $10 on every $10,000 they hold, at every funding time. Holding the short now earns something.

The payment is the position times the ƒfunding rate. In this toy the rate is simply the premium, the gap as a share of the index: at 0.10% above it, a long holding $10,000 pays $10 at each funding time. Binance and Hyperliquid average the premium over the period and add a small interest term.

While longs pay shorts, a trader can buy a coin on a spot exchange and sell the same amount of the perpetual. One side gains what the other loses, so the trader carries no price risk and collects funding for as long as the premium lasts. This is an arbitrage, and its selling pushes the perpetual's price down toward the index. The next figure starts a week with the perpetual 0.30% above its index.

Step 2 of 4

Choose how many traders buy the coin and sell the perpetual, then run the week. Watch the gap, and what the longs pay.

3

Start of the week. The perpetual is 0.30% above its index. Run the week with 3 arbitrageurs.

With nobody arbitraging, the premium sits at 0.30% all week and a long holding $10,000 pays $630 in funding. With three arbitrageurs it's down to 0.03% by the end of the week, and the long pays $246. It never quite reaches zero, because arbitrageurs stop once funding no longer covers their fees and the money tied up in the coin.

The gap between a perpetual's price and its index is its ƒbasis. Funding charges whichever side holds the price away from the index, and pays whoever helps close the gap.

The maths

With the perpetual at price F, the index at I and a position worth Q dollars:

premium = (F − I) / I

toy funding rate r = premium; a long pays Q · r, a short receives it

Binance's rate for an eight-hour period, with P the premium averaged over the period and an interest term of 0.01%:

r = P + clamp(0.01% − P, −0.05%, 0.05%)

So while P sits between −0.04% and 0.06%, the rate is 0.01%.

Open interest

Every contract has one long and one short, so counting either side counts the contracts still open: the ƒopen interest. Each trade has a buyer and a seller, and each of them is either opening a position or closing one.

Step 3 of 4

Pick who buys and who sells, then trade one contract. Watch open interest and volume part ways.

Long
ABC
Short
DEF
The buyer
The seller

Three contracts open. Every trade has a buyer and a seller. Choose what each of them is doing, and trade.

When both sides open, a contract is created. When both close, one ends. When one opens and the other closes, a contract changes hands and the count stays put. Volume counts every contract traded, so a busy day can leave open interest exactly where it started.

Borrowed money

A perpetual asks only for a deposit, the margin, and the venue lets you hold a position several times bigger. Hold $10,000 of bitcoin on $1,000 of margin and your leverage is 10×: every 1% the price moves is 10% of your money.

If the losses use up the whole margin, the venue closes the position for you before anyone else has to cover them, selling at whatever the book will pay. That is a liquidation. In this lesson's toy it happens when the loss reaches the margin: after a 10% fall at 10×, or 5% at 20×. Binance, for one, steps in earlier, at a smaller amount it calls the maintenance margin (its liquidation rules), and it judges the loss by a mark price rather than the last trade, so one odd trade can't liquidate anyone (how Binance builds it).

A liquidation is a forced sale, and a forced sale walks the price down the book (lesson 5), where it can reach the next trader's liquidation price. Below, 20 traders are all long from 100, each with their own leverage.

Step 4 of 4

Pick how much the crowd borrowed, then let a big seller knock the price down. See whose lines it reaches, and how far it falls.

Typical leverage in the crowd

Everyone is long from 100. At 10×, the highest line is at 96.2. Let the big seller in.

At 2× and 5× nobody's liquidation line is within reach of 96. At 10× the highest line sits just above 96, and each forced sale pushes the price into the next line until half the crowd, 10 of 20, is gone and the price is at 91. At 20× the chain runs through everyone and ends at 86. The big seller moved the price by 4 every time; what changed was how much everyone had borrowed.

Each liquidation closes a long. When the buyer on the other side is a short closing out, a contract disappears, so a cascade can show up as open interest falling sharply while the price falls.

The maths

With margin M on a position worth Q, bought at price E:

leverage L = Q / M

toy liquidation price for a long = E · (1 − 1 / L)

At 10×, from 100: 100 · (1 − 1/10) = 90, a fall of 10%.

In real data

Bitcoin's perpetual, one bar

Last trade103,817.20
Mark price103,817.20
Index price103,859.74
Basis, mark minus index−42.54 (−4.1 bps)
Funding rate0.0055%
Open interest81,053 BTC, $8.41 billion

At the end of the five minutes from 14:00 UTC on 14 May 2025, Binance's bitcoin perpetual last traded at 103,817.20 dollars, and its mark price was the same. The index stood at 103,859.74, so the basis, mark minus index, was −42.54 dollars or −4.1 basis points: the perpetual was a little cheaper than the coin. Over the hour below, the mark sat under the index at the close of every bar.

103,600103,800104,000104,20013:05 UTC14:00 UTC
  • mark price
  • index price

Even so, Binance's next funding, at 16:00 UTC, had longs paying shorts: 0.0055%, about 55 cents on every $10,000. Its interest term holds the rate at 0.01% while the averaged premium sits between −0.04% and 0.06% (its funding rules), so a rate a little under 0.01% means that premium was a little under −0.04%.

Open interest was 81,053 bitcoin, about $8.41 billion at the mark price. Each bar's basis, funding rate and open interest are in ƒBasis, ƒFunding and ƒOpen Interest, and its last, mark and index prices in ƒDerivative Price.

Binance BTC-USDT perpetual, the five-minute bar from 14:00 UTC on 14 May 2025 and the eleven before it, from Aperiodic's free sample. Prices in US dollars; each value is the last one in its bar.

What you learned

Futures contract
A promise to buy or sell on a set date at a price agreed now. The date pulls its price to the price of the thing itself.
Perpetual
A futures contract with no date. Funding keeps its price near an index instead.
Funding rate
What longs pay shorts at each funding time when the perpetual is above its index, or shorts pay longs when it is below, as a share of the position.
Basis
How far the perpetual's price is from its index, often in basis points. Funding charges whoever holds it apart.
Open interest
The contracts still open, each with one long and one short. Opening and closing change it; a contract changing hands doesn't.
Leverage
A position bigger than your margin. When losses use up the margin the venue sells you out, and that sale can push the price to the next trader's liquidation price.

Check yourself

  1. 1. A perpetual trades at 100.20 while its index is at 100.00. Who pays funding?

  2. 2. Open interest is 3. Someone opening a new long buys from a long who wants out. What is open interest after the trade?

  3. 3. You hold $10,000 of a perpetual on $1,000 of margin. Under this lesson's toy rule, how far must the price fall before you are liquidated?

Lesson 8 of 10

A stock that trades on Sunday

What is a Tesla perpetual, and what does it do while Nasdaq is closed?

10 min

So far: A perpetual never expires. Funding between longs and shorts pulls its price toward an index, and when a crowd has borrowed the same way, one forced sale can set off the next (lesson 7).

The same contract works for things that aren't crypto. A stock perpetual is a perpetual whose index follows a company's share price: a Tesla perpetual pays as if you held Tesla shares. You never own a share, and you trade it on a crypto venue at any hour, on any day of the week.

The shares themselves trade on Nasdaq, whose market hours are 9:30 to 16:00 New York time, with its systems open from 4:00 to 20:00 for trading before and after (Nasdaq's hours). At weekends nobody trades them there at all, and the perpetual keeps going.

The weekend

So over a weekend the perpetual has nothing live to follow. If news about the company breaks on Saturday, the shares can't react until Monday, but the perpetual can. The people trading it have to work out the new price among themselves.

Here is a toy weekend for a stock that closed at 200 on Friday. Pick what happens, then run it from Friday's close to Monday's open, and watch the gap between the perpetual and the stock's last price.

Step 1 of 3

Pick a weekend and run it from Friday's close to Monday's open. Watch the gap between the perpetual and the stock's last price.

Friday, 16:00 in New York. The stock has just closed at 200. The perpetual is still trading.

On a quiet weekend the perpetual drifts and the gap stays under half a percent. With good news on Saturday it jumps about 6% and stays up; on Monday the stock opens at 211.20, close to where the perpetual spent Sunday, and the gap closes. With a rumour that is denied on Sunday, the perpetual drops 6.8% and climbs most of the way back, so anyone who sold in a hurry on Saturday sold at a price the stock never traded at.

In this toy the weekend's gap was news the stock hadn't been able to price yet, and the perpetual got there first. It doesn't have to be that way. With fewer people trading, a handful of orders can push the price around (lesson 6), and Monday's open is the first time the weekend's price is checked against the shares.

That leaves the venue with a problem. Funding pulls a perpetual toward its index, and an index built from the stock's price sits still all weekend. Each venue settles this its own way, and a contract's specification says what its index does while the stock's market is closed. The figure tries two simple choices on the good-news weekend: watch the perpetual, the index, and the funding a long pays.

Step 2 of 3

Switch how the index is kept while the stock is shut. Watch the basis, and what a long pays in funding.

200210openfunding a $10,000 long pays, each timeFriSatSunMon
While the stock is shut, the index
Live: The index stands still all weekend
Widest basis
+6.2%
A $10,000 long pays
$300
Index at 9:00 Monday
200.00
Stock opens at
211.20

The basis is the whole weekend move, so funding hits its cap and the longs pay it every eight hours for a price everyone knows is out of date. At Monday's open the index jumps to where the perpetual already was.

If the index holds Friday's close, the basis is the whole weekend move, and in this toy a long holding $10,000 pays $300 in funding for a price everyone knows is out of date. If the index follows the venue's own trading, the basis stays small and so does funding, but nothing outside the venue checks the price until Monday. Either way, a stock perpetual's basis on a Saturday means something different from its basis on a Tuesday.

The maths

With the perpetual at F and the stock's last price at S:

gap = F / S − 1

Against an index I, the same sum is the basis as a share of the index, and the toy's funding rate for a period, capped at 0.5%:

r = min(0.5%, max(−0.5%, F / I − 1))

Who is around

In this toy, fewer market makers quote at the weekend, and the ones who do have a harder job. A market maker who sells you the perpetual on a Tuesday afternoon can buy the shares on Nasdaq a moment later and be back to holding nothing. On a Saturday they can't, so they carry the risk until Monday. They quote less, and further from the mid (lesson 2).

Below is the same toy perpetual's book on a Wednesday afternoon and on a Saturday. Choose how much you want to buy straight away, and see what it costs over the mid.

Step 3 of 3

Switch between a Wednesday afternoon and a Saturday, and change how much you buy. Watch the spread, and how far up the book your order reaches.

Asks
200.11$68k
200.09$60k
200.07$53k
200.05$45k
200.03$38k
200.01$30k
spread 1 bps · mid 200.00
199.99$30k
199.97$38k
199.95$45k
199.93$53k
199.91$60k
199.89$68k
Bids
$25k
Live: Wednesday afternoon, the stock market open
Spread
1 bps
Depth, 5 levels a side
$450k
Your cost over the mid
0.5 bps
Ask levels used
1

Your $25,000 fits inside the best ask, so you pay half the spread over the mid and nothing more.

On Wednesday, $25,000 fits inside the best ask and costs 0.5 basis points over the mid. On Saturday the spread is ten times wider, and the same order walks four levels up the book (lesson 5) for 11.6 basis points. Nothing about the contract changed, only who was around to trade it.

The maths

Buying D dollars across ask levels at prices ak, taking dk dollars at each, with the mid at m:

average price = D / Σ (d_k / a_k)

cost over the mid in bps = (average − m) / m × 10,000

In real data

Stock perpetuals, live

The free sample this guide draws from has no stock perpetual in it, but the RWA board shows the ones Aperiodic covers, with each one's basis, spread and depth. For scale, in the bar from lessons 2 and 7, bitcoin's perpetual had a spread of 0.0096 basis points and a basis of −4.1 basis points. Open the board on a weekday afternoon, then again on a Saturday, and compare.

When you look at a stock perpetual, start with its basis, how far it has wandered from its index; at a weekend, ask how that index is being kept. Then look at its spread, what trading right now costs, and its depth, how much you could trade before the price moves. Each is kept for every bar, weekends included, in ƒBasis, ƒL1 Liquidity and ƒL2 Order Book Liquidity.

The RWA board is live, 15 minutes behind the venues. Bitcoin figures: Binance BTC-USDT perpetual, the five-minute bar from 14:00 UTC on 14 May 2025, from Aperiodic's free sample.

What you learned

Stock perpetual
A perpetual whose index follows a share price. It trades on a crypto venue at any hour, weekends included.
Weekend gap
While the stock's market is shut, the perpetual moves and the stock's last price doesn't. The gap is the venue's guess at what the stock is worth now.
Monday's open
The first time the weekend's price is checked against the shares themselves.
The index while shut
Each venue decides what its index does while the stock can't trade, and the contract's specification says how. Basis and funding depend on it.
Spread and depth
Thinner when fewer people are around and market makers can't hedge in the stock, so trading straight away costs more.

Check yourself

  1. 1. A stock closed at 200 on Friday. On Saturday its perpetual trades at 212. What is the gap?

  2. 2. In this lesson's toy, why is the spread wider on Saturday?

  3. 3. A venue's index holds Friday's close all weekend, and the perpetual rises 6% on Saturday. Who pays funding?

Lesson 9 of 10

Three numbers for any market

The same asset trades on several venues. Where is it cheapest to trade, where is it deepest, and where is it hardest to move?

12 min

So far: A stock perpetual trades on crypto venues around the clock, and while the stock's own market is shut, nothing outside the venue checks its price (lesson 8).

You have now met the costs a market order pays to the book. It crosses the spread (lesson 2), it walks up the book when it is bigger than the best ask (lesson 5), and it leaves the price moved behind it (lesson 6). The same coin often trades on several venues at once, each with its own book. This lesson turns those costs into three numbers you can read off any of them.

Three venues, one coin

Here is one coin on three venues. It is worth 100 dollars on all three, so a basis point is one cent, but their books differ. Venue A has the narrowest spread between its best bid and best ask, and little waiting at each price. B's spread is wider, with one big queue at its best ask and little behind it. C's spread is the widest, and the book behind its best ask is the thickest.

You want to buy. Set the size of your order and see what it pays on each.

Step 1 of 3

Change the size of your order. Watch how much of each book it eats, and which venue it costs least on.

$50k
Live: Buying $50k: cheapest on A
Paid on A
1.0 bps
Paid on B
3.0 bps
Paid on C
5.0 bps

The order fits in the first few prices of every book, so the spread is most of what it pays, and A has the narrowest.

Small orders go to A. They fit in its first few prices, so they pay little more than half its narrow spread: $50,000 costs 1 basis point above the mid on A, against 3 on B and 5 on C. At $500,000, A's thin book has run out of cheap prices, and B's big queue fills the whole order at 3. At $5 million every first queue is gone, and C, the venue with the widest spread, is cheapest by far: 9.9 basis points, against 22.8 on B and 50.5 on A. Which venue is cheapest depends on how much you trade.

Three numbers

You can't walk every venue's book before every order, and you rarely see the whole book anyway. What you want instead is a few numbers that sum up each book, each one a question you could ask of any market. Measure three of them on the same three books; the third buys $1M and watches where the mid ends up.

Step 2 of 3

Measure each number on all three books, and see which venue leads on each.

NumberABC
Costspread, bps of the mid, lower is better???
Depthdollars at best bid and ask, more is better???
Impactbps the mid moves per $1M, lower is better???

Nothing measured yet. Each button measures one number on all three books and fills in its row.

Cost is the spread in basis points of the mid: what you lose if you buy and sell again at once. A market order pays half of it, so lower is better, and A leads with 2.

Depth is the dollars waiting at the best bid and the best ask. It tells you roughly how big an order can be before it pays more than half the spread. More is better, and B leads with $1.2 million.

Impact is how far $1M of net buying moves the price, in basis points, and lower is better. It sees the book behind the best prices, which Depth can't. Behind B's big first queue the book is thin, so $1M moves its mid 2.5 basis points, while C's thick book holds it to 1.

No venue leads on all three, so which one matters depends on your order. The next figure shows where each takes over.

These are the three Aperiodic indices: the Cost Index, the Depth Index and the Impact Index. Each is worked out the same way for every perpetual it covers, so bitcoin, a small coin and a perpetual on Tesla or gold sit on one board. On real data the Impact Index doesn't push $1M into a book. It estimates Kyle's lambda from the trades themselves (lesson 6) and scales it to $1M of net taker flow.

The maths

For a book with best bid b and best ask a, sizes B and A waiting at them, and mid m = (a + b) / 2:

Cost = (a − b) / m × 10,000

Depth = b · B + a · A

With Kyle's lambda λ, the price return per coin of net taker buying, and the contract's price p:

Impact = λ × (1,000,000 / p) × 10,000

A market buy of Q dollars, filled in pieces of qi dollars at prices pi, pays above the mid:

Σ qi · (pi − m) / (Q · m) × 10,000

While the whole order fits at the best ask, that is Cost / 2.

Which number decides

To see where each number takes over, try every order size from $10,000 to $10 million and note the cheapest venue at each. Then make the queue at B's best ask bigger or smaller, and search again.

Step 3 of 3

Run the search from $10k to $10M and see where the cheapest venue changes. Then change the queue at B's best ask and run it again.

051015bps$10k$100k$1M$10M
$600k

Not searched yet. The search tries every order size from $10k to $10M on all three books.

The cheapest venue changes twice. Up to $250,000 the order fits in A's first prices and the spread is nearly all of what it pays, so the Cost decides. From there to about $1.6 million B wins, because its big first queue fills the order, or a large part of it, at 3 basis points: the Depth decides. Past that every first queue is used up, and what counts is how slowly the price climbs as you keep buying. The Impact decides, and C wins.

Give B a bigger queue and its stretch grows: with $1.5 million at its best ask, B stays cheapest up to $3.3 million. Past that, C still wins. Depth counts only the first queue on each side, and Impact is the number that tells you about the rest.

In real data

One bar of bitcoin, on all three

NumberOne barField
Cost0.0096 bpsspread_bps, bar from 14:00
Depth$1.55Mtotal_dollar_depth, bar from 14:00
Impact0.17 bps per $1Mkyle_like_lambda, minute from 14:38

The table holds the three inputs for Binance's bitcoin perpetual. In the five-minute bar from 14:00 UTC on 14 May 2025, the one from lesson 1, the spread was 0.0096 basis points: one tick of 10 cents on a coin at 103,805.65 dollars. About $1.55 million waited at the best bid and ask.

For impact, take the minute of trades from lesson 3, from 14:38 UTC on 11 June 2025. Its Kyle's lambda says each bitcoin of net taker buying moved the price 0.019 basis points. At that minute's close of 109,927 dollars, $1M is 9.1 bitcoin, so $1M of net buying moved it 0.17 basis points.

These are single bars, not the indices. Each index takes a contract's last day of five-minute bars: the Cost Index is the median of the day's spreads, the Depth Index the average of its dollars at the best prices, and the Impact Index the median of its lambda, in basis points per $1M. The live boards for Cost, Depth and Impact put bitcoin next to smaller coins and to perpetuals on US stocks and commodities. Each bar's spread and dollars at the best prices are in ƒL1 Liquidity, and its lambda in ƒImpact.

Binance BTC-USDT perpetual: the five-minute bar from 14:00 UTC on 14 May 2025 (lesson 1's bar), from Aperiodic's free sample, and the minute from 14:38 UTC on 11 June 2025 (lesson 3's minute), built from Aperiodic's raw trades. Prices in US dollars. Single bars, not the indices.

What you learned

Cost
The spread in basis points of the mid: what buying and selling again at once loses. A market order pays half. Lower is better.
Depth
The dollars waiting at the best bid and the best ask: roughly how big an order can be before it pays more than half the spread. More is better.
Impact
How far $1M of net taker buying or selling moves the price, in basis points. It sees the book behind the best prices. Lower is better.
Order size
Small orders pay mostly the spread. Orders bigger than the first queue pay for depth, and the biggest for impact.
Any market
The same three numbers compare venues, coins and stock perpetuals, because each means the same thing on any book.

Check yourself

  1. 1. Venue X has a spread of 2 bps and $50,000 at its best ask. Venue Y has a spread of 8 bps and $2 million at its best ask. Where does a $20,000 market buy cost less?

  2. 2. You want to buy $5 million on a venue whose best ask holds $500,000. Which number tells you most about what it will cost?

  3. 3. A market's Impact is 4 bps per $1M. Roughly how far does $1M of net buying move its price?

Lesson 10 of 10

Behind the numbers

Why is market data so hard to get right, and how does bad data make a backtest lie?

6 min

So far: Cost, Depth and Impact are three numbers you can read off any market's book, and the same three compare venues, coins and stock perpetuals (lesson 9).

Every real number in this guide was worked out from records of trades and quotes. A backtest does the same for a strategy: it replays the records and adds up what the strategy would have made. If the records hold something you couldn't have known at the time, or miss something that happened, the backtest is wrong. Some of those faults make a strategy look better than it would have done.

A backtest on bad data

Here is a toy strategy on six toy coins over four months. Every midnight it buys the two coins that rose most the day before, and sells them at the next midnight. If one falls 8% below what it paid, it sells that one at once, with a stop.

The grey line is its money on point-in-time data. Put a fault into the data and run it again: the orange line is what the backtest reports.

Step 1 of 1

Tick one fault at a time and run the backtest. Compare the orange line, what the faulty data reports, with the grey one.

  • coin 1
  • coin 2
  • coin 3
  • coin 4
  • coin 5
  • coin 6delisted
6080100120day 1day 30day 60day 90
Faults in your data

Not run yet. Tick the faults to put into the data, then run the backtest. With none ticked, both runs see the same data.

On point-in-time data the strategy loses 11% over the four months. Each fault on its own turns that loss into a gain, and with all three the backtest reports a gain of 53%. The strategy is the same in every run. Only what the backtest knew has changed.

Three ways data goes wrong

A close that is an hour late gives the signal the first hour of the day it trades. The coins that rose most “yesterday” are partly the coins rising right now, and the backtest buys them at the midnight price, from before that hour. It even sees coin 6 open 45% down after its delisting news, in time to skip it. This is look-ahead bias, and any input stamped earlier than you could have had it does the same.

A recorder that falls behind when trading is busiest drops trades, and the busiest minutes are often the sharpest moves. In the toy, five of them set off the stop on a coin the strategy held, and each time the coin ended the day above its stop. Without those minutes in the data, the backtest never sells, and books the recovery. In real life the stop sold, 8% down.

A list of coins made today holds only the coins that survived. Coin 6 jumped, then collapsed when its delisting was announced in the third month, and it is not on today's list. So the backtest never bought it the night before the crash, and never took the loss. This is survivorship bias.

How busy a busy minute is

The minute of bitcoin trades from lesson 3, from 14:38 UTC on 11 June 2025, held 11,692 trades on Binance's perpetual, about 195 a second. A record that is right has every one of them, in order, each stamped with the moment it could first have been seen. Aperiodic records both the exchange's timestamp and the moment each trade reached its collectors, and can build every bar on either clock. On the arrival clock, a bar holds only what had reached the collectors by its close. Its symbol list, Atlas, keeps every delisted instrument with the day it stopped trading.

Binance BTC-USDT perpetual, the minute from 14:38 UTC on 11 June 2025, from Aperiodic's raw trades: lesson 3's minute.

This lesson is a short version of a course of its own. Building market data, which comes later, is about how market data is built and kept right.

What you learned

Point-in-time
Every record holds only what could be known at its timestamp, and nothing is added, dropped or changed later.
Look-ahead bias
An input stamped earlier than you could have had it lets a backtest trade on the future.
Missing data
Gaps fall where trading is busiest, and they can hide the very moves that hurt.
Survivorship bias
A list of markets made today leaves out the ones that failed, and the losses they caused.

Check yourself

  1. 1. Your signal reads each day's close, but the close was taken an hour after the opening price you buy at. What is wrong with the backtest?

  2. 2. You backtest on the coins an exchange lists today. Which coins are missing?

  3. 3. In the figure, which fault took away the days the stop sold?

That's every lesson out so far.

All 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

111 min left
  1. 1. From a square to a book
  2. 2. Why there's a gap
  3. 3. Who's pushing
  4. 4. What the candle leaves out
  5. 5. Walking the book
  6. 6. Every trade leaves a mark
  7. 7. A contract that never expires
  8. 8. A stock that trades on Sunday
  9. 9. Three numbers for any market
  10. 10. Behind the numbers
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