β‘ Overview
The GoQuant Real-Time Trade Simulator is a Python-based platform that simulates live trading scenarios using OKX's Level 2 (L2) order book data. Designed for quant traders and developers, it predicts execution costs (slippage, fees, market impact), analyzes maker/taker behavior, and measures internal latencyβall integrated into an interactive Streamlit UI for actionable insights.
π Core Features
β Live Order Book Processing
- WebSocket Integration: Connects to OKX's L2 order book via:
wss://ws.gomarket-cpp.goquant.io/ws/l2-orderbook/okx/BTC-USDT-SWAP - Real-Time Updates: Processes tick-by-tick data to reflect current market conditions.
π Execution Cost Predictions
Slippage Estimation
Uses Quantile Regression (50th percentile) with inputs:
SpreadUSD AmountOrder Book Depth
- Output: Median slippage in basis points (bps).
Fee Calculation
- Rule-based model for maker/taker fees (e.g., Tier 1: 0.02%/0.06%).
Market Impact Modeling
Almgren-Chriss Optimal Execution with dynamic programming:
- Temporary Impact: ( \eta \cdot v^\alpha )
- Permanent Impact: ( \gamma \cdot v^\beta )
- Execution Risk: Volatility + inventory/time horizon.
- Net Execution Cost
[
\text{Net Cost} = \text{Slippage} + \text{Fees} + \text{Market Impact}
] Maker/Taker Classification
- Logistic Regression trained on real-time data (100% accuracy).
Latency Profiling
- Tracks processing time per tick via
time.perf_counter().
- Tracks processing time per tick via
π§ Machine Learning Models
π Quantile Regression (Slippage)
- Library:
statsmodels Performance:
- MSE: 5.39e-05
- RΒ²: 0.798
π Logistic Regression (Maker/Taker)
- Library:
scikit-learn - Features: One-hot encoded
order_type,side, and market depth.
π₯οΈ Streamlit UI
- Left Panel: User inputs (asset, order type, quantity).
- Right Panel: Real-time outputs (costs, probabilities, latency).
βοΈ Optimizations
- NumPy-driven Almgren-Chriss solver.
- Low-latency JSON processing.
- Lazy evaluation to reduce idle computations.
π¦ Setup
pip install -r requirements.txt
streamlit run ui_app.py β FAQ
Q: How accurate are the slippage predictions?
A: The quantile regression model achieves an RΒ² of 0.798, reflecting realistic median execution costs.
Q: Can I test different fee tiers?
A: Yes! The UI supports customizable fee structures.
Q: Is historical data available?
A: Currently, the tool processes live data only.
π Learn more about OKX WebSocket APIs