Flash Crash Early Warning — Market Microstructure ML Detector
A real-time detector on limit-order-book (LOB) streams that flags microstructure anomalies (order-book imbalance, spoofing, liquidity evaporation) 50–500ms before price dislocation.
Built as a 5-stage hybrid detection cascade: Statistical pre-filter → Isolation Forest → Temporal Convolutional Network (TCN) → Cross-symbol correlation breakdown → Bayesian aggregator. The operating cascade is S1→S2→S3→S5 (Stage-4's Transformer is disabled in the shipped configs/pipeline.yml; the validated correlation-breakdown signal is wired as the real Stage-4 input). Operating point: models/stage3_tcn_prod.pt @ threshold 0.5, trailing-realized-vol gate ≥ 2 bps, 10 s cooldown. Held-out crash recall 0.38–1.0 with zero calm-day alerts.
⚠️ Status: MVP / research prototype. Not production trading software. See Risks & Disclaimer.
The Rust proxy (proxy/) is an experimental ingest path that currently only opens a TCP port; the live feed uses the Node mini-service (binance-stream). See docs/ANALYSIS-2026-08-11.md for the full reality-vs-docs audit.
End-to-end p99: ~27 ms (measured, single-tick cascade) · Open-source first.
Quickstart
Prerequisites
Python 3.11+
Rust 1.75+ (optional — only for the high-performance proxy)
4 GB RAM, 5 GB disk
Option A — Python-only quickstart (recommended for first run)
bash
1# 1. Install Python deps2cd ml
3pip install -r requirements.txt
45# 2. Download a sample of Binance historical data (BTC/USDT, 1 day)6python -m flash_crash_watchdog.data.download_binance \7 --symbol BTCUSDT --date 2021-05-19 --out ../data/
89# 3. Run the offline backtest on the May 19, 2021 BTC flash crash10python -m flash_crash_watchdog.cli backtest \11 --data ../data/BTCUSDT_2021-05-19.parquet \12 --model configs/tcn_baseline.yml
1314# 4. Or: start the live detector against Binance WebSocket15python -m flash_crash_watchdog.cli live --symbol BTCUSDT
Option B — Full stack with Rust proxy (for sub-ms ingest)
bash
1# 1. Build the Rust proxy2cd proxy
3cargo build --release
45# 2. Run the proxy (ingests Binance WebSocket, publishes to localhost:5555)6./target/release/flash-crash-proxy --symbol BTCUSDT --out tcp://127.0.0.1:5555
78# 3. In another terminal, run the Python detector consuming from the proxy9cd../ml
10python -m flash_crash_watchdog.cli live --source tcp://127.0.0.1:5555
Option C — Docker Compose (everything wired up)
bash
1docker-compose up -d
2# Dashboard: http://localhost:30003# Prometheus metrics: http://localhost:9090
Adversarial adaptation: spoofers evolve once they know detectors exist.
Regulatory: any deployment that triggers automated trades requires Reg NMS / MiFID II compliance review.
No financial advice: this software is for research and educational purposes only. The authors are not responsible for any financial losses incurred through its use.
1@software{flash_crash_watchdog,
2 title = {Flash Crash Early Warning: Market Microstructure ML Detector},
3 author = {Z.ai Quant Research},
4 year = {2026},
5 url = {https://github.com/yourusername/flash-crash-watchdog}
6}
References
See the accompanying project brief PDF for the full bibliography (Easley & O'Hara, SEC/CFTC May 2010 report, Ntakaris et al. FI-2010, Vaswani et al. Transformer, etc.).