merge annotate /ANNOTATE/core into /core.
fix chart updates
This commit is contained in:
@@ -4372,3 +4372,78 @@ class DataProvider:
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting report data for multiple pairs: {e}")
|
||||
return {}
|
||||
# ===== ANNOTATION UI SUPPORT METHODS =====
|
||||
# Added to support ANNOTATE app without duplicate data_loader
|
||||
|
||||
def get_data_for_annotation(self, symbol: str, timeframe: str,
|
||||
start_time: Optional[datetime] = None,
|
||||
end_time: Optional[datetime] = None,
|
||||
limit: int = 2500,
|
||||
direction: str = 'latest') -> Optional[pd.DataFrame]:
|
||||
"""
|
||||
Get data specifically for annotation UI needs
|
||||
Combines functionality from the old HistoricalDataLoader
|
||||
"""
|
||||
try:
|
||||
# For live updates (small limit, direction='latest', no time range)
|
||||
is_live_update = (direction == 'latest' and not start_time and not end_time and limit <= 5)
|
||||
|
||||
if is_live_update:
|
||||
# Use get_latest_candles for live updates (combines cached + real-time)
|
||||
logger.debug(f"Getting live candles for annotation UI: {symbol} {timeframe}")
|
||||
return self.get_latest_candles(symbol, timeframe, limit)
|
||||
|
||||
# For historical data with time range
|
||||
if start_time or end_time:
|
||||
# Use DuckDB for historical queries
|
||||
if self.duckdb_storage:
|
||||
df = self.duckdb_storage.get_ohlcv_data(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
limit=limit,
|
||||
direction=direction
|
||||
)
|
||||
if df is not None and not df.empty:
|
||||
return df
|
||||
|
||||
# Fallback to API if DuckDB doesn't have the data
|
||||
logger.info(f"Fetching historical data from API for annotation: {symbol} {timeframe}")
|
||||
return self.get_historical_data(symbol, timeframe, limit, refresh=True)
|
||||
|
||||
# For regular data requests
|
||||
return self.get_historical_data(symbol, timeframe, limit)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error getting data for annotation: {e}")
|
||||
return None
|
||||
|
||||
def get_multi_timeframe_data_for_annotation(self, symbol: str,
|
||||
timeframes: List[str],
|
||||
start_time: Optional[datetime] = None,
|
||||
end_time: Optional[datetime] = None,
|
||||
limit: int = 2500) -> Dict[str, pd.DataFrame]:
|
||||
"""Get data for multiple timeframes at once for annotation UI"""
|
||||
result = {}
|
||||
|
||||
for timeframe in timeframes:
|
||||
df = self.get_data_for_annotation(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
start_time=start_time,
|
||||
end_time=end_time,
|
||||
limit=limit
|
||||
)
|
||||
|
||||
if df is not None and not df.empty:
|
||||
result[timeframe] = df
|
||||
|
||||
logger.info(f"Loaded annotation data for {len(result)}/{len(timeframes)} timeframes")
|
||||
return result
|
||||
|
||||
def disable_startup_mode(self):
|
||||
"""Disable startup mode - annotation UI compatibility method"""
|
||||
# This was used by the old data_loader, now we just ensure fresh data
|
||||
logger.info("Annotation UI requested fresh data mode")
|
||||
pass # Main DataProvider always provides fresh data when requested
|
||||
Reference in New Issue
Block a user