This project launches Freqtrade with a Redis server to collect liquidation and trade data from Binance WebSocket streams. The data is stored in CSV format and can be accessed by Freqtrade, with the most recent data fetched from Redis.
The system consists of four main components:
- WebSocket Stream Service (
websocket_stream/
): Connects to Binance WebSocket to collect liquidation and trade data - CSV Writer Service (
csv_writer/
): Writes aggregated data from Redis to CSV files - Redis: In-memory data store for real-time data exchange
- Freqtrade: Trading bot that uses the collected data via the
LiquidationStrategy
- Fixed CSV path mismatch between csv_writer.py and Docker volume mount
- Fixed Docker volume mount inconsistencies in docker-compose.yaml
- Eliminated PAIRLIST duplication by creating shared configuration
- Fixed timing synchronization between services
- Enhanced error handling with retry logic and exponential backoff
- Added Redis connection validation with proper timeout handling
- Improved WebSocket reliability with better connection parameters
- Added Docker health checks for better service monitoring
- Centralized configuration in
config.py
to avoid hardcoded values - Better data validation in CSV writer to prevent empty rows
- Added restart policies for Docker containers
- All shared configuration is now centralized in
config.py
- Environment variables supported for flexible deployment
- Fallback values ensure system works even if config import fails
-
Clone and navigate to the project:
git clone <repository> cd freqtrade_redis_ws
-
Start all services:
docker-compose up -d
-
Monitor logs:
docker-compose logs -f
-
Stop services:
docker-compose down
CSV_FILE_PATH
: Custom path for CSV output fileREDIS_HOST
: Redis server hostname (default: redis)REDIS_PORT
: Redis server port (default: 6379)
Edit config.py
to modify the PAIRLIST
array with your desired trading pairs.
The CSV file contains the following columns:
symbol
: Trading pair symboltimestamp
: Data timestampliq_long_count
: Number of long liquidationsliq_short_count
: Number of short liquidationsliq_long_usd_size
: USD value of long liquidationsliq_short_usd_size
: USD value of short liquidationstrade_long_count
: Number of large long tradestrade_short_count
: Number of large short tradestrade_long_usd_size
: USD value of large long tradestrade_short_usd_size
: USD value of large short tradesfunding_rate
: Current funding rate
- Data aggregation interval is currently fixed at 1 minute
- Large trade threshold is set to $10,000 USD
- First data collection round may return empty data
- Comments in some files are in German
- Redis connection failed: Ensure Redis container is healthy
- WebSocket connection issues: Check internet connectivity and Binance API status
- CSV file not created: Verify volume mounts and file permissions
- Empty data in CSV: Wait for market activity or check WebSocket connections
# Check Redis health
docker exec redis redis-cli ping
# Check service logs
docker-compose logs websocket_stream
docker-compose logs csv_writer
├── config.py # Shared configuration
├── docker-compose.yaml # Service orchestration
├── websocket_stream/ # WebSocket data collection
│ ├── Dockerfile
│ └── websocket_stream.py
├── csv_writer/ # CSV data writer
│ ├── Dockerfile
│ └── csv_writer.py
└── freqtrade/ # Trading bot
├── Dockerfile
└── user_data/
└── strategies/
└── LiquidationStrategy.py
- Update
config.py
for new configuration options - Modify the appropriate service (websocket_stream or csv_writer)
- Update Docker containers and test
This project is for educational purposes only. Use at your own risk.