Skip to main content
Use this workflow to compare how liquidity behaves across venues. You will analyze tick-by-tick and time-sampled spreads, measure directional slippage at several order sizes, and profile the latest reconstructed L2 books. The example compares the BTC perpetual on Hyperliquid and Pacifica over the same public interval. It resolves the exact datasets through Catalog and does not require an API key.
Displayed liquidity can be canceled before you trade. Treat BBO, depth metrics, and L2 profiles as historical observations, not fill guarantees.

Install the dependencies

Configure the analysis

Use a short window for tick-level and reconstructed-book analysis. The row caps stop the example instead of silently returning a partial sample.

Resolve an active shared window

Catalog defines the exact source, market, access state, and coverage bounds. Clamp preview datasets to their public UTC day, then search backward for a window where both venues publish BBO observations.
Use one-second BBO samples only to locate a shared active interval. The tick-level query comes next.

Measure tick-by-tick spreads

Set changes_only=True to keep observations where the best price or quantity changed. This preserves quote-event behavior while suppressing deep-book updates that leave BBO unchanged.
Summarize the distribution and displayed top-level notional:
Tick-weighted statistics give more influence to venues that update more often. Build a second summary from non-empty one-second buckets for a closer clock-time comparison. Empty buckets remain absent rather than being forward-filled:
Plot the empirical spread distribution without choosing histogram bins:

Compare depth and directional slippage

depth_metrics(...) reconstructs the book and calculates depth within depth_pct, plus buy and sell slippage for one target notional. Query several notionals to build an execution-cost curve.
Sample at one-second intervals before comparing venues so faster books do not dominate the result:
Plot the median cost on the less liquid side at each target notional:

Profile reconstructed L2 books

Use l2_snapshots(...) when you need the complete price ladder rather than a derived metric. Retain only the latest book in the interval to keep memory use bounded.
Measure displayed notional within 1, 5, 10, and 25 basis points of each latest midpoint:
Confirm that book timestamps are close enough for your comparison. A wide time gap can look like a venue difference when it is a market move.
Plot cumulative displayed notional by distance from the midpoint:

Interpret the result carefully

  • Tick-weighted distributions describe quote-event behavior. Use interval samples when comparing time spent at each spread.
  • Compare markets with equivalent contract multipliers, quote assets, and minimum order sizes. The same base asset does not guarantee identical risk.
  • Depth and slippage are conditional on the chosen notional, depth band, and observation time. Report all three with the result.
  • L2 shows displayed orders. It does not reveal queue position, hidden liquidity, cancellation probability, or your actual fill path.
  • Coverage gaps and reconnects reset reconstructed book state. Do not carry a book across a gap.
  • Add fees, latency, and market impact before turning a liquidity comparison into an execution decision.