ramseshk e0be9f4d40 feat: advanced microstructure — sequencer latency, dealer GEX, tick regime, triangular arb
4 new modules with 20 tests:

#22 Sequencer Latency Detector (live/monitors/sequencer_latency.py):
  Detects stale-state windows between WebSocket and REST API.
  - WebSocket vs REST timestamp delta tracking
  - Transport latency percentiles (p50, p99)
  - Liquidation-triggered stale-state detection
  - Stale asset identification for cross-margin arbitrage

#25 Dealer GEX (microstructure/dealer_gex.py):
  Dealer Gamma Exposure estimation via Black-Scholes.
  - Per-strike gamma × OI × spot² GEX computation
  - Pin level detection (strikes where dealers are long gamma)
  - Net GEX aggregation
  - Signal: fade_breakout (long gamma pinning) vs ride_momentum
    (short gamma amplification)
  - nearest_pin() for distance-to-magnet calculation

#30 Tick-Size Regime Exploitation (microstructure/tick_regime.py):
  Detects when asset price approaches tick-size boundaries.
  - Hyperliquid tick schedule (BTC 0.1/0.5, ETH 0.01/0.05, SOL 0.001/0.005)
  - Boundary approach detection with configurable threshold
  - Linear trend estimation for expected bars-to-cross
  - Signal: widen_quotes or tighten_quotes with urgency classification
  - Per-coin state tracking

#33 Triangular Latency Arb (live/monitors/triangular_arb.py):
  Cross-venue A→B→C triangular arbitrage detection.
  - Internal triangular: BTC-USDT → ETH-BTC → ETH-USDT
  - Cross-venue: price discrepancy across slow/fast venues
  - Latency gap detection between venue pairs
  - Implied cross-rate computation vs direct quote
  - Minimum spread threshold gating
2026-08-10 10:34:56 +08:00

FTDT Quant Lab

Production multi-strategy quant trading system running on Hyperliquid.
Live testnet node, paper trading simulator, historical backtesting, and real-time dashboard.

Live: https://ftdt.io/cv


Stack

Layer Technology
Runtime Python 3.13 (async trading)
API Client nautilus_trader (Hyperliquid SDK, Rust bindings)
Dashboard Next.js 16 (static export) + shadcn/ui + Framer Motion
Design System Hallmark Cobalt — Ubuntu font, hairline borders, cool paper palette
Reverse Proxy Caddy → auto HTTPS
WebSocket FastAPI (live/paper streaming)
Data PostgreSQL 17 (ftdt_quant), JSON metrics files
Backtesting Custom dollar-bar engine + numpy
Infra OVH VPS (4 vCPU, 8GB RAM, Debian 13), 2GB swap

~5,300 lines of Python + TypeScript. 67 commits since July 2026.


Repository Structure

ftdt-quant-lab/
├── live/
│   ├── node.py                  # Live trading node — testnet, 9 strategies
│   └── paper_trader.py          # Paper trading — mainnet data, 10 strategies
├── strategies/
│   ├── orderbook_imbalance.py   # L2 bid/ask volume skew (OBI)
│   ├── iceberg_detection.py     # Whale TWAP accumulation detection
│   ├── funding_arb.py           # Delta-neutral carry — spot/perp funding
│   ├── pairs_trading.py         # BTC/ETH ratio Z-score (1.5σ)
│   ├── avellaneda_stoikov.py    # Dual-sided stochastic control MM
│   ├── kalman_pairs/            # Kalman-filter adaptive hedge ratio
│   ├── hawkes_ofi.py            # Hawkes process order flow
│   ├── deep_lob.py              # Deep LOB CNN feature extraction
│   ├── queue_imbalance.py       # Weighted queue dynamics
│   ├── hurst_vpin.py            # Hurst exponent + VPIN directional
│   ├── hurst_vpin_live.py       # Lightweight Hurst/VPIN for live tick stream
│   └── quant_report.py          # QF-Lib style quant analytics
├── dashboard/
│   ├── server.py                # FastAPI backend — WS, REST, static files
│   └── next/
│       └── src/
│           ├── app/             # Main page + layout
│           ├── components/      # QuantReport, StrategyCard, L2Terminal
│           └── lib/             # Types, API client
├── backtests/
│   ├── run.py                   # Backtest runner
│   └── results/
│       └── historical/          # JSON backtest snapshots (32 entries)
├── common/                      # Shared utilities
│   ├── risk.py, risk_manager.py
│   ├── hyperliquid_api.py
│   └── portfolio.py, metrics.py
├── config/
│   └── fee_tiers.py             # Perp/spot fee schedules
└── infrastructure/
    ├── Caddyfile                # Reverse proxy config
    └── systemd/                 # Service units (pending)

Strategies — Current State

Live Node (Hyperliquid Testnet — 9 strategies, $100 each)

# Strategy Type Asset Size PnL Trades Win
1 Order Book Imbalance reversal BTC 0.000200 $0.00 0 —
2 Iceberg Detection momentum BTC 0.000210 $0.00 2 0%
3 Funding Rate Arb carry BTC 0.000220 $0.00 0 —
4 Pairs Trading stat_arb ETH 0.006000 +$0.74 9 67%
5 Avellaneda-Stoikov market_making BTC 0.000230 -$1.35 32 0%
6 Momentum Breakout momentum ETH 0.000500 $0.00 0 —
7 Mean Reversion reversal ETH 0.000500 $0.00 0 —
8 Kalman Pairs stat_arb ETH 0.005000 $0.00 0 —
9 Hurst VPIN momentum BTC 0.000240 $0.00 0 —

Execution: GTC POST-ONLY limit orders. Signals every 5 ticks (5s), dual-sided for A-S.
Fee model: Maker 0.02% (testnet).

Paper Trader (Hyperliquid Mainnet data — 10 strategies, $100 each)

Same set + Queue Imbalance. Real mainnet orderbook + funding data. Fee model: taker 0.05% / maker 0.02%. Trades simulated with 1bps slippage.


Historical Backtests

32 backtest snapshots across 8 strategies × 4 coins (BTC, ETH, HYPE, VVV).
Hurst/VPIN BTC: 46 trades, 96% win rate, +1.10% on synthetic trending data.


Priority Analysis

Strategies showing real signal

Strategy Signal Status
Pairs Trading ✅ +$0.74, 67% win rate — only profitable live strategy
Avellaneda-Stoikov ⚠️ 32 trades but losing — spread capture not covering fees
Iceberg Detection ⚠️ 2 trades — rare signals, needs threshold tuning
Hurst VPIN 🔬 96% win in backtest, 0 live trades — very selective
Mean Reversion ⏳ 0 trades — VWAP deviation not crossing 1.0σ
Momentum ⏳ 0 trades — Bollinger 1.2σ too tight for ETH

Recommendation: focus investment here

  1. Pairs Trading — #1 priority. Only live winner. Extend to more pairs (SOL, ARB, OP). Add Kalman dynamic hedge ratio. This is the clearest path to sustained PnL.

  2. Hurst/VPIN — #2 priority. Backtest shows strong edge (96% win). Needs real market data (not synthetic) and 3-day candle feed to trigger more signals. The selectivity IS the edge — don't dilute it.

  3. Avellaneda-Stoikov — Needs inventory control. 32 trades losing because adverse selection. Add skew-aware quoting (update reserve price based on queue imbalance).

  4. Iceberg Detection — Lower detection threshold. Currently requires 7/10 consecutive ticks same direction — too strict.

  5. Funding Rate Arb — Real Hyperliquid funding data already plumbed. Test threshold from 3% → 1% APR. Prefunding detection (predict next rate before announcement).

  6. Backtest engine — Replace synthetic data with real Hyperliquid candles. Add walk-forward optimization. The hurst_vpin.py infrastructure is ready.

Skip for now

  • OBI / Mean Reversion / Momentum — 0 trades. Signal thresholds need fundamental redesign, not just tuning.
  • Cartea-Jaimungal / Gueant MM — academic models, not adapted to crypto microstructure.
  • DeepLOB / Hawkes OFI — dependency-heavy, no live integration.

Next Steps

# Clone and deploy
git clone https://git.ftdt.io/rams/ftdt-quant-lab.git
cd ftdt-quant-lab
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt        # (pending — currently manual)

# Start services
python live/node.py &                  # Trading node
python live/paper_trader.py &          # Paper simulator
python dashboard/server.py --port 9175  # Dashboard backend

Roadmap

  • Docker Compose for reproducible deployment
  • Walk-forward backtest on real Hyperliquid candle data
  • Extend Pairs Trading to BTC/SOL, BTC/ARB
  • Hurst/VPIN 3-day candle feed → real live signals
  • Memory leak proofing — current guard at 512MB RSS
  • systemd service unit files for auto-restart
  • Grafana + Prometheus monitoring dashboard

Built with Hermes Agent · Hallmark Cobalt · Ubuntu fonts

S
Description
Quantitative trading lab — Nautilus Trader strategies on Hyperliquid Testnet. Part of my professional portfolio.
Readme 13 MiB
Languages
HTML 61.6%
Python 33.7%
TypeScript 3.4%
Jupyter Notebook 1.2%