ghost T predictions plotting on chart live chart updates

This commit is contained in:
Dobromir Popov
2025-11-22 01:14:32 +02:00
parent f967f0a142
commit d349a1bac0
4 changed files with 272 additions and 30 deletions

View File

@@ -65,14 +65,26 @@ class HistoricalDataLoader:
# Check memory cache first (exclude direction from cache key for infinite scroll)
cache_key = f"{symbol}_{timeframe}_{start_time}_{end_time}_{limit}"
# Determine TTL based on timeframe
current_ttl = self.cache_ttl
if timeframe == '1s':
current_ttl = timedelta(seconds=1)
elif timeframe == '1m':
current_ttl = timedelta(seconds=5)
if cache_key in self.memory_cache and direction == 'latest':
cached_data, cached_time = self.memory_cache[cache_key]
if datetime.now() - cached_time < self.cache_ttl:
elapsed_ms = (time.time() - start_time_ms) * 1000
logger.debug(f"⚡ Memory cache hit for {symbol} {timeframe} ({elapsed_ms:.1f}ms)")
if datetime.now() - cached_time < current_ttl:
# For 1s/1m, we want to return immediately if valid
if timeframe not in ['1s', '1m']:
elapsed_ms = (time.time() - start_time_ms) * 1000
logger.debug(f"⚡ Memory cache hit for {symbol} {timeframe} ({elapsed_ms:.1f}ms)")
return cached_data
try:
# FORCE refresh for 1s/1m if requesting latest data
force_refresh = (timeframe in ['1s', '1m'] and not start_time and not end_time)
# Try to get data from DataProvider's cached data first (most efficient)
if hasattr(self.data_provider, 'cached_data'):
with self.data_provider.data_lock:
@@ -215,7 +227,7 @@ class HistoricalDataLoader:
return None
# Fallback: Use DataProvider for latest data (startup mode or no time range)
if self.startup_mode and not (start_time or end_time):
if self.startup_mode and not (start_time or end_time) and not force_refresh:
logger.info(f"Loading data for {symbol} {timeframe} (startup mode: allow stale cache)")
df = self.data_provider.get_historical_data(
symbol=symbol,
@@ -225,7 +237,12 @@ class HistoricalDataLoader:
)
else:
# Fetch from API and store in DuckDB (no time range specified)
logger.info(f"Fetching latest data from API for {symbol} {timeframe}")
# For 1s/1m, logging every request is too verbose, use debug
if timeframe in ['1s', '1m']:
logger.debug(f"Fetching latest data from API for {symbol} {timeframe}")
else:
logger.info(f"Fetching latest data from API for {symbol} {timeframe}")
df = self.data_provider.get_historical_data(
symbol=symbol,
timeframe=timeframe,