fix(filter): load OHLCV from full universe cache key to get cache hit

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 <noreply@anthropic.com>
This commit is contained in:
Youssef Aitousarrah 2026-04-15 20:02:39 -07:00
parent 1da77817ea
commit 54583ee667
1 changed files with 8 additions and 2 deletions

View File

@ -174,11 +174,17 @@ class CandidateFilter:
volume_by_ticker = self._fetch_batch_volume(state, candidates) volume_by_ticker = self._fetch_batch_volume(state, candidates)
news_by_ticker = self._fetch_batch_news(start_date, end_date, 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") 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")] 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...") 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") logger.info(f"OHLCV cache loaded for {len(ohlcv_data)}/{len(candidate_tickers)} tickers")
( (