fix(news): align type hints with config-default semantics and add Alpha Vantage limit

Addresses gemini-code-assist review on #565:
- Type hints: int | None for nullable look_back_days/limit on get_global_news
  in alpha_vantage_news.py, yfinance_news.py, and news_data_tools.py.
  Adds explicit str type hint to curr_date in alpha_vantage_news.py.
- Config override: news_data_tools.get_global_news no longer hardcodes
  look_back_days=7 / limit=5; defaults to None so DEFAULT_CONFIG values
  flow through to the dataflow layer.
- Cross-vendor consistency: alpha_vantage_news.get_news now respects the
  news_article_limit config (parity with yfinance_news.get_news_yfinance).
- Fallback consistency: alpha_vantage_news.get_global_news fallback now
  matches DEFAULT_CONFIG (10) instead of the legacy 50.
This commit is contained in:
octo-patch 2026-04-18 13:44:28 +08:00
parent 09a9062ec9
commit 50902c3dc0
3 changed files with 12 additions and 8 deletions

View File

@ -23,16 +23,18 @@ def get_news(
@tool
def get_global_news(
curr_date: Annotated[str, "Current date in yyyy-mm-dd format"],
look_back_days: Annotated[int, "Number of days to look back"] = 7,
limit: Annotated[int, "Maximum number of articles to return"] = 5,
look_back_days: Annotated[int | None, "Number of days to look back (defaults to global_news_lookback_days config)"] = None,
limit: Annotated[int | None, "Maximum number of articles to return (defaults to global_news_article_limit config)"] = None,
) -> str:
"""
Retrieve global news data.
Uses the configured news_data vendor.
Args:
curr_date (str): Current date in yyyy-mm-dd format
look_back_days (int): Number of days to look back (default 7)
limit (int): Maximum number of articles to return (default 5)
look_back_days (int | None): Number of days to look back. If None, uses
the global_news_lookback_days value from DEFAULT_CONFIG (7).
limit (int | None): Maximum number of articles to return. If None, uses
the global_news_article_limit value from DEFAULT_CONFIG (10).
Returns:
str: A formatted string containing global news data
"""

View File

@ -15,15 +15,17 @@ def get_news(ticker, start_date, end_date) -> dict[str, str] | str:
Dictionary containing news sentiment data or JSON string.
"""
limit = get_config().get("news_article_limit", 20)
params = {
"tickers": ticker,
"time_from": format_datetime_for_api(start_date),
"time_to": format_datetime_for_api(end_date),
"limit": str(limit),
}
return _make_api_request("NEWS_SENTIMENT", params)
def get_global_news(curr_date, look_back_days: int = None, limit: int = None) -> dict[str, str] | str:
def get_global_news(curr_date: str, 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.
@ -42,7 +44,7 @@ def get_global_news(curr_date, look_back_days: int = None, limit: int = None) ->
if look_back_days is None:
look_back_days = config.get("global_news_lookback_days", 7)
if limit is None:
limit = config.get("global_news_article_limit", 50)
limit = config.get("global_news_article_limit", 10)
# Calculate start date
curr_dt = datetime.strptime(curr_date, "%Y-%m-%d")

View File

@ -108,8 +108,8 @@ def get_news_yfinance(
def get_global_news_yfinance(
curr_date: str,
look_back_days: int = None,
limit: int = None,
look_back_days: int | None = None,
limit: int | None = None,
) -> str:
"""
Retrieve global/macro economic news using yfinance Search.