A high-performance real-time trading bot that monitors Binance futures markets for volume imbalances and records price movements.
- Real-time WebSocket streaming from Binance futures markets
- 100ms time window aggregation for ultra-short-term analysis
- Volume skew detection to identify buying/selling pressure
- Forward price measurement at multiple time horizons (50ms, 100ms, 250ms, 500ms)
- CSV data recording with automatic file rotation
- Prometheus metrics for monitoring
- Health check endpoints for service monitoring
- Automatic reconnection with exponential backoff
- Server time synchronization with Binance
- Install dependencies:
pip install -r requirements.txt-
Configure the bot by editing
config/config.yaml -
Run the bot:
python -m src.main --config config/config.yamlpython -m src.main [OPTIONS]
Options:
-c, --config PATH Configuration file path [default: config/config.yaml]
-l, --log-level LEVEL Logging level (DEBUG/INFO/WARNING/ERROR) [default: INFO]
-f, --log-format FORMAT Log format (json/console) [default: console]
--dry-run Run without writing output files
--help Show this message and exitEdit config/config.yaml to configure:
- Symbols: Trading pairs to monitor (e.g., BTCUSDT, ETHUSDT)
- Trigger conditions: Volume thresholds and skew ratios
- Time windows: Aggregation window size and horizons
- Storage: Output directory and file rotation settings
The bot writes CSV files to data/records/ with the following columns:
- Timestamp and symbol information
- Volume data (buy/sell quantities and counts)
- Skew indicators (dominant side, skew ratio)
- Price data (baseline, min, max, first, last)
- Forward price changes at each horizon
- Metadata (measure type, latency)
Access metrics at http://localhost:9108/metrics
Key metrics include:
- Event processing rates
- Trigger detection counts
- Processing latency histograms
- Connection status
- Queue utilization
Access health status at http://localhost:9109/health
The health check monitors:
- WebSocket connection status
- Processing performance
- Queue utilization
- Event rates
The bot consists of several modules:
- WebSocket Manager: Handles Binance stream connections
- Window Aggregator: Aggregates trades into 100ms windows
- Trigger Detector: Identifies volume imbalance conditions
- Price Measurement: Tracks prices at future time points
- Data Recorder: Writes trigger events to CSV files
- Metrics Collector: Exposes Prometheus metrics
- Health Check: Provides service health endpoints
pytest tests/black src/
flake8 src/MIT License