A high-performance trade simulator leveraging real-time L2 orderbook data from OKX via WebSocket, with transaction cost and market impact estimation. Built with Python and Dash.
- Real-time L2 orderbook data processing with multi-endpoint fallback
- Slippage, fee, and market impact estimation
- Professional Dash/Plotly UI with Bootstrap styling
- Performance and latency metrics
- AI-powered market analysis using Google's Gemini
- Comprehensive documentation and performance analysis
-
Clone the repository
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Create a
.envfile in the project root - Add
GEMINI_API_KEY=your_key_herefor AI market analysis - Or set this environment variable in your system
- Create a
-
Run the app:
python app.py
app.py: Dash application entry pointwebsocket_client.py: WebSocket client for L2 orderbookmodels.py: Slippage, market impact, and regression modelsfee_model.py: Fee calculation logicutils.py: Helper functions (latency, logging, etc.)gemini_integration.py: AI-powered market analysis
The project includes comprehensive documentation:
DOCUMENTATION.md: Detailed explanation of models, algorithms, and implementationPERFORMANCE_ANALYSIS.md: Performance benchmarks and optimization techniques
-
Linear Regression for Slippage Estimation
- Predicts expected slippage based on order size and market volatility
-
Almgren-Chriss Model for Market Impact
- Estimates both permanent and temporary price impacts
- Accounts for order size, execution time, and market liquidity
-
Logistic Regression for Maker/Taker Proportion
- Predicts probability of order executing as maker vs. taker
- Uses order size and current market spread as features
-
Rule-based Fee Model
- Calculates expected fees based on exchange fee tiers
-
AI Market Analysis
- Uses Google's Gemini AI to analyze orderbook data
- Provides market sentiment and trading strategy recommendations
- Implement real-time model training based on market data
- Add more sophisticated market impact models
- Integrate with exchange APIs for actual order placement
- Develop advanced trade strategy backtesting