Implement comprehensive transformation module with safety limits and validations
- Introduced a new transformation module that includes safety limits for trade operations, enhancing data integrity and preventing errors. - Refactored existing transformation logic into dedicated classes and functions, improving modularity and maintainability. - Added detailed validation for trade sizes, prices, and symbol formats, ensuring compliance with trading rules. - Implemented logging for significant operations and validation checks, aiding in monitoring and debugging. - Created a changelog to document the new features and changes, providing clarity for future development. - Developed extensive unit tests to cover the new functionality, ensuring reliability and preventing regressions. These changes significantly enhance the architecture of the transformation module, making it more robust and easier to manage.
This commit is contained in:
@@ -10,7 +10,12 @@ from decimal import Decimal
|
||||
from typing import Dict, List, Optional, Any, Callable
|
||||
from collections import defaultdict
|
||||
|
||||
from ..data_types import StandardizedTrade, OHLCVCandle, CandleProcessingConfig, ProcessingStats
|
||||
from ..data_types import (
|
||||
StandardizedTrade,
|
||||
OHLCVCandle,
|
||||
CandleProcessingConfig,
|
||||
ProcessingStats
|
||||
)
|
||||
from .bucket import TimeframeBucket
|
||||
|
||||
|
||||
@@ -71,6 +76,7 @@ class RealTimeCandleProcessor:
|
||||
|
||||
# Stats tracking
|
||||
self.stats = ProcessingStats()
|
||||
self.stats.active_timeframes = len(self.config.timeframes)
|
||||
|
||||
def add_candle_callback(self, callback: Callable[[OHLCVCandle], None]) -> None:
|
||||
"""Add callback to be called when candle is completed."""
|
||||
@@ -87,6 +93,7 @@ class RealTimeCandleProcessor:
|
||||
List of completed candles (if any time boundaries were crossed)
|
||||
"""
|
||||
self.stats.trades_processed += 1
|
||||
self.stats.last_trade_time = trade.timestamp
|
||||
|
||||
completed_candles = []
|
||||
for timeframe in self.config.timeframes:
|
||||
@@ -94,6 +101,7 @@ class RealTimeCandleProcessor:
|
||||
if completed:
|
||||
completed_candles.append(completed)
|
||||
self.stats.candles_emitted += 1
|
||||
self.stats.last_candle_time = completed.end_time
|
||||
|
||||
return completed_candles
|
||||
|
||||
@@ -196,6 +204,7 @@ class RealTimeCandleProcessor:
|
||||
except Exception as e:
|
||||
if self.logger:
|
||||
self.logger.error(f"Error in candle callback: {e}")
|
||||
self.stats.errors_count += 1
|
||||
|
||||
def get_current_candles(self, incomplete: bool = True) -> List[OHLCVCandle]:
|
||||
"""
|
||||
@@ -221,15 +230,20 @@ class RealTimeCandleProcessor:
|
||||
candle = bucket.to_candle(is_complete=True)
|
||||
completed.append(candle)
|
||||
self._emit_candle(candle)
|
||||
self.stats.candles_emitted += 1
|
||||
self.current_buckets.clear()
|
||||
return completed
|
||||
|
||||
def get_stats(self) -> Dict[str, Any]:
|
||||
"""Get processing statistics."""
|
||||
return {
|
||||
"component": self.component_name,
|
||||
"stats": self.stats.to_dict()
|
||||
}
|
||||
stats_dict = self.stats.to_dict()
|
||||
stats_dict.update({
|
||||
'component': self.component_name,
|
||||
'symbol': self.symbol,
|
||||
'exchange': self.exchange,
|
||||
'active_timeframes': list(self.current_buckets.keys())
|
||||
})
|
||||
return stats_dict
|
||||
|
||||
|
||||
__all__ = ['RealTimeCandleProcessor']
|
||||
Reference in New Issue
Block a user