Back to Projects
2024 // MICROSTRUCTURE & PAPER TRADING

DERIBIT LOB MODEL

Real-time limit order book analysis and paper-trading system for Deribit. Streams live order-book snapshots and trades via WebSocket, runs four competing microstructure strategies side-by-side, and displays a live terminal dashboard comparing their performance.

Go to Repo Read Blog
Live terminal dashboard demo
Role
Researcher & Developer
Stack
Python / WebSocket / Rich
Exchange
Deribit (BTC_USDC)
Strategies
4 Competing Models

THE IDEA

Most alpha in liquid crypto markets lives in the microstructure — queue imbalances, order flow, and price-impact dynamics that play out over milliseconds to seconds. This project streams live Deribit order-book snapshots via WebSocket, runs three academic microstructure models in parallel, and wraps them in a composite signal with explicit confidence gating and asymmetric risk management.

The result is a live paper-trading engine that logs every decision — signal values, confidence scores, skip/entry/exit rationale — to a real-time terminal dashboard powered by Rich.

STRATEGIES — MICROSTRUCTURE

Three standalone microstructure strategies run independently, each rooted in a canonical academic model:

StrategyPaperSignal
Cont-de LarrardSIAM J. Financial Math, 2013LOB queue imbalance at best bid/ask
KyleEconometrica, 1985Price-impact coefficient λ from net order flow
OFIJ. Financial Econometrics, 2014Event-by-event order flow imbalance z-score

COMPOSITE ALPHA

The fourth strategy fuses all three microstructure signals plus an Ornstein-Uhlenbeck mean-reversion anchor into a single composite score. Every entry is gated through a multi-layer confidence filter:

  • Confidence check: requires 3 of 4 sub-signals to agree, a favorable vol regime, and no recent price jumps.
  • Asymmetric SL/TP: stop-loss = 5× ATR, take-profit = 20× ATR — a 1:4 risk-reward ratio.
  • 30s cooldown: prevents overtrading; quality over quantity.

The model logs its full reasoning to a live thought-process panel on the dashboard, making every skip and entry fully auditable in real time.

DASHBOARD LAYOUT

The terminal dashboard refreshes twice per second and organises information into five panels:

  • Strategy table: signal, position, trade count, realized / unrealized / total PnL for all four strategies.
  • PnL sparklines: rolling history per strategy, rendered as ASCII bar charts.
  • Signal breakdown: horizontal bars for each Composite Alpha sub-signal plus a confidence meter.
  • Thought process: scrolling log of Composite Alpha decisions with timestamps.
  • Recent trades: last 10 fills across all strategies with side, price, size, position, and PnL delta.

ADDITIONAL MODELS

Three more models are included but inactive by default — they can be enabled in run_model.py:

  • Jump Diffusion: Merton (1976) — drift plus Poisson jump estimation.
  • OU Mean Reversion: Ornstein-Uhlenbeck mean-reverting process.
  • Heston Vol: Heston (1993) — momentum scaled by stochastic vol regime.

KEY RESULTS

4
Competing strategies running simultaneously on live Deribit data
1:4
Asymmetric risk-reward ratio on Composite Alpha (SL = 5× ATR, TP = 20× ATR)
2 Hz
Dashboard refresh rate — real-time signal breakdown and decision logging
3
Academic models implemented: Cont-de Larrard, Kyle, OFI