Python
fix: improve data vendor implementations and tool signatures
Yijia Xiaob06936f42030
diff --git a/tradingagents/agents/analysts/fundamentals_analyst.py b/tradingagents/agents/analysts/fundamentals_analyst.pyindex e20139cbb..22d91848a 100644--- a/tradingagents/agents/analysts/fundamentals_analyst.py+++ b/tradingagents/agents/analysts/fundamentals_analyst.py@@ -1,7 +1,7 @@from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholderimport timeimport json-from tradingagents.agents.utils.agent_utils import get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement, get_insider_sentiment, get_insider_transactions+from tradingagents.agents.utils.agent_utils import get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement, get_insider_transactionsfrom tradingagents.dataflows.config import get_configdiff --git a/tradingagents/agents/utils/agent_utils.py b/tradingagents/agents/utils/agent_utils.pyindex 691346a4e..b329a3e97 100644--- a/tradingagents/agents/utils/agent_utils.py+++ b/tradingagents/agents/utils/agent_utils.py@@ -15,7 +15,6 @@ from tradingagents.agents.utils.fundamental_data_tools import ()from tradingagents.agents.utils.news_data_tools import (get_news,- get_insider_sentiment,get_insider_transactions,get_global_news)diff --git a/tradingagents/agents/utils/news_data_tools.py b/tradingagents/agents/utils/news_data_tools.pyindex 0df9d0474..781e793c3 100644--- a/tradingagents/agents/utils/news_data_tools.py+++ b/tradingagents/agents/utils/news_data_tools.py@@ -38,34 +38,16 @@ def get_global_news("""return route_to_vendor("get_global_news", curr_date, look_back_days, limit)-@tool-def get_insider_sentiment(- ticker: Annotated[str, "ticker symbol for the company"],- curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"],-) -> str:- """- Retrieve insider sentiment information about a company.- Uses the configured news_data vendor.- Args:- ticker (str): Ticker symbol of the company- curr_date (str): Current date you are trading at, yyyy-mm-dd- Returns:- str: A report of insider sentiment data- """- return route_to_vendor("get_insider_sentiment", ticker, curr_date)-@tooldef get_insider_transactions(ticker: Annotated[str, "ticker symbol"],- curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"],) -> str:"""Retrieve insider transaction information about a company.Uses the configured news_data vendor.Args:ticker (str): Ticker symbol of the company- curr_date (str): Current date you are trading at, yyyy-mm-ddReturns:str: A report of insider transaction data"""- return route_to_vendor("get_insider_transactions", ticker, curr_date)+ return route_to_vendor("get_insider_transactions", ticker)diff --git a/tradingagents/dataflows/alpha_vantage.py b/tradingagents/dataflows/alpha_vantage.pyindex c5177c297..b2be1d611 100644--- a/tradingagents/dataflows/alpha_vantage.py+++ b/tradingagents/dataflows/alpha_vantage.py@@ -2,4 +2,4 @@from .alpha_vantage_stock import get_stockfrom .alpha_vantage_indicator import get_indicatorfrom .alpha_vantage_fundamentals import get_fundamentals, get_balance_sheet, get_cashflow, get_income_statement-from .alpha_vantage_news import get_news, get_insider_transactions\ No newline at end of file+from .alpha_vantage_news import get_news, get_global_news, get_insider_transactions\ No newline at end of filediff --git a/tradingagents/dataflows/alpha_vantage_news.py b/tradingagents/dataflows/alpha_vantage_news.pyindex 8124fb45d..4cf7bb0ec 100644--- a/tradingagents/dataflows/alpha_vantage_news.py+++ b/tradingagents/dataflows/alpha_vantage_news.py@@ -18,12 +18,40 @@ def get_news(ticker, start_date, end_date) -> dict[str, str] | str:"tickers": ticker,"time_from": format_datetime_for_api(start_date),"time_to": format_datetime_for_api(end_date),- "sort": "LATEST",- "limit": "50",}-++ 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:+ """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).++ Returns:+ Dictionary containing global news sentiment data or JSON string.+ """+ from datetime import datetime, timedelta++ # Calculate start date+ 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")++ params = {+ "topics": "financial_markets,economy_macro,economy_monetary",+ "time_from": format_datetime_for_api(start_date),+ "time_to": format_datetime_for_api(curr_date),+ "limit": str(limit),+ }+return _make_api_request("NEWS_SENTIMENT", params)+def get_insider_transactions(symbol: str) -> dict[str, str] | str:"""Returns latest and historical insider transactions by key stakeholders.diff --git a/tradingagents/dataflows/interface.py b/tradingagents/dataflows/interface.pyindex 423d2e43b..e2862c62a 100644--- a/tradingagents/dataflows/interface.py+++ b/tradingagents/dataflows/interface.py@@ -20,6 +20,7 @@ from .alpha_vantage import (get_income_statement as get_alpha_vantage_income_statement,get_insider_transactions as get_alpha_vantage_insider_transactions,get_news as get_alpha_vantage_news,+ get_global_news as get_alpha_vantage_global_news,)from .alpha_vantage_common import AlphaVantageRateLimitError@@ -100,6 +101,7 @@ VENDOR_METHODS = {},"get_global_news": {"yfinance": get_global_news_yfinance,+ "alpha_vantage": get_alpha_vantage_global_news,},"get_insider_transactions": {"alpha_vantage": get_alpha_vantage_insider_transactions,diff --git a/tradingagents/dataflows/yfinance_news.py b/tradingagents/dataflows/yfinance_news.pyindex 415bc6459..20e9120de 100644--- a/tradingagents/dataflows/yfinance_news.py+++ b/tradingagents/dataflows/yfinance_news.py@@ -64,7 +64,7 @@ def get_news_yfinance("""try:stock = yf.Ticker(ticker)- news = stock.get_news(count=20, tab="news")+ news = stock.get_news(count=20)if not news:return f"No news found for {ticker}"diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.pyindex 9a3d472c3..d8dff2046 100644--- a/tradingagents/graph/trading_graph.py+++ b/tradingagents/graph/trading_graph.py@@ -29,7 +29,6 @@ from tradingagents.agents.utils.agent_utils import (get_cashflow,get_income_statement,get_news,- get_insider_sentiment,get_insider_transactions,get_global_news)@@ -162,7 +161,6 @@ class TradingAgentsGraph:# News and insider informationget_news,get_global_news,- get_insider_sentiment,get_insider_transactions,]),