Example gallery¶
Every figure ob-analytics draws, rendered from the bundled Bitstamp sample. Click a thumbnail for the full figure and the exact code that produced it. New to these? The tutorial builds each one up from first principles.
Depth heatmap
Book snapshot (L3)
Depth chart
Trade tape
Trade size
Volume profile
Cumulative signed volume
Depth bands
Liquidity at touch
Spread
Order outcomes (L3)
Queue position (L3)
Cancellations (L3)
VPIN
Kyle's lambda
Trade imbalance
Transaction costs
The book¶
Depth heatmap¶

Resting volume at each price level over time.
start, end = busiest_window(result.trades)
return plot(
"depth_heatmap",
level="L2",
**prepare.depth_heatmap(
result.depth,
spread=get_spread(result.depth_summary),
trades=result.trades,
col_bias=0.4,
start_time=start,
end_time=end,
),
)
Book snapshot (L3)¶

The bid/ask book at a single timestamp, one bar per resting order.
tp = result.events["timestamp"].iloc[0] + pd.Timedelta(minutes=10)
snap = order_book(result.events, at=tp)
return plot("book_snapshot", level="L3", **prepare.book_snapshot(snap, level="L3"))
Depth chart¶

Cumulative resting volume by price, bids left, asks right.
tp = result.events["timestamp"].iloc[0] + pd.Timedelta(minutes=10)
snap = order_book(result.events, at=tp)
return plot("depth_chart", level="L2", **prepare.book_snapshot(snap, level="L2"))
Trades¶
Trade tape¶

Executions against the mid price, marked by aggressor side.
start, end = busiest_window(result.trades)
return plot(
"trade_tape",
level="L2",
**prepare.trade_tape(
result.trades,
spread=get_spread(result.depth_summary),
start_time=start,
end_time=end,
level="L2",
),
)
Trade size¶

How many trades fell in each size range, buys above and sells below.
Volume profile¶

The size traded in each price range, buys and sells stacked.
Cumulative signed volume¶

The running sum of buy volume minus sell volume.
return plot(
"cumulative_signed_volume",
level="L2",
**prepare.cumulative_signed_volume(result.trades),
)
Liquidity¶
Depth bands¶

Cumulative resting volume in basis-point bands around the mid.
start, end = busiest_window(result.trades)
return plot(
"depth_bands",
level="L2",
**prepare.depth_bands(result.depth_summary, start_time=start, end_time=end),
)
Liquidity at touch¶

Resting volume at the best bid and ask over time.
start, end = busiest_window(result.trades)
return plot(
"liquidity_at_touch",
level="L2",
**prepare.liquidity_at_touch(
result.depth_summary, start_time=start, end_time=end, level="L2"
),
)
Spread¶

The quoted spread over time, with its range in each window.
Order lifecycles¶
Order outcomes (L3)¶

The share of orders that filled, by distance from the touch at placement.
Queue position (L3)¶

Each order's FIFO rank at the touch over time.
start, end = busiest_window(result.trades)
return plot(
"queue_position",
level="L3",
**prepare.queue_position(result.events, start_time=start, end_time=end),
)
Cancellations (L3)¶

Cancellations by age and distance from the touch.
Flow toxicity¶
VPIN¶

Volume-synchronised probability of informed trading.
# Twenty buckets over the session, averaged ten at a time: the default
# 50-bucket window would never fill on a 30-minute sample.
# The trades store whole lots; lot_size turns their total into BTC.
total = result.trades["volume"].sum() * result.config.lot_size
v = flow_toxicity.vpin(result.trades, bucket_volume=total / 20, n_buckets=10)
return plot("vpin", **prepare.vpin(v, threshold=0.7))
Kyle's lambda¶

Price impact per unit of signed order flow.
# A short regression window gives more points, so the scatter reads as a
# cloud around the fit rather than a bare line.
return plot(
"kyle_lambda",
**prepare.kyle_lambda(flow_toxicity.kyle_lambda(result.trades, window="1min")),
)
Trade imbalance¶

Net buy-minus-sell volume per minute.
# The registered metric draws the last trade price of each window in the
# quote currency; trade_imbalance(result.trades) is the same table.
return result.plot("trade_imbalance", window="1min")
Transaction cost¶
Transaction costs¶

The effective spread split into realized spread and price impact.