main cleanup

This commit is contained in:
Dobromir Popov
2025-09-30 23:56:36 +03:00
parent 468a2c2a66
commit 608da8233f
52 changed files with 5308 additions and 9985 deletions

View File

@@ -1,6 +1,12 @@
"""
Multi-Timeframe, Multi-Symbol Data Provider
CRITICAL POLICY: NO SYNTHETIC DATA ALLOWED
This module MUST ONLY use real market data from exchanges.
NEVER use np.random.*, mock/fake/synthetic data, or placeholder values.
If data is unavailable: return None/0/empty, log errors, raise exceptions.
See: reports/REAL_MARKET_DATA_POLICY.md
This module consolidates all data functionality including:
- Historical data fetching from Binance API
- Real-time data streaming via WebSocket
@@ -227,6 +233,40 @@ class DataProvider:
logger.warning(f"Error ensuring datetime index: {e}")
return df
def get_price_range_over_period(self, symbol: str, start_time: datetime,
end_time: datetime, timeframe: str = '1m') -> Optional[Dict[str, float]]:
"""Get min/max price and other statistics over a specific time period"""
try:
# Get historical data for the period
data = self.get_historical_data(symbol, timeframe, limit=50000, refresh=False)
if data is None:
return None
# Filter data for the time range
data = data[(data.index >= start_time) & (data.index <= end_time)]
if len(data) == 0:
return None
# Calculate statistics
price_range = {
'min_price': float(data['low'].min()),
'max_price': float(data['high'].max()),
'open_price': float(data.iloc[0]['open']),
'close_price': float(data.iloc[-1]['close']),
'avg_price': float(data['close'].mean()),
'price_volatility': float(data['close'].std()),
'total_volume': float(data['volume'].sum()),
'data_points': len(data),
'time_range_seconds': (end_time - start_time).total_seconds()
}
return price_range
except Exception as e:
logger.error(f"Error getting price range for {symbol}: {e}")
return None
def get_historical_data(self, symbol: str, timeframe: str, limit: int = 1000, refresh: bool = False) -> Optional[pd.DataFrame]:
"""Get historical OHLCV data for a symbol and timeframe"""
try:
@@ -985,6 +1025,33 @@ class DataProvider:
support_levels = sorted(list(set(support_levels)))
resistance_levels = sorted(list(set(resistance_levels)))
# Extract trend context from pivot levels
pivot_context = {
'nested_levels': len(pivot_levels),
'level_details': {}
}
# Get trend info from primary level (level_0)
if 'level_0' in pivot_levels and pivot_levels['level_0']:
level_0 = pivot_levels['level_0']
pivot_context['trend_direction'] = getattr(level_0, 'trend_direction', 'UNKNOWN')
pivot_context['trend_strength'] = getattr(level_0, 'trend_strength', 0.0)
else:
pivot_context['trend_direction'] = 'UNKNOWN'
pivot_context['trend_strength'] = 0.0
# Add details for each level
for level_key, level_data in pivot_levels.items():
if level_data:
level_info = {
'swing_points_count': len(getattr(level_data, 'swing_points', [])),
'support_levels_count': len(getattr(level_data, 'support_levels', [])),
'resistance_levels_count': len(getattr(level_data, 'resistance_levels', [])),
'trend_direction': getattr(level_data, 'trend_direction', 'UNKNOWN'),
'trend_strength': getattr(level_data, 'trend_strength', 0.0)
}
pivot_context['level_details'][level_key] = level_info
# Create PivotBounds object
bounds = PivotBounds(
symbol=symbol,
@@ -994,7 +1061,7 @@ class DataProvider:
volume_min=float(volume_min),
pivot_support_levels=support_levels,
pivot_resistance_levels=resistance_levels,
pivot_context=pivot_levels,
pivot_context=pivot_context,
created_timestamp=datetime.now(),
data_period_start=monthly_data['timestamp'].min(),
data_period_end=monthly_data['timestamp'].max(),