All 10 lessons on one page · One lesson per page
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
What happens when a crowd wants to trade, and they can't all be there at the same time?
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.
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.
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.
How many sacks do you need right now? Pick a number and buy them. Then see what being in a hurry cost you.
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.
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.
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.
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.
Switch from the notes to the book. The four numbers underneath are what the book tells you.
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.
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
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. You want a sack right now. Which note do you take?
3. The best bid is 51 and the best ask is 53. What are the spread and the mid?
Lesson 2 of 10
Why does buying cost more than selling at the same moment?
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?
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.
Set your gap and how many customers know tomorrow's price, then open the stall. Watch your ledger fill up.
The stall is closed. You quote 48.5 to buy and 51.5 to sell. Open the stall and watch who comes.
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.
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.
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.
Drag the two queues. Watch the weighted mid lean toward the shorter one.
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.
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
1. One customer in five knows tomorrow's price, which will move by 5 coins. Which gap breaks even?
2. Ten people wait to buy at 49 and two wait to sell at 51. Where is the weighted mid?
3. News is coming, and more of the people trading know something. What happens to the spread?
Lesson 3 of 10
Every trade has a buyer and a seller. Which one moved the price, and was it a crowd or one big player?
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.
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.
Set how many takers in every ten are buying, then send them in. Watch the price follow the gap between buys and sells.
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.
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.
Switch between a crowd of sellers and one big seller. Both sell the same amount, so look at the runs on the tape.
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.
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.
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.
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
z = −0.1: right by the average
How busy: how far the price moved around, in coins
z = 0.0: right by the average
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.
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)
1. In one minute, takers bought 30 bitcoin and sold 50. What was the volume delta?
2. One order sells 12 sacks against a board with one sack on each note. How many trades does the tape show?
3. Which minute gets the most negative flow toxicity score?
Lesson 4 of 10
What does a five-minute candle throw away?
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.
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.
Pick a tape and play it. Then play the other two, and compare the candle each one leaves.
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.
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.
Pick a tape, then read it three ways: how the price stepped, how big the trades were, and who did the taking.
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.
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.
Move more of the six-coin fall into a single trade. Watch bipower variation fall behind realised variance.
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.
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)
1. Two five-minute candles are identical. Were the trades inside them the same?
2. A price falls six coins, four of them in a single trade. Is its jump ratio nearer 0 or nearer 1?
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
What does it cost to buy more than the best ask holds?
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).
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.
Pick an order size and send it. Watch it take the asks level by level, and see where its average price lands.
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.
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
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.
Drag the order size. Compare what the same order pays on a thick book and on a thin one.
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.
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.
Add up the first 5, 10, 20 or 25 levels on each side. Watch which side comes out heavier.
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.
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)
1. The best ask holds 10 units. You buy 8. What is your slippage?
2. Halve what waits at every level. What happens to the slippage of the same order?
3. On the first five levels, 60 units wait to buy and 40 to sell. What is the book imbalance?
Lesson 6 of 10
After a big order, how much of the move stays?
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.
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.
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.
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.
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.
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.
Make the book thinner or thicker. Watch every trade's move grow or shrink, and the line's slope with them.
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.
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|)
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.
Change how many trades ahead to look. Watch where the price was by then, after each big buy.
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.
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. Market A's Kyle's lambda is twice market B's. A 10-unit buy in A moves the price…
3. Five trades after the biggest buys, the price is on average below where they printed. What does that say?
Lesson 7 of 10
How do you trade bitcoin without ever holding any, and what happens when everyone borrowed to do it?
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.
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.
Move the perpetual's price above and below its index. Watch which way the payment flows.
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.
Choose how many traders buy the coin and sell the perpetual, then run the week. Watch the gap, and what the longs pay.
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.
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%.
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.
Pick who buys and who sells, then trade one contract. Watch open interest and volume part ways.
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.
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.
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.
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.
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%.
1. A perpetual trades at 100.20 while its index is at 100.00. Who pays funding?
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. 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
What is a Tesla perpetual, and what does it do while Nasdaq is closed?
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.
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.
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.
Switch how the index is kept while the stock is shut. Watch the basis, and what a long pays in funding.
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.
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))
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.
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.
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.
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
1. A stock closed at 200 on Friday. On Saturday its perpetual trades at 212. What is the gap?
2. In this lesson's toy, why is the spread wider on Saturday?
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
The same asset trades on several venues. Where is it cheapest to trade, where is it deepest, and where is it hardest to move?
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.
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.
Change the size of your order. Watch how much of each book it eats, and which venue it costs least on.
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.
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.
Measure each number on all three books, and see which venue leads on each.
| Number | A | B | C |
|---|---|---|---|
| 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.
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.
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.
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.
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.
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. 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. A market's Impact is 4 bps per $1M. Roughly how far does $1M of net buying move its price?
Lesson 10 of 10
Why is market data so hard to get right, and how does bad data make a backtest lie?
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.
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.
Tick one fault at a time and run the backtest. Compare the orange line, what the faulty data reports, with the grey one.
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.
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.
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.
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. You backtest on the coins an exchange lists today. Which coins are missing?
3. In the figure, which fault took away the days the stop sold?
That's every lesson out so far.
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