mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-19 11:15:24 +03:00
fix(dataflows): use configured defaults for omitted Alpha Vantage global-news options (#1326)
This commit is contained in:
@@ -151,3 +151,18 @@ def test_request_error_message_carries_no_key(monkeypatch):
|
|||||||
with pytest.raises(requests.Timeout) as caught:
|
with pytest.raises(requests.Timeout) as caught:
|
||||||
av._make_api_request("OVERVIEW", {"symbol": "IBM"})
|
av._make_api_request("OVERVIEW", {"symbol": "IBM"})
|
||||||
assert key not in str(caught.value)
|
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"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from .alpha_vantage_common import _make_api_request, format_datetime_for_api
|
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:
|
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)
|
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.
|
"""Returns global market news & sentiment data without ticker-specific filtering.
|
||||||
|
|
||||||
Covers broad market topics like financial markets, economy, and more.
|
Covers broad market topics like financial markets, economy, and more.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
curr_date: Current date in yyyy-mm-dd format.
|
curr_date: Current date in yyyy-mm-dd format.
|
||||||
look_back_days: Number of days to look back (default 7).
|
look_back_days: Number of days to look back; ``None`` uses
|
||||||
limit: Maximum number of articles (default 50).
|
``global_news_lookback_days`` from the active config.
|
||||||
|
limit: Maximum number of articles; ``None`` uses
|
||||||
|
``global_news_article_limit`` from the active config.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dictionary containing global news sentiment data or JSON string.
|
Dictionary containing global news sentiment data or JSON string.
|
||||||
"""
|
"""
|
||||||
from datetime import datetime, timedelta
|
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")
|
curr_dt = datetime.strptime(curr_date, "%Y-%m-%d")
|
||||||
start_dt = curr_dt - timedelta(days=look_back_days)
|
start_dt = curr_dt - timedelta(days=look_back_days)
|
||||||
start_date = start_dt.strftime("%Y-%m-%d")
|
start_date = start_dt.strftime("%Y-%m-%d")
|
||||||
|
|||||||
Reference in New Issue
Block a user