02 · WebSocket · snapshot plus deltas · computed in your browser
Order book microstructure, checksum verified
This page keeps its own copy of Kraken's order book, the list of prices where people are waiting to buy or sell and how much, and checks it against the exchange's fingerprint of the book (a CRC32 checksum) after every update. From that copy it shows where buyers and sellers wait, how tight the market is, whether buying pressure moves the price, and how much the price swings.
Source Kraken WebSocket API v2 (book, trade and instrument channels) · Transport: one WebSocket to wss://ws.kraken.com/v2, public, no authentication · Terms: Kraken legal and terms of service
Where buyers and sellers are waiting
Each column is the order book, half a second apart. Stronger color means more BTC waiting at that price; dots are trades, sized by amount.
How this is measured
Every 500 ms the page copies the whole local book (100 price levels per side) into a new column. Each pixel row is a price bucket of a fixed width, and its color is the total size resting in that bucket, on a log scale between the 2nd and 99.5th percentile of visible buckets, once data arrives. Hatched grey marks prices past the 100th level, which the subscription does not return, and moments with no connection.
The window is a fraction of mid either side (the price window control). It recenters only when mid leaves the middle 60% of the window, so the picture does not jitter. Until 4 minutes of columns exist, the time axis spans from the first column to now. Lines are the best bid and best ask, drawn 1 px outside their own price so both stay visible when the gap is one tick. Trade circles have area proportional to size; time is arrival time on this computer.
How these numbers are measured
Pb and Pa are the best bid and ask prices, Qb and Qa the sizes waiting there. A basis point (bps) is 0.01%. One tick is the smallest price step, read from the instrument's precision. Waiting for the first verified book.
For Book verified, after every book message the page computes a CRC32 over its own top 10 levels per side and compares it with the exchange's. No messages yet.
Trades per minute counts trades by arrival time over the last 60 s and appears once 60 s have passed.
Price swings is realized volatility. The mid is sampled at the end of every exchange second, log returns r are taken at 1 s or 10 s spacing over the last 5 minutes, RV = sqrt(sum r^2), and the result is annualized by sqrt(365 * 86,400 / window seconds). If returns were independent and Gaussian, its relative error would be about 1/sqrt(2n) for n returns. It appears after 120 s of data.
How much is waiting near the price?
Coins waiting to buy (left) and to sell (right), added up from the best price outward (cumulative depth, 100 levels a side).
Waiting for the first verified book.
How this is measured
The band is a fixed 5 basis points (0.05%) either side of mid. Each curve stops at the 100th level, the deepest the subscription returns, so a band total is a lower bound whenever level 100 falls inside it.
Hover reads the size and the dollar value (notional) between the best price and the pointer.
Does buying pressure move the price?
Each dot is one second: net buying pressure at the best prices against how far the mid moved, last 5 minutes (order flow imbalance).
Collecting seconds.
How this is measured
Order flow imbalance follows Cont, Kukanov and Stoikov (2014). Every change of the best quotes adds an event e, with primes marking the previous state:
e = 1{Pb >= Pb'} Qb - 1{Pb <= Pb'} Qb' - 1{Pa <= Pa'} Qa + 1{Pa >= Pa'} Qa'Events are summed per second of exchange time (x, in BTC), and y is the change in mid over the same second (USD). The line is ordinary least squares, dP = a + b OFI, over the last 300 seconds, drawn once 30 seconds are available.
The paper found a linear relation for equities; this tests it live on crypto. A second containing a resync is left out, because its price change has no measured flow behind it. The standard error assumes independent residuals; per second crypto moves are heavy tailed and clustered, so read it as a lower bound on the uncertainty.
How tight is the market, and which side is heavier?
The gap between best bid and ask, and the bids' share of size at the best prices, every half second for 5 minutes.
Waiting for the first verified book.
How this is measured
Spread in basis points is (Pa - Pb) / mid * 10,000. Imbalance is Qb / (Qb + Qa) at the best level only; size one tick away is ignored. Both are sampled every 500 ms by arrival time. Dashed lines mark resyncs and reconnects.
Who is trading, buyers or sellers?
Coins traded every 10 seconds, split by the side that crossed the gap to trade, last 10 minutes.
Waiting for the first trade.
How this is measured
The side is the taker side as Kraken reports it. A buy lifted the ask; a sell hit the bid. The average price is the volume weighted average price (VWAP), sum(price * size) / sum(size).
Bins use arrival time on this computer; the bin still filling and the partial bin at subscription are left out.
How big are the trades?
Trades counted by dollar value (price times size), in tenfold steps, since subscribing.
Waiting for the first trade.
How this is measured
Notional is price times size in USD. Bins are log10 steps, from under $10 through $10 to $100 up to $1M and above. One large order that fills several resting orders appears as several trades.
Latest trades
The last 20, newest first, with exchange time in your time zone.
A buy lifted the ask; a sell hit the bid.
Is the copy exact, and how fresh is it?
Checks against the exchange after every update, and how long each update takes to arrive.
Counts since subscribing
Arrival delay of book updates, ms
Waiting for book updates.
How this is measured
Delay (lag) is arrival time on this computer minus the exchange timestamp, shown per second as the median (p50) and the 95th percentile (p95). It includes the offset between your clock and Kraken's, so its changes over time are more trustworthy than its level.
A checksum mismatch counts as a mismatch and triggers a resync: the page unsubscribes and resubscribes the book and ignores updates until the fresh snapshot verifies. A closed socket reconnects with exponential backoff.
Method
An order book is the list of prices where people wait to buy (bids) or sell (asks), with the amount at each price. Kraken sends the full list once and then only the changes. This page applies each change, checks its copy against the exchange's checksum, and computes every number above from that copy and the stream of trades.
Book maintenance
The page subscribes to Kraken's book channel at depth 100. The first message is a snapshot of the best 100 price levels on each side. Every later message lists only the levels that changed, each with its new total size, and a size of zero removes the level. Each side is held as a sorted array (bids descending, asks ascending) with binary search for insert, update and delete.
After every update both sides are cut back to 100 levels. The exchange stops sending changes for a level once it falls past the subscribed depth, so a level kept beyond that point would carry a stale size. The checksum covers only the top 10 levels and cannot catch a missed truncation, so the test suite checks it separately against a captured stream.
Checksum
Every book message carries a CRC32 of the exchange's own book. The page builds the same string from its local copy, taking the 10 best asks in ascending price, then the 10 best bids in descending price, each price and size printed with the instrument's precision, decimal point removed, leading zeros stripped. Precision is read from the instrument channel when the connection opens (for BTC/USD, 1 decimal for price and 8 for size).
Formatting is where implementations fail. A size of 0.0157 must print as 0.01570000 and contribute 1570000; printing the shortest decimal form, 0.0157, gives a different string and every checksum fails. On a mismatch the page counts it, unsubscribes and resubscribes the book, ignores updates until the fresh snapshot verifies, and counts the resync.
Top of book
With best bid price Pb and size Qb, and best ask price Pa and size Qa:
The microprice weights each price by the size on the opposite side, so a heavy bid pulls it toward the ask. It is a better guess than the mid at where the next trade will print only to the extent that touch size carries information, which the imbalance chart lets you watch.
Order flow imbalance
Following Cont, Kukanov and Stoikov (2014), every change of the best quotes contributes an event e, where primes mark the previous state:
An unchanged quote contributes its size change. A bid that moves up adds its whole new size, a bid that moves down removes its whole old size, and the ask side mirrors this with the opposite sign. Events are summed over each second of exchange time to give OFI, and the change in mid over the same second is dP. The scatter fits dP = a + b OFI by ordinary least squares over the last 300 seconds:
The paper found a linear relation between order flow imbalance and short horizon price changes for US equities. Here it is tested live on one crypto venue. A second that contains a resync is left out, because its price change has no measured flow behind it. The standard error assumes independent residuals with equal variance; per second crypto returns are heavy tailed and clustered, so read it as a lower bound on the uncertainty.
Realized volatility
The mid is sampled on a fixed grid, taking the last mid at the end of each exchange second, carried forward through quiet seconds. With log returns r = ln(m_i / m_(i-1)) over a window of T seconds:
The window is the last 300 seconds, which gives 300 returns at 1 s sampling and 30 at 10 s. Using 365 days reflects a market that trades every day; the annualized figure rescales five minutes of movement and says nothing about the coming year. If returns were independent and Gaussian, the relative standard error from n returns would be about 1/sqrt(2n), roughly 4% at 300 returns and 13% at 30.
Finer sampling usually reads higher. The observed mid is the underlying price plus noise from tick discreteness and quotes that flicker back and forth, and that noise adds about 2 n η² to the sum of squares for n returns with noise variance η². It grows with the number of returns while the underlying variance does not, so the gap between the two figures is a live estimate of microstructure noise. When the 10 s figure is the higher one, price moved in short runs within the window, which noise cannot produce; with 30 returns that can also be sampling error. The tile compares the gap with twice its standard error before naming either cause.
Limitations
- One venue. Kraken's book is a slice of the market for each pair; other exchanges are not seen.
- Depth 100 only. Nothing past the 100th level on either side is visible, and the heatmap hatches that unobserved range in grey.
- The trade side is the taker side exactly as the exchange reports it.
- Delay includes the offset between your clock and Kraken's. Its level is only as good as your clock sync; its changes over time are more trustworthy.
- OFI, mid changes and realized volatility use exchange timestamps. The heatmap, spread chart, trade flow and trades per minute use arrival time on this computer.
- Everything resets when the symbol changes or the page reloads; nothing is stored. Painting runs at a few frames a second, decoupled from the message rate, and pausing the display stops painting but not ingestion or verification.
Market data from the Kraken public WebSocket API. Not investment advice. Back to the portfolio