From 1a8ec533c02801c94370daf5a40c5edfdb2ea285 Mon Sep 17 00:00:00 2001 From: voidborne-d Date: Mon, 23 Mar 2026 19:07:21 +0000 Subject: [PATCH] fix: add yf_retry to yfinance_news.py to handle rate limits The yfinance_news module was missing the yf_retry exponential backoff wrapper that y_finance.py and stockstats_utils.py already use. When Yahoo Finance returns HTTP 429 (Too Many Requests), get_news_yfinance and get_global_news_yfinance would fail immediately instead of retrying. This adds yf_retry around: - stock.get_news() in get_news_yfinance() - yf.Search() in get_global_news_yfinance() Fixes #437 --- tradingagents/dataflows/yfinance_news.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tradingagents/dataflows/yfinance_news.py b/tradingagents/dataflows/yfinance_news.py index 20e9120d..a86675b1 100644 --- a/tradingagents/dataflows/yfinance_news.py +++ b/tradingagents/dataflows/yfinance_news.py @@ -4,6 +4,8 @@ import yfinance as yf from datetime import datetime from dateutil.relativedelta import relativedelta +from .stockstats_utils import yf_retry + def _extract_article_data(article: dict) -> dict: """Extract article data from yfinance news format (handles nested 'content' structure).""" @@ -64,7 +66,7 @@ def get_news_yfinance( """ try: stock = yf.Ticker(ticker) - news = stock.get_news(count=20) + news = yf_retry(lambda: stock.get_news(count=20)) if not news: return f"No news found for {ticker}" @@ -131,11 +133,11 @@ def get_global_news_yfinance( try: for query in search_queries: - search = yf.Search( - query=query, + search = yf_retry(lambda q=query: yf.Search( + query=q, news_count=limit, enable_fuzzy_query=True, - ) + )) if search.news: for article in search.news: