Update OKX configuration and aggregation logic for enhanced multi-timeframe support

- Increased health check interval from 30s to 120s in `okx_config.json`.
- Added support for additional timeframes (1s, 5s, 10s, 15s, 30s) in the aggregation logic across multiple components.
- Updated `CandleProcessingConfig` and `RealTimeCandleProcessor` to handle new timeframes.
- Enhanced validation and parsing functions to include new second-based timeframes.
- Updated database schema to support new timeframes in `schema_clean.sql`.
- Improved documentation to reflect changes in multi-timeframe aggregation capabilities.
This commit is contained in:
Vasily.onl
2025-06-02 12:35:19 +08:00
parent cecb5fd411
commit 02a51521a0
9 changed files with 964 additions and 374 deletions

View File

@@ -17,7 +17,7 @@ The OKX Data Collector provides real-time market data collection from OKX exchan
- **Trades**: Real-time trade executions (`trades` channel)
- **Orderbook**: 5-level order book depth (`books5` channel)
- **Ticker**: 24h ticker statistics (`tickers` channel)
- **Future**: Candle data support planned
- **Candles**: Real-time OHLCV aggregation (1s, 5s, 10s, 15s, 30s, 1m, 5m, 15m, 1h, 4h, 1d)
### 🔧 **Configuration Options**
- Auto-restart on failures
@@ -25,6 +25,7 @@ The OKX Data Collector provides real-time market data collection from OKX exchan
- Raw data storage toggle
- Custom ping/pong timing
- Reconnection attempts configuration
- Multi-timeframe candle aggregation
## Quick Start
@@ -163,6 +164,50 @@ async def main():
asyncio.run(main())
```
### 3. Multi-Timeframe Candle Processing
```python
import asyncio
from data.exchanges.okx import OKXCollector
from data.base_collector import DataType
from data.common import CandleProcessingConfig
async def main():
# Configure multi-timeframe candle processing
candle_config = CandleProcessingConfig(
timeframes=['1s', '5s', '10s', '15s', '30s', '1m', '5m', '15m', '1h'],
auto_save_candles=True,
emit_incomplete_candles=False
)
# Create collector with candle processing
collector = OKXCollector(
symbol='BTC-USDT',
data_types=[DataType.TRADE], # Trades needed for candle aggregation
candle_config=candle_config,
auto_restart=True,
store_raw_data=False # Disable raw storage for production
)
# Add candle callback
def on_candle_completed(candle):
print(f"Completed {candle.timeframe} candle: "
f"OHLCV=({candle.open},{candle.high},{candle.low},{candle.close},{candle.volume}) "
f"at {candle.end_time}")
collector.add_candle_callback(on_candle_completed)
# Start collector
await collector.start()
# Monitor real-time candle generation
await asyncio.sleep(300) # 5 minutes
await collector.stop()
asyncio.run(main())
```
## Configuration
### 1. JSON Configuration File
@@ -876,70 +921,4 @@ class OKXCollector(BaseDataCollector):
health_check_interval: Seconds between health checks
store_raw_data: Whether to store raw OKX data
"""
```
### OKXWebSocketClient Class
```python
class OKXWebSocketClient:
def __init__(self,
component_name: str = "okx_websocket",
ping_interval: float = 25.0,
pong_timeout: float = 10.0,
max_reconnect_attempts: int = 5,
reconnect_delay: float = 5.0):
"""
Initialize OKX WebSocket client.
Args:
component_name: Name for logging
ping_interval: Seconds between ping messages (must be < 30)
pong_timeout: Seconds to wait for pong response
max_reconnect_attempts: Maximum reconnection attempts
reconnect_delay: Initial delay between reconnection attempts
"""
```
### Factory Functions
```python
def create_okx_collector(symbol: str,
data_types: Optional[List[DataType]] = None,
**kwargs) -> BaseDataCollector:
"""
Create OKX collector using convenience function.
Args:
symbol: Trading pair symbol
data_types: Data types to collect
**kwargs: Additional collector parameters
Returns:
OKXCollector instance
"""
def ExchangeFactory.create_collector(config: ExchangeCollectorConfig) -> BaseDataCollector:
"""
Create collector using factory pattern.
Args:
config: Exchange collector configuration
Returns:
Appropriate collector instance
"""
```
---
## Support
For OKX collector issues:
1. **Check Status**: Use `get_status()` and `get_health_status()` methods
2. **Review Logs**: Check logs in `./logs/` directory
3. **Debug Mode**: Set `LOG_LEVEL=DEBUG` for detailed logging
4. **Test Connection**: Run `scripts/test_okx_collector.py`
5. **Verify Configuration**: Check `config/okx_config.json`
For more information, see the main [Data Collectors Documentation](data_collectors.md).
```