Fix concurrent API credit exhaustion — shared prefetch + dedup warnings

- telegram_bot: one ForexDataProvider shared across all SCAN_TIMEFRAMES;
  combined prefetch of all unique TFs up front so the 4 concurrent scans
  hit the warm cache instead of firing simultaneous API calls
- data_provider: skip prefetch_batch for timeframes already in cache
- data_provider: deduplicate "no data" warning per symbol (fires once, not once per TF)
- data_provider: [live] info log on successful fetch; outlier-removal downgraded to debug

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Harwinder
2026-05-04 20:48:25 -04:00
parent 8ca59c6a21
commit df77e0fb5e
3 changed files with 30 additions and 10 deletions
+14 -4
View File
@@ -20,6 +20,7 @@ import requests
from config import PlatformConfig, Timeframe, SYMBOL_DISPLAY, PIP_VALUES
logger = logging.getLogger(__name__)
_no_data_warned: set = set() # suppress duplicate "no data" warnings per symbol
class DataIntegrityError(Exception):
@@ -151,7 +152,17 @@ class ForexDataProvider:
if lookback_days is None:
lookback_days = self.config.data_lookback_days
now = time.time()
for tf in timeframes:
cached = all(
f"{s}_{tf.value}" in self._cache_timestamps
and (now - self._cache_timestamps[f"{s}_{tf.value}"]) < self.config.refresh_interval
and not self._cache.get(f"{s}_{tf.value}", pd.DataFrame()).empty
for s in symbols
)
if cached:
logger.debug(f"Skipping prefetch for {tf.value} — all {len(symbols)} symbols cached")
continue
try:
self._batch_fetch_timeframe(symbols, tf, lookback_days)
time.sleep(1.0) # brief pause between TF requests
@@ -332,10 +343,9 @@ class ForexDataProvider:
values = sym_data.get("values")
if not values:
logger.warning(
f"No data returned by Twelve Data for {td_sym} "
f"— symbol may require a paid plan."
)
if td_sym not in _no_data_warned:
logger.warning(f"No data from Twelve Data for {td_sym} — symbol may require a paid plan.")
_no_data_warned.add(td_sym)
continue
records = [