WIP oclcv in storage. migrate do duckdb
This commit is contained in:
@@ -36,7 +36,10 @@ class HistoricalDataLoader:
|
||||
self.memory_cache = {}
|
||||
self.cache_ttl = timedelta(minutes=5)
|
||||
|
||||
logger.info("HistoricalDataLoader initialized with existing DataProvider")
|
||||
# Startup mode - allow stale cache for faster loading
|
||||
self.startup_mode = True
|
||||
|
||||
logger.info("HistoricalDataLoader initialized with existing DataProvider (startup mode: ON)")
|
||||
|
||||
def get_data(self, symbol: str, timeframe: str,
|
||||
start_time: Optional[datetime] = None,
|
||||
@@ -130,12 +133,22 @@ class HistoricalDataLoader:
|
||||
return df
|
||||
|
||||
# Fallback: fetch from DataProvider's historical data method
|
||||
logger.info(f"Fetching fresh data for {symbol} {timeframe}")
|
||||
df = self.data_provider.get_historical_data(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
limit=limit
|
||||
)
|
||||
# During startup, allow stale cache to avoid slow API calls
|
||||
if self.startup_mode:
|
||||
logger.info(f"Loading data for {symbol} {timeframe} (startup mode: allow stale cache)")
|
||||
df = self.data_provider.get_historical_data(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
limit=limit,
|
||||
allow_stale_cache=True
|
||||
)
|
||||
else:
|
||||
logger.info(f"Fetching fresh data for {symbol} {timeframe}")
|
||||
df = self.data_provider.get_historical_data(
|
||||
symbol=symbol,
|
||||
timeframe=timeframe,
|
||||
limit=limit
|
||||
)
|
||||
|
||||
if df is not None and not df.empty:
|
||||
# Filter by time range if specified
|
||||
@@ -219,6 +232,11 @@ class HistoricalDataLoader:
|
||||
self.memory_cache.clear()
|
||||
logger.info("Memory cache cleared")
|
||||
|
||||
def disable_startup_mode(self):
|
||||
"""Disable startup mode to fetch fresh data"""
|
||||
self.startup_mode = False
|
||||
logger.info("Startup mode disabled - will fetch fresh data on next request")
|
||||
|
||||
def get_data_boundaries(self, symbol: str, timeframe: str) -> Tuple[Optional[datetime], Optional[datetime]]:
|
||||
"""
|
||||
Get the earliest and latest available data timestamps
|
||||
|
||||
Reference in New Issue
Block a user