From 54583ee6670287a4be554a4eafd46a191df53379 Mon Sep 17 00:00:00 2001 From: Youssef Aitousarrah Date: Wed, 15 Apr 2026 20:02:39 -0700 Subject: [PATCH] fix(filter): load OHLCV from full universe cache key to get cache hit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Requesting only candidate tickers produced a different cache key from the nightly prefetch, triggering a fresh yfinance download that hit rate limits (4/75 tickers returned). Now loads the full universe (same key as nightly prefetch) and slices to candidate tickers — always a cache hit. Co-Authored-By: Claude Sonnet 4.6 --- tradingagents/dataflows/discovery/filter.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tradingagents/dataflows/discovery/filter.py b/tradingagents/dataflows/discovery/filter.py index c8bbc3d2..a0a7db15 100644 --- a/tradingagents/dataflows/discovery/filter.py +++ b/tradingagents/dataflows/discovery/filter.py @@ -174,11 +174,17 @@ class CandidateFilter: volume_by_ticker = self._fetch_batch_volume(state, candidates) news_by_ticker = self._fetch_batch_news(start_date, end_date, candidates) - # Load OHLCV cache for candidate tickers — replaces per-ticker yfinance calls + # Load OHLCV cache — use the full universe key (same as nightly prefetch) so we + # get a cache hit, then slice to candidate tickers. Requesting only candidate + # tickers produces a different cache key and triggers a fresh download. cache_dir = self.config.get("discovery", {}).get("ohlcv_cache_dir", "data/ohlcv_cache") candidate_tickers = [c["ticker"].upper() for c in candidates if c.get("ticker")] logger.info(f"Loading OHLCV cache for {len(candidate_tickers)} candidate tickers...") - ohlcv_data = download_ohlcv_cached(candidate_tickers, period="1y", cache_dir=cache_dir) + from tradingagents.dataflows.universe import load_universe + + universe_tickers = load_universe(self.config) + full_ohlcv = download_ohlcv_cached(universe_tickers, period="1y", cache_dir=cache_dir) + ohlcv_data = {t: full_ohlcv[t] for t in candidate_tickers if t in full_ohlcv} logger.info(f"OHLCV cache loaded for {len(ohlcv_data)}/{len(candidate_tickers)} tickers") (