Order Book Reconstruction
Enterprise helpers rebuild Lighter order books from checkpoints and deltas.
Use the official clients for typed requests across market data, order-level routes, data-quality monitoring, and wallet/web3 flows.
Order book reconstruction
Enterprise helpers rebuild Lighter tick history from checkpoints and deltas.
- Tier
- Enterprise
- For
- Tick-level Lighter order book history
- Preferred path
- Auto-paginating iterator
# Orderbook Reconstruction (Enterprise tier only)from oxarchive import Client, OrderBookReconstructor
client = Client(api_key="0xa_your_api_key")
# Option 1: Auto-paginating iterator (recommended for large time ranges)# Automatically handles pagination, fetching up to 1,000 deltas per requestfor snapshot in client.lighter.orderbook.iterate_tick_history( "BTC", start="2026-01-01T00:00:00Z", end="2026-01-01T12:00:00Z" # 12 hours of data): print(f"{snapshot.timestamp}: mid={snapshot.mid_price}") if some_condition: break # Early exit supported
# Option 2: Get fully reconstructed snapshots (single page)snapshots = client.lighter.orderbook.history_reconstructed( "BTC", start="2026-01-01T00:00:00Z", end="2026-01-01T01:00:00Z")for ob in snapshots: print(f"{ob.timestamp}: bid={ob.bids[0].px} ask={ob.asks[0].px}")
# Option 3: Get raw tick data for custom reconstructiontick_data = client.lighter.orderbook.history_tick("BTC", start=start, end=end)print(f"Checkpoint: {len(tick_data.checkpoint.bids)} bids")print(f"Deltas: {len(tick_data.deltas)} updates")
# Check for sequence gapsgaps = OrderBookReconstructor.detect_gaps(tick_data.deltas)if gaps: print("Gaps detected:", gaps)| Method | Best use | Notes |
|---|---|---|
| iterateTickHistory() | Long windows and production replay | Auto-paginates and handles large delta ranges cleanly. |
| historyTick() | Raw checkpoints and deltas | Single page, maximum 1,000 deltas. |
| historyReconstructed() | Direct reconstructed snapshots | Single page when you need the finished book immediately. |
| detectGaps() | Continuity checks | Use before backtests or downstream reconstruction pipelines. |