fix(dataflows): use configured defaults for omitted Alpha Vantage global-news options (#1326)

This commit is contained in:
Yijia-Xiao
2026-09-15 01:33:48 +00:00
parent ef52d4452b
commit dffff22951
2 changed files with 27 additions and 4 deletions

View File

@@ -151,3 +151,18 @@ def test_request_error_message_carries_no_key(monkeypatch):
with pytest.raises(requests.Timeout) as caught:
av._make_api_request("OVERVIEW", {"symbol": "IBM"})
assert key not in str(caught.value)
@pytest.mark.unit
def test_global_news_omitted_optionals_use_the_configured_defaults(monkeypatch):
"""The tool passes None for an omitted look_back_days or limit (#1326)."""
from tradingagents.dataflows import alpha_vantage_news
monkeypatch.setattr(alpha_vantage_news, "get_config",
lambda: {"global_news_lookback_days": 3, "global_news_article_limit": 9})
seen = {}
monkeypatch.setattr(alpha_vantage_news, "_make_api_request", lambda fn, params: seen.update(params) or "{}")
alpha_vantage_news.get_global_news("2026-08-14", None, None)
assert seen["time_from"].startswith("20260811") and seen["limit"] == "9"

View File

@@ -1,6 +1,7 @@
import json
from .alpha_vantage_common import _make_api_request, format_datetime_for_api
from .config import get_config
def get_news(ticker, start_date, end_date) -> dict[str, str] | str:
@@ -25,22 +26,29 @@ def get_news(ticker, start_date, end_date) -> dict[str, str] | str:
return _make_api_request("NEWS_SENTIMENT", params)
def get_global_news(curr_date, look_back_days: int = 7, limit: int = 50) -> dict[str, str] | str:
def get_global_news(curr_date, look_back_days: int | None = None, limit: int | None = None) -> dict[str, str] | str:
"""Returns global market news & sentiment data without ticker-specific filtering.
Covers broad market topics like financial markets, economy, and more.
Args:
curr_date: Current date in yyyy-mm-dd format.
look_back_days: Number of days to look back (default 7).
limit: Maximum number of articles (default 50).
look_back_days: Number of days to look back; ``None`` uses
``global_news_lookback_days`` from the active config.
limit: Maximum number of articles; ``None`` uses
``global_news_article_limit`` from the active config.
Returns:
Dictionary containing global news sentiment data or JSON string.
"""
from datetime import datetime, timedelta
# Calculate start date
config = get_config()
if look_back_days is None:
look_back_days = config["global_news_lookback_days"]
if limit is None:
limit = config["global_news_article_limit"]
curr_dt = datetime.strptime(curr_date, "%Y-%m-%d")
start_dt = curr_dt - timedelta(days=look_back_days)
start_date = start_dt.strftime("%Y-%m-%d")