From 3a17471c0e4b1e76f31f59ba5efb7e56e0039357 Mon Sep 17 00:00:00 2001 From: Harwinder Date: Wed, 6 May 2026 12:23:00 -0400 Subject: [PATCH] =?UTF-8?q?Persist=20ForexDataProvider=20across=20calls=20?= =?UTF-8?q?=E2=80=94=20speeds=20up=20repeat=20/scans=2050=C3=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- telegram_bot.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/telegram_bot.py b/telegram_bot.py index 8fd324e..a639d97 100644 --- a/telegram_bot.py +++ b/telegram_bot.py @@ -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: