crypto book →magic behind crypto →

Inside a crypto exchange — off-chain matching, on-chain money, 24/7

one order · ambient traffic pausedordersmarket datasettlement / on-chainrisk / ops
order1/30

An order arrives over the REST API, HMAC-signed — you connect directly, no broker in between. Follow it to an instant settlement, then watch the money move on-chain.

API clientsexternal · REST · WebSocket · 24/7API gateway & riskMatching engine — off-chain · 24/7in-memory CLOB · internal ledger · no chain on the hot pathMarket data (WebSocket)Blockchainon-chain · the only on-chain partWallet & custody24/7 ops & maintenanceAccounts, fees & earnorders in →← WebSocket push to clientson-chain deposit (waits for confirmations) →REST clientorders · REST APIWebSocket clientlive book · 24/7Deposit / withdrawcoins on-chainAPI gatewayHMAC key auth · rate limitBalance & riskfunds · margin · self-tradeself-tradeSequencerorder id · timestampAck · WebSocket pushfills back to clientOrder book (CLOB)22 levelsMatch loopmatch 5.5 µsµsInternal ledgerinstant off-chain settle · custodialcustodialLiquidation · funding (perps)margin call · funding rateBook feeddepth · diffsTrade & tickerprints · 24h statsBlockchain nodesBTC / ETH / … full nodesConfirmationscredit after N blocksDeposit watcherscan chain → creditHot walletonline · withdrawalsWithdrawal signersign tx → broadcastCold walletoffline · most fundsHot standbyreplicate · promote on failoverRolling upgradedrain shard · deploy · rejoinPer-market pausehalt one pair, rest keep tradingKYC / onboardingidentity · account openFee enginemaker/taker · tiersSub-accountsisolated balances · keysStaking / earnyield · from cold

Trace mode. The ambient traffic is paused so you can follow exactly one order, plus the on-chain money flow. Press next ▸ to walk it: an order clears balance & risk, the off-chain engine crosses it and it settles instantly on the internal ledger; then a deposit and a withdrawal move coins on-chain through nodes, confirmations and hot/cold custody; finally the always-on ops and account-plane services. Switch to Live traffic to see it all at once. Hover any module for its job and data in/out.

Explained in the book

zoom in

The flows that make crypto different

The order book is the same as any exchange. What's different is the edges — where money crosses the chain, and where leverage gets force-closed. Both are opened up here into their own sub-components, step by step.

1Deposits & withdrawals — the on-chain ↔ off-chain bridge

The only part that touches a blockchain. A deposit waits for the chain to be final before the ledger is credited; a withdrawal clears risk off-chain, then signs from the hot wallet and broadcasts. Every step is tagged on-chain or off-chain.

DEPOSIT ↔ WITHDRAWAL
step 1/16
↓ deposit · money in↑ withdrawal · money outoff-chain

Money IN is the on-chain half. You send coins to your deposit address — and the exchange cannot credit you until the chain says the transaction is final.

the deposit crosses the boundary once — 4 on-chain steps, then 2 off-chain to credit you.

01User sendschain

tx → your deposit address

02Mempoolchain

unconfirmed, waiting

03Minedchain

included in a block

04Confirmationschain

wait for N blocks

05Deposit watcheroff

node sees confirmed tx

06Credit ledgeroff

balance, ready to trade

confirmations

0/3
internal balance0.50 BTC
hot wallet12.4 BTC
The hot wallet is small & online (withdrawals); the bulk sits in offline COLD storage, never on the request path.
Explained in the book

2Perpetual futures — the liquidation engine

Most crypto volume is leveraged perps. Watch a 10x long get marked, breach maintenance margin, get liquidated, and how the insurance fund (then auto-deleveraging) keeps the exchange solvent.

PERPS · LIQUIDATION
step 1/11

Leverage makes blow-ups fast, so a risk engine marks every position in real time and force-closes any that runs out of margin. Watch a 10x long get liquidated.

01Open position

10x long · margin posted

02Mark price

index-based, not last trade

03Margin ratio

equity vs maintenance

04Liquidation trigger

equity < maintenance

05Liquidation engine

cancel orders, take position

06Close in market

fill the position out

07Insurance fund

covers shortfall / takes surplus

08Auto-deleveraging

only if the fund is empty

mark price

100.0

mark vs liquidation

liq 90.7entry 100
100entry
90.7liq price
margin health100%
positionOPEN
insurance fund$18.4M
Explained in the book

3The order lifecycle — a state machine

An order isn't a moment — it moves through states (NEW → OPEN → PARTIALLY_FILLED → FILLED), with CANCELED / REJECTED branches and post-only / IOC variants.

ORDER LIFECYCLE
step 1/10

An order isn't a moment — it's a lifecycle of states. Follow one LIMIT BUY 10 @ 100 (GTC) through them, plus the branches and what post-only / IOC do differently.

NEWOPENPARTIALLY_FILLEDFILLED
branches:CANCELEDREJECTEDEXPIRED

order

BUY 10 @ 100.00

LIMIT · GTC

filled0 / 10

event log

Explained in the book

4Fees & sub-accounts

Who pays what, and how funds are organized: isolated sub-accounts under a master, a volume-based fee-tier ladder, and the worked maker / taker fee on a fill.

FEES & SUB-ACCOUNTS
step 1/8

Who pays what, and how funds are organized — fees and sub-accounts.

Master account
Spot desk₿ 4.20
Perps desk$ 1.2M
Bot #1$ 240k

worked fee · fill 10 @ 100

step to a TAKER / MAKER fill…

tier30d volmaker bpstaker bps
Regular< $1M10.010.0
VIP 1≥ $1M8.09.0
VIP 2≥ $5M5.07.0
VIP 3≥ $25M2.04.0

1 bp = 0.01%. Takers usually pay more than makers — resting liquidity is what the exchange is buying.

Explained in the book

the other model

A DEX — no order book, no custodian

Everything above is a centralized exchange. The other half of crypto trading is the decentralized exchange: no custodian and no order book — you trade against a liquidity pool priced by the constant-product formula x · y = k, on-chain. Watch a swap slide along the curve, and see where slippage and impermanent loss come from.

DEX · AMM (x · y = k)
step 1/7

A DEX has no order book and no custodian. You trade against a liquidity POOL, priced by one formula: x · y = k. The ratio of the reserves IS the price.

USDCETH reserve →1000 ETH · 2.000M USDC

spot price (USDC / ETH)

2,000

1000ETH (x)
2.00MUSDC (y)
k = x · y · constant ✓

2,000,000,000

swap to see slippage…
Explained in the book

never closes

How a 24/7 exchange goes to maintenance — without going down

A stock exchange deploys overnight, in the gap between the close and the next open. A crypto exchange has no such gap — it trades every second of every day. So maintenance has to happen with the market live. Step through the three techniques.

24/7 MAINTENANCE
step 1/11

A 24/7 exchange never closes — there is no daily market close to deploy in. Every market shard runs a PRIMARY plus a HOT STANDBY that replays the exact same sequenced event log, so it is always a perfect copy.

01Hot standby replicates

same sequenced event log

02Drain the shard

stop new orders, finish in-flight

03Promote standby

sub-second, same endpoint

04Upgrade & rejoin

old primary → new standby

05Roll to next shard

the rest keep trading

06Per-market pause

halt one pair only

07Re-open via auction

re-discover a fair price

Exchange statusUP · all markets live · uptime 99.99%
BTC-USDTv41
LIVE primarystandby
ETH-USDTv41
LIVE primarystandby
SOL-USDTv41
LIVE primarystandby
ADA-USDTv41
LIVE primarystandby
fleet upgraded to v420 / 4

Each market is its own shard with a hot standby. Maintenance is always scoped to one shard or one market — the exchange as a whole stays UP.

Explained in the book

How a crypto exchange works — off-chain matching, on-chain money

A centralized crypto exchange looks, on the inside, a lot like a stock exchange: an in-memory central limit order book matched by price-time priority, off-chain, in microseconds. The blockchain is far too slow to match orders on — it only ever handles deposits and withdrawals. Because the exchange custodies your coins, trades settle instantly against an internal ledger. The trade-offs that make it different are custody (“not your keys, not your coins”) and the fact that it runs 24/7, so it must do maintenance with the market live.

This page is about the exchange machinery. The fundamentals — why virtual money has value, what a blockchain actually is, and how mining works — are a separate story: the magic behind crypto →

Built by Ashutosh Pandeyabout →