Persist ForexDataProvider across calls — speeds up repeat /scans 50×

Cold /scan is rate-limited (4 pairs × 3 TFs = 12 credits, free tier 8/min)
so the first call takes ~73s. Without provider reuse, every subsequent
/scan is also ~73s because the cache is rebuilt from scratch.

Reusing the provider on the bot instance preserves the OHLCV cache
between calls, so a /scan within the cache TTLs (M15: 5m, H1: 30m,
D1: 4h) skips the prefetch entirely:

  Cold /scan:  ~73s  (rate-limited prefetch + analyze + Gemini)
  Warm /scan:  ~10s  (cached data, news re-scored)
  Re-warm:     ~1.5s (cached data + cached sentiment)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Harwinder
2026-05-06 12:23:00 -04:00
parent 405ddffc9c
commit 3a17471c0e
+5 -1
View File
@@ -274,6 +274,10 @@ class ForexTelegramBot:
self._executor = ThreadPoolExecutor(
max_workers=len(SCAN_TIMEFRAMES), thread_name_prefix="forex"
)
# Persistent ForexDataProvider so the OHLCV cache survives across
# /scan and /signal calls. Without this each call burns API credits
# re-fetching the same bars and waits up to 60s on the rate limit.
self._provider = ForexDataProvider(PlatformConfig())
# ── Engine helpers ────────────────────────────────────────────────
@@ -297,7 +301,7 @@ class ForexTelegramBot:
for tf_name in SCAN_TIMEFRAMES
for tf in [_TF_MAP[tf_name]] + _TF_CONFIRMATIONS.get(tf_name, [])
})
provider = ForexDataProvider(PlatformConfig())
provider = self._provider # reuse across calls — see __init__
loop = asyncio.get_running_loop()
if progress: