diff --git a/README.md b/README.md index cac18691..1908a376 100644 --- a/README.md +++ b/README.md @@ -178,7 +178,6 @@ config = DEFAULT_CONFIG.copy() config["deep_think_llm"] = "gpt-4.1-nano" # Use a different model config["quick_think_llm"] = "gpt-4.1-nano" # Use a different model config["max_debate_rounds"] = 1 # Increase debate rounds -config["online_tools"] = True # Use online tools or cached data # Initialize with custom config ta = TradingAgentsGraph(debug=True, config=config) @@ -188,8 +187,6 @@ _, decision = ta.propagate("NVDA", "2024-05-10") print(decision) ``` -> For `online_tools`, we recommend enabling them for experimentation, as they provide access to real-time data. The agents' offline tools rely on cached data from our **Tauric TradingDB**, a curated dataset we use for backtesting. We're currently in the process of refining this dataset, and we plan to release it soon alongside our upcoming projects. Stay tuned! - You can view the full list of configurations in `tradingagents/default_config.py`. ## Contributing diff --git a/main.py b/main.py index 6c8ae3d9..1ce62cc6 100644 --- a/main.py +++ b/main.py @@ -8,7 +8,6 @@ config["backend_url"] = "https://generativelanguage.googleapis.com/v1" # Use a config["deep_think_llm"] = "gemini-2.0-flash" # Use a different model config["quick_think_llm"] = "gemini-2.0-flash" # Use a different model config["max_debate_rounds"] = 1 # Increase debate rounds -config["online_tools"] = True # Increase debate rounds # Initialize with custom config ta = TradingAgentsGraph(debug=True, config=config) diff --git a/tradingagents/agents/analysts/fundamentals_analyst.py b/tradingagents/agents/analysts/fundamentals_analyst.py index e3ed51c2..cb74a17f 100644 --- a/tradingagents/agents/analysts/fundamentals_analyst.py +++ b/tradingagents/agents/analysts/fundamentals_analyst.py @@ -9,16 +9,9 @@ def create_fundamentals_analyst(llm, toolkit): ticker = state["company_of_interest"] company_name = state["company_of_interest"] - if toolkit.config["online_tools"]: - tools = [toolkit.get_fundamentals_openai] - else: - tools = [ - toolkit.get_finnhub_company_insider_sentiment, - toolkit.get_finnhub_company_insider_transactions, - toolkit.get_simfin_balance_sheet, - toolkit.get_simfin_cashflow, - toolkit.get_simfin_income_stmt, - ] + tools = [ + toolkit.get_fundamentals_openai + ] system_message = ( get_prompts("analysts", "fundamentals_analyst", "system_message") diff --git a/tradingagents/agents/analysts/market_analyst.py b/tradingagents/agents/analysts/market_analyst.py index b34a7504..e254332a 100644 --- a/tradingagents/agents/analysts/market_analyst.py +++ b/tradingagents/agents/analysts/market_analyst.py @@ -10,16 +10,9 @@ def create_market_analyst(llm, toolkit): ticker = state["company_of_interest"] company_name = state["company_of_interest"] - if toolkit.config["online_tools"]: - tools = [ - toolkit.get_binance_data, - toolkit.get_stockstats_indicators_report_online, - ] - else: - tools = [ - toolkit.get_YFin_data, - toolkit.get_stockstats_indicators_report, - ] + tools = [ + toolkit.get_binance_data + ] system_message = ( get_prompts("analysts", "market_analyst", "system_message") diff --git a/tradingagents/agents/analysts/news_analyst.py b/tradingagents/agents/analysts/news_analyst.py index 6193b8bf..2c0fa61f 100644 --- a/tradingagents/agents/analysts/news_analyst.py +++ b/tradingagents/agents/analysts/news_analyst.py @@ -8,19 +8,13 @@ def create_news_analyst(llm, toolkit): current_date = state["trade_date"] ticker = state["company_of_interest"] - if toolkit.config["online_tools"]: - tools = [ - toolkit.get_global_news_openai, - toolkit.get_google_news, - toolkit.get_blockbeats_news, - toolkit.get_coindesk_news, - ] - else: - tools = [ - toolkit.get_finnhub_news, - toolkit.get_reddit_news, - toolkit.get_google_news, - ] + tools = [ + # toolkit.get_global_news_openai, + # toolkit.get_google_news, + # toolkit.get_reddit_news, + toolkit.get_blockbeats_news, + toolkit.get_coindesk_news, + ] system_message = ( get_prompts("analysts", "news_analyst", "system_message") diff --git a/tradingagents/agents/analysts/social_media_analyst.py b/tradingagents/agents/analysts/social_media_analyst.py index b0d72c7e..2fe6daec 100644 --- a/tradingagents/agents/analysts/social_media_analyst.py +++ b/tradingagents/agents/analysts/social_media_analyst.py @@ -9,12 +9,10 @@ def create_social_media_analyst(llm, toolkit): ticker = state["company_of_interest"] company_name = state["company_of_interest"] - if toolkit.config["online_tools"]: - tools = [toolkit.get_stock_news_openai] - else: - tools = [ - toolkit.get_reddit_stock_info, - ] + tools = [ + toolkit.get_stock_news_openai, + toolkit.get_reddit_stock_info + ] system_message = ( get_prompts("analysts", "social_media_analyst", "system_message") diff --git a/tradingagents/agents/utils/agent_utils.py b/tradingagents/agents/utils/agent_utils.py index 397bbd1f..d04669af 100644 --- a/tradingagents/agents/utils/agent_utils.py +++ b/tradingagents/agents/utils/agent_utils.py @@ -51,12 +51,12 @@ class Toolkit: @staticmethod @tool def get_blockbeats_news( - count: Annotated[int, "Number of news articles to retrieve, no more than 50"] = 10, + count: Annotated[int, "Number of news articles to retrieve, no more than 30"] = 10, ) -> str: """ Retrieve the latest news from BlockBeats, especially useful for Cryptos. Args: - count (int): Number of news articles to retrieve, no more than 50 + count (int): Number of news articles to retrieve, no more than 30 Returns: str: A formatted string containing the latest news from BlockBeats. """ @@ -120,38 +120,6 @@ class Toolkit: return global_news_result - @staticmethod - @tool - def get_finnhub_news( - ticker: Annotated[ - str, - "Search query of a company, e.g. 'AAPL, TSM, etc.", - ], - start_date: Annotated[str, "Start date in yyyy-mm-dd format"], - end_date: Annotated[str, "End date in yyyy-mm-dd format"], - ): - """ - Retrieve the latest news about a given stock from Finnhub within a date range - Args: - ticker (str): Ticker of a company. e.g. AAPL, TSM - start_date (str): Start date in yyyy-mm-dd format - end_date (str): End date in yyyy-mm-dd format - Returns: - str: A formatted dataframe containing news about the company within the date range from start_date to end_date - """ - - end_date_str = end_date - - end_date = datetime.strptime(end_date, "%Y-%m-%d") - start_date = datetime.strptime(start_date, "%Y-%m-%d") - look_back_days = (end_date - start_date).days - - finnhub_news_result = interface.get_finnhub_news( - ticker, end_date_str, look_back_days - ) - - return finnhub_news_result - @staticmethod @tool def get_reddit_stock_info( @@ -174,228 +142,6 @@ class Toolkit: return stock_news_results - @staticmethod - @tool - def get_YFin_data( - symbol: Annotated[str, "ticker symbol of the company"], - start_date: Annotated[str, "Start date in yyyy-mm-dd format"], - end_date: Annotated[str, "Start date in yyyy-mm-dd format"], - ) -> str: - """ - Retrieve the stock price data for a given ticker symbol from Yahoo Finance. - Args: - symbol (str): Ticker symbol of the company, e.g. AAPL, TSM - start_date (str): Start date in yyyy-mm-dd format - end_date (str): End date in yyyy-mm-dd format - Returns: - str: A formatted dataframe containing the stock price data for the specified ticker symbol in the specified date range. - """ - - result_data = interface.get_YFin_data(symbol, start_date, end_date) - - return result_data - - @staticmethod - @tool - def get_YFin_data_online( - symbol: Annotated[str, "ticker symbol of the company"], - start_date: Annotated[str, "Start date in yyyy-mm-dd format"], - end_date: Annotated[str, "Start date in yyyy-mm-dd format"], - ) -> str: - """ - Retrieve the stock price data for a given ticker symbol from Yahoo Finance. - Args: - symbol (str): Ticker symbol of the company, e.g. AAPL, TSM - start_date (str): Start date in yyyy-mm-dd format - end_date (str): End date in yyyy-mm-dd format - Returns: - str: A formatted dataframe containing the stock price data for the specified ticker symbol in the specified date range. - """ - - result_data = interface.get_YFin_data_online(symbol, start_date, end_date) - - return result_data - - @staticmethod - @tool - def get_stockstats_indicators_report( - symbol: Annotated[str, "ticker symbol of the company"], - indicator: Annotated[ - str, "technical indicator to get the analysis and report of" - ], - curr_date: Annotated[ - str, "The current trading date you are trading on, YYYY-mm-dd" - ], - look_back_days: Annotated[int, "how many days to look back"] = 30, - ) -> str: - """ - Retrieve stock stats indicators for a given ticker symbol and indicator. - Args: - symbol (str): Ticker symbol of the company, e.g. AAPL, TSM - indicator (str): Technical indicator to get the analysis and report of - curr_date (str): The current trading date you are trading on, YYYY-mm-dd - look_back_days (int): How many days to look back, default is 30 - Returns: - str: A formatted dataframe containing the stock stats indicators for the specified ticker symbol and indicator. - """ - - result_stockstats = interface.get_stock_stats_indicators_window( - symbol, indicator, curr_date, look_back_days, False - ) - - return result_stockstats - - @staticmethod - @tool - def get_stockstats_indicators_report_online( - symbol: Annotated[str, "ticker symbol of the company"], - indicator: Annotated[ - str, "technical indicator to get the analysis and report of" - ], - curr_date: Annotated[ - str, "The current trading date you are trading on, YYYY-mm-dd" - ], - look_back_days: Annotated[int, "how many days to look back"] = 30, - ) -> str: - """ - Retrieve stock stats indicators for a given ticker symbol and indicator. - Args: - symbol (str): Ticker symbol of the company, e.g. AAPL, TSM - indicator (str): Technical indicator to get the analysis and report of - curr_date (str): The current trading date you are trading on, YYYY-mm-dd - look_back_days (int): How many days to look back, default is 30 - Returns: - str: A formatted dataframe containing the stock stats indicators for the specified ticker symbol and indicator. - """ - - result_stockstats = interface.get_stock_stats_indicators_window( - symbol, indicator, curr_date, look_back_days, True - ) - - return result_stockstats - - @staticmethod - @tool - def get_finnhub_company_insider_sentiment( - ticker: Annotated[str, "ticker symbol for the company"], - curr_date: Annotated[ - str, - "current date of you are trading at, yyyy-mm-dd", - ], - ): - """ - Retrieve insider sentiment information about a company (retrieved from public SEC information) for the past 30 days - 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 the sentiment in the past 30 days starting at curr_date - """ - - data_sentiment = interface.get_finnhub_company_insider_sentiment( - ticker, curr_date, 30 - ) - - return data_sentiment - - @staticmethod - @tool - def get_finnhub_company_insider_transactions( - ticker: Annotated[str, "ticker symbol"], - curr_date: Annotated[ - str, - "current date you are trading at, yyyy-mm-dd", - ], - ): - """ - Retrieve insider transaction information about a company (retrieved from public SEC information) for the past 30 days - 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 the company's insider transactions/trading information in the past 30 days - """ - - data_trans = interface.get_finnhub_company_insider_transactions( - ticker, curr_date, 30 - ) - - return data_trans - - @staticmethod - @tool - def get_simfin_balance_sheet( - ticker: Annotated[str, "ticker symbol"], - freq: Annotated[ - str, - "reporting frequency of the company's financial history: annual/quarterly", - ], - curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], - ): - """ - Retrieve the most recent balance sheet of a company - Args: - ticker (str): ticker symbol of the company - freq (str): reporting frequency of the company's financial history: annual / quarterly - curr_date (str): current date you are trading at, yyyy-mm-dd - Returns: - str: a report of the company's most recent balance sheet - """ - - data_balance_sheet = interface.get_simfin_balance_sheet(ticker, freq, curr_date) - - return data_balance_sheet - - @staticmethod - @tool - def get_simfin_cashflow( - ticker: Annotated[str, "ticker symbol"], - freq: Annotated[ - str, - "reporting frequency of the company's financial history: annual/quarterly", - ], - curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], - ): - """ - Retrieve the most recent cash flow statement of a company - Args: - ticker (str): ticker symbol of the company - freq (str): reporting frequency of the company's financial history: annual / quarterly - curr_date (str): current date you are trading at, yyyy-mm-dd - Returns: - str: a report of the company's most recent cash flow statement - """ - - data_cashflow = interface.get_simfin_cashflow(ticker, freq, curr_date) - - return data_cashflow - - @staticmethod - @tool - def get_simfin_income_stmt( - ticker: Annotated[str, "ticker symbol"], - freq: Annotated[ - str, - "reporting frequency of the company's financial history: annual/quarterly", - ], - curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], - ): - """ - Retrieve the most recent income statement of a company - Args: - ticker (str): ticker symbol of the company - freq (str): reporting frequency of the company's financial history: annual / quarterly - curr_date (str): current date you are trading at, yyyy-mm-dd - Returns: - str: a report of the company's most recent income statement - """ - - data_income_stmt = interface.get_simfin_income_statements( - ticker, freq, curr_date - ) - - return data_income_stmt - @staticmethod @tool def get_google_news( diff --git a/tradingagents/dataflows/__init__.py b/tradingagents/dataflows/__init__.py index e10e0873..0bb70233 100644 --- a/tradingagents/dataflows/__init__.py +++ b/tradingagents/dataflows/__init__.py @@ -3,29 +3,19 @@ from .coindesk_utils import fetch_news_from_coindesk from .googlenews_utils import getNewsData from .binance_utils import * from .reddit_utils import fetch_top_from_category -from .stockstats_utils import StockstatsUtils -from .yfin_utils import YFinanceUtils from .interface import ( # News and sentiment functions get_blockbeats_news, get_coindesk_news, - get_finnhub_news, - get_finnhub_company_insider_sentiment, - get_finnhub_company_insider_transactions, get_google_news, get_reddit_global_news, get_reddit_company_news, # Financial statements functions - get_simfin_balance_sheet, - get_simfin_cashflow, - get_simfin_income_statements, + # TODO # Technical analysis functions - get_stock_stats_indicators_window, - get_stockstats_indicator, + # TODO # Market data functions - get_YFin_data_window, - get_YFin_data, get_binance_data ) @@ -33,21 +23,13 @@ __all__ = [ # News and sentiment functions "get_blockbeats_news", "get_coindesk_news", - "get_finnhub_news", - "get_finnhub_company_insider_sentiment", - "get_finnhub_company_insider_transactions", "get_google_news", "get_reddit_global_news", "get_reddit_company_news", # Financial statements functions - "get_simfin_balance_sheet", - "get_simfin_cashflow", - "get_simfin_income_statements", + # TODO # Technical analysis functions - "get_stock_stats_indicators_window", - "get_stockstats_indicator", + # TODO # Market data functions - "get_YFin_data_window", - "get_YFin_data", "get_binance_data" ] diff --git a/tradingagents/dataflows/finnhub_utils.py b/tradingagents/dataflows/finnhub_utils.py index e7c7103c..9b1d9d3b 100644 --- a/tradingagents/dataflows/finnhub_utils.py +++ b/tradingagents/dataflows/finnhub_utils.py @@ -1,7 +1,8 @@ import json import os - +from warnings import deprecated +@deprecated("Utilities only for stocks are deprecated.") def get_data_in_range(ticker, start_date, end_date, data_type, data_dir, period=None): """ Gets finnhub data saved and processed on disk. diff --git a/tradingagents/dataflows/interface.py b/tradingagents/dataflows/interface.py index d0130a12..36ecc541 100644 --- a/tradingagents/dataflows/interface.py +++ b/tradingagents/dataflows/interface.py @@ -17,17 +17,18 @@ from tqdm import tqdm import yfinance as yf from openai import OpenAI from .config import get_config, set_config, DATA_DIR +from warnings import deprecated -def get_blockbeats_news(count: Annotated[int, "news' count, no more than 50"] = 10): +def get_blockbeats_news(count: Annotated[int, "news' count, no more than 30"] = 10): """ Retrieve the latest top Blockbeats news Args: - count (int): number of news to retrieve, no more than 50 + count (int): number of news to retrieve, no more than 30 Returns: str: A formatted string containing the latest news articles and meta information """ - if count > 50: - raise ValueError("Count should not be more than 50") + if count > 30: + raise ValueError("Count should not be more than 30") news = fetch_news_from_blockbeats(count) @@ -65,272 +66,6 @@ def get_coindesk_news( return f"## Coindesk News:\n\n{news_str}" -def get_finnhub_news( - ticker: Annotated[ - str, - "Search query of a company's, e.g. 'AAPL, TSM, etc.", - ], - curr_date: Annotated[str, "Current date in yyyy-mm-dd format"], - look_back_days: Annotated[int, "how many days to look back"], -): - """ - Retrieve news about a company within a time frame - - Args - ticker (str): ticker for the company you are interested in - start_date (str): Start date in yyyy-mm-dd format - end_date (str): End date in yyyy-mm-dd format - Returns - str: dataframe containing the news of the company in the time frame - - """ - - start_date = datetime.strptime(curr_date, "%Y-%m-%d") - before = start_date - relativedelta(days=look_back_days) - before = before.strftime("%Y-%m-%d") - - result = get_data_in_range(ticker, before, curr_date, "news_data", DATA_DIR) - - if len(result) == 0: - return "" - - combined_result = "" - for day, data in result.items(): - if len(data) == 0: - continue - for entry in data: - current_news = ( - "### " + entry["headline"] + f" ({day})" + "\n" + entry["summary"] - ) - combined_result += current_news + "\n\n" - - return f"## {ticker} News, from {before} to {curr_date}:\n" + str(combined_result) - - -def get_finnhub_company_insider_sentiment( - ticker: Annotated[str, "ticker symbol for the company"], - curr_date: Annotated[ - str, - "current date of you are trading at, yyyy-mm-dd", - ], - look_back_days: Annotated[int, "number of days to look back"], -): - """ - Retrieve insider sentiment about a company (retrieved from public SEC information) for the past 15 days - Args: - ticker (str): ticker symbol of the company - curr_date (str): current date you are trading on, yyyy-mm-dd - Returns: - str: a report of the sentiment in the past 15 days starting at curr_date - """ - - date_obj = datetime.strptime(curr_date, "%Y-%m-%d") - before = date_obj - relativedelta(days=look_back_days) - before = before.strftime("%Y-%m-%d") - - data = get_data_in_range(ticker, before, curr_date, "insider_senti", DATA_DIR) - - if len(data) == 0: - return "" - - result_str = "" - seen_dicts = [] - for date, senti_list in data.items(): - for entry in senti_list: - if entry not in seen_dicts: - result_str += f"### {entry['year']}-{entry['month']}:\nChange: {entry['change']}\nMonthly Share Purchase Ratio: {entry['mspr']}\n\n" - seen_dicts.append(entry) - - return ( - f"## {ticker} Insider Sentiment Data for {before} to {curr_date}:\n" - + result_str - + "The change field refers to the net buying/selling from all insiders' transactions. The mspr field refers to monthly share purchase ratio." - ) - - -def get_finnhub_company_insider_transactions( - ticker: Annotated[str, "ticker symbol"], - curr_date: Annotated[ - str, - "current date you are trading at, yyyy-mm-dd", - ], - look_back_days: Annotated[int, "how many days to look back"], -): - """ - Retrieve insider transcaction information about a company (retrieved from public SEC information) for the past 15 days - 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 the company's insider transaction/trading informtaion in the past 15 days - """ - - date_obj = datetime.strptime(curr_date, "%Y-%m-%d") - before = date_obj - relativedelta(days=look_back_days) - before = before.strftime("%Y-%m-%d") - - data = get_data_in_range(ticker, before, curr_date, "insider_trans", DATA_DIR) - - if len(data) == 0: - return "" - - result_str = "" - - seen_dicts = [] - for date, senti_list in data.items(): - for entry in senti_list: - if entry not in seen_dicts: - result_str += f"### Filing Date: {entry['filingDate']}, {entry['name']}:\nChange:{entry['change']}\nShares: {entry['share']}\nTransaction Price: {entry['transactionPrice']}\nTransaction Code: {entry['transactionCode']}\n\n" - seen_dicts.append(entry) - - return ( - f"## {ticker} insider transactions from {before} to {curr_date}:\n" - + result_str - + "The change field reflects the variation in share count—here a negative number indicates a reduction in holdings—while share specifies the total number of shares involved. The transactionPrice denotes the per-share price at which the trade was executed, and transactionDate marks when the transaction occurred. The name field identifies the insider making the trade, and transactionCode (e.g., S for sale) clarifies the nature of the transaction. FilingDate records when the transaction was officially reported, and the unique id links to the specific SEC filing, as indicated by the source. Additionally, the symbol ties the transaction to a particular company, isDerivative flags whether the trade involves derivative securities, and currency notes the currency context of the transaction." - ) - - -def get_simfin_balance_sheet( - ticker: Annotated[str, "ticker symbol"], - freq: Annotated[ - str, - "reporting frequency of the company's financial history: annual / quarterly", - ], - curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], -): - data_path = os.path.join( - DATA_DIR, - "fundamental_data", - "simfin_data_all", - "balance_sheet", - "companies", - "us", - f"us-balance-{freq}.csv", - ) - df = pd.read_csv(data_path, sep=";") - - # Convert date strings to datetime objects and remove any time components - df["Report Date"] = pd.to_datetime(df["Report Date"], utc=True).dt.normalize() - df["Publish Date"] = pd.to_datetime(df["Publish Date"], utc=True).dt.normalize() - - # Convert the current date to datetime and normalize - curr_date_dt = pd.to_datetime(curr_date, utc=True).normalize() - - # Filter the DataFrame for the given ticker and for reports that were published on or before the current date - filtered_df = df[(df["Ticker"] == ticker) & (df["Publish Date"] <= curr_date_dt)] - - # Check if there are any available reports; if not, return a notification - if filtered_df.empty: - print("No balance sheet available before the given current date.") - return "" - - # Get the most recent balance sheet by selecting the row with the latest Publish Date - latest_balance_sheet = filtered_df.loc[filtered_df["Publish Date"].idxmax()] - - # drop the SimFinID column - latest_balance_sheet = latest_balance_sheet.drop("SimFinId") - - return ( - f"## {freq} balance sheet for {ticker} released on {str(latest_balance_sheet['Publish Date'])[0:10]}: \n" - + str(latest_balance_sheet) - + "\n\nThis includes metadata like reporting dates and currency, share details, and a breakdown of assets, liabilities, and equity. Assets are grouped as current (liquid items like cash and receivables) and noncurrent (long-term investments and property). Liabilities are split between short-term obligations and long-term debts, while equity reflects shareholder funds such as paid-in capital and retained earnings. Together, these components ensure that total assets equal the sum of liabilities and equity." - ) - - -def get_simfin_cashflow( - ticker: Annotated[str, "ticker symbol"], - freq: Annotated[ - str, - "reporting frequency of the company's financial history: annual / quarterly", - ], - curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], -): - data_path = os.path.join( - DATA_DIR, - "fundamental_data", - "simfin_data_all", - "cash_flow", - "companies", - "us", - f"us-cashflow-{freq}.csv", - ) - df = pd.read_csv(data_path, sep=";") - - # Convert date strings to datetime objects and remove any time components - df["Report Date"] = pd.to_datetime(df["Report Date"], utc=True).dt.normalize() - df["Publish Date"] = pd.to_datetime(df["Publish Date"], utc=True).dt.normalize() - - # Convert the current date to datetime and normalize - curr_date_dt = pd.to_datetime(curr_date, utc=True).normalize() - - # Filter the DataFrame for the given ticker and for reports that were published on or before the current date - filtered_df = df[(df["Ticker"] == ticker) & (df["Publish Date"] <= curr_date_dt)] - - # Check if there are any available reports; if not, return a notification - if filtered_df.empty: - print("No cash flow statement available before the given current date.") - return "" - - # Get the most recent cash flow statement by selecting the row with the latest Publish Date - latest_cash_flow = filtered_df.loc[filtered_df["Publish Date"].idxmax()] - - # drop the SimFinID column - latest_cash_flow = latest_cash_flow.drop("SimFinId") - - return ( - f"## {freq} cash flow statement for {ticker} released on {str(latest_cash_flow['Publish Date'])[0:10]}: \n" - + str(latest_cash_flow) - + "\n\nThis includes metadata like reporting dates and currency, share details, and a breakdown of cash movements. Operating activities show cash generated from core business operations, including net income adjustments for non-cash items and working capital changes. Investing activities cover asset acquisitions/disposals and investments. Financing activities include debt transactions, equity issuances/repurchases, and dividend payments. The net change in cash represents the overall increase or decrease in the company's cash position during the reporting period." - ) - - -def get_simfin_income_statements( - ticker: Annotated[str, "ticker symbol"], - freq: Annotated[ - str, - "reporting frequency of the company's financial history: annual / quarterly", - ], - curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], -): - data_path = os.path.join( - DATA_DIR, - "fundamental_data", - "simfin_data_all", - "income_statements", - "companies", - "us", - f"us-income-{freq}.csv", - ) - df = pd.read_csv(data_path, sep=";") - - # Convert date strings to datetime objects and remove any time components - df["Report Date"] = pd.to_datetime(df["Report Date"], utc=True).dt.normalize() - df["Publish Date"] = pd.to_datetime(df["Publish Date"], utc=True).dt.normalize() - - # Convert the current date to datetime and normalize - curr_date_dt = pd.to_datetime(curr_date, utc=True).normalize() - - # Filter the DataFrame for the given ticker and for reports that were published on or before the current date - filtered_df = df[(df["Ticker"] == ticker) & (df["Publish Date"] <= curr_date_dt)] - - # Check if there are any available reports; if not, return a notification - if filtered_df.empty: - print("No income statement available before the given current date.") - return "" - - # Get the most recent income statement by selecting the row with the latest Publish Date - latest_income = filtered_df.loc[filtered_df["Publish Date"].idxmax()] - - # drop the SimFinID column - latest_income = latest_income.drop("SimFinId") - - return ( - f"## {freq} income statement for {ticker} released on {str(latest_income['Publish Date'])[0:10]}: \n" - + str(latest_income) - + "\n\nThis includes metadata like reporting dates and currency, share details, and a comprehensive breakdown of the company's financial performance. Starting with Revenue, it shows Cost of Revenue and resulting Gross Profit. Operating Expenses are detailed, including SG&A, R&D, and Depreciation. The statement then shows Operating Income, followed by non-operating items and Interest Expense, leading to Pretax Income. After accounting for Income Tax and any Extraordinary items, it concludes with Net Income, representing the company's bottom-line profit or loss for the period." - ) - - def get_google_news( query: Annotated[str, "Query to search with"], curr_date: Annotated[str, "Curr date in yyyy-mm-dd format"], @@ -356,7 +91,6 @@ def get_google_news( return f"## {query} Google News, from {before} to {curr_date}:\n\n{news_str}" - def get_reddit_global_news( start_date: Annotated[str, "Start date in yyyy-mm-dd format"], look_back_days: Annotated[int, "how many days to look back"], @@ -408,7 +142,6 @@ def get_reddit_global_news( return f"## Global News Reddit, from {before} to {curr_date}:\n{news_str}" - def get_reddit_company_news( ticker: Annotated[str, "ticker symbol of the company"], start_date: Annotated[str, "Start date in yyyy-mm-dd format"], @@ -492,7 +225,7 @@ def get_binance_data( symbol += "USDT" # Ensure the symbol ends with USDT for futures klines_str = "" - klines = get_binance_klines(symbol, interval, klines_limit) + klines = fetch_klines_from_binance(symbol, interval, klines_limit) if klines is not None and len(klines) != 0: klines = list(map(lambda x: { "t": x[0], "o": x[1], "h": x[2], "l": x[3], "c": x[4], "v": x[5] }, klines)) klines_str = f"## {symbol} Futures **KLines Data** for {interval} interval:\n" + "\n".join( @@ -500,7 +233,7 @@ def get_binance_data( ) + "\n\n" depth_str = "" - depth = get_binance_depth(symbol, depth_limit) + depth = fetch_depth_from_binance(symbol, depth_limit) if depth is not None and isinstance(depth, dict): bids = depth.get("bids", [-1, -1]) asks = depth.get("asks", [-1, -1]) @@ -508,12 +241,12 @@ def get_binance_data( depth_str = f"## {symbol} Futures **Current Depth Data**:\nBids: Price: {depth["bids"]["price"]}, Volume: {depth["bids"]["volume"]}\nAsks: Price: {depth["asks"]["price"]}, Volume: {depth["asks"]["volume"]}\n\n" ticker_24hr_str = "" - ticker_24hr = get_binance_24hr_pricechange(symbol) + ticker_24hr = fetch_24hr_pricechange_from_binance(symbol) if ticker_24hr is not None and isinstance(ticker_24hr, dict): ticker_24hr_str = f"## {symbol} Futures **24-Hour Price Change**:\nPrice Change: {ticker_24hr.get("priceChange", "N/A")}, Price Change Percent: {ticker_24hr.get("priceChangePercent", "N/A")}, Weighted Avg Price: {ticker_24hr.get("weightedAvgPrice", "N/A")}\n\n" top_longshort_position_ratio_str = "" - top_longshort_position_ratio = get_binance_toplongshort_position_ratio(symbol, interval, longshort_limit) + top_longshort_position_ratio = fetch_toplongshort_position_ratio_from_binance(symbol, interval, longshort_limit) if top_longshort_position_ratio is not None and isinstance(top_longshort_position_ratio, list): top_longshort_position_ratio = [ { "t": entry["timestamp"], "longShortRatio": entry["longShortRatio"] } @@ -524,7 +257,7 @@ def get_binance_data( ) + "\n\n" top_longshort_account_ratio_str = "" - top_longshort_account_ratio = get_binance_toplongshort_account_ratio(symbol, interval, longshort_limit) + top_longshort_account_ratio = fetch_toplongshort_account_ratio_from_binance(symbol, interval, longshort_limit) if top_longshort_account_ratio is not None and isinstance(top_longshort_account_ratio, list): top_longshort_account_ratio = [ { "t": entry["timestamp"], "longShortRatio": entry["longShortRatio"] } @@ -535,7 +268,7 @@ def get_binance_data( ) + "\n\n" global_longshort_account_ratio_str = "" - global_longshort_account_ratio = get_binance_global_longshort_account_ratio(symbol, interval, longshort_limit) + global_longshort_account_ratio = fetch_global_longshort_account_ratio_from_binance(symbol, interval, longshort_limit) if global_longshort_account_ratio is not None and isinstance(global_longshort_account_ratio, list): global_longshort_account_ratio = [ { "t": entry["timestamp"], "longShortRatio": entry["longShortRatio"] } @@ -546,7 +279,7 @@ def get_binance_data( ) + "\n\n" taker_longshort_ratio_str = "" - taker_longshort_ratio = get_binance_taker_longshort_ratio(symbol, interval, longshort_limit) + taker_longshort_ratio = fetch_taker_longshort_ratio_from_binance(symbol, interval, longshort_limit) if taker_longshort_ratio is not None and isinstance(taker_longshort_ratio, list): taker_longshort_ratio = [ { "t": entry["timestamp"], "buySellRatio": entry["buySellRatio"], "buyVol": entry["buyVol"], "sellVol": entry["sellVol"] } @@ -567,6 +300,385 @@ def get_binance_data( + taker_longshort_ratio_str ) +def get_stock_news_openai(ticker, curr_date): + config = get_config() + client = OpenAI( + base_url=config["backend_url"], + api_key=os.getenv(config["api_key_env_name"]) + ) + + response = client.responses.create( + model=config["quick_think_llm"], + input=[ + { + "role": "system", + "content": [ + { + "type": "input_text", + "text": f"Can you search Social Media for {ticker} from 7 days before {curr_date} to {curr_date}? Make sure you only get the data posted during that period.", + } + ], + } + ], + text={"format": {"type": "text"}}, + reasoning={}, + tools=[ + { + "type": "web_search_preview", + "user_location": {"type": "approximate"}, + "search_context_size": "low", + } + ], + temperature=1, + max_output_tokens=4096, + top_p=1, + store=True, + ) + + return response.output[1].content[0].text + +def get_global_news_openai(curr_date): + config = get_config() + client = OpenAI( + base_url=config["backend_url"], + api_key=os.getenv(config["api_key_env_name"]) + ) + + response = client.responses.create( + model=config["quick_think_llm"], + input=[ + { + "role": "system", + "content": [ + { + "type": "input_text", + "text": f"Can you search global or macroeconomics news from 7 days before {curr_date} to {curr_date} that would be informative for trading purposes? Make sure you only get the data posted during that period.", + } + ], + } + ], + text={"format": {"type": "text"}}, + reasoning={}, + tools=[ + { + "type": "web_search_preview", + "user_location": {"type": "approximate"}, + "search_context_size": "low", + } + ], + temperature=1, + max_output_tokens=4096, + top_p=1, + store=True, + ) + + return response.output[1].content[0].text + +def get_fundamentals_openai(ticker, curr_date): + config = get_config() + client = OpenAI( + base_url=config["backend_url"], + api_key=os.getenv(config["api_key_env_name"]) + ) + + response = client.responses.create( + model=config["quick_think_llm"], + input=[ + { + "role": "system", + "content": [ + { + "type": "input_text", + "text": f"Can you search Fundamental for discussions on {ticker} during of the month before {curr_date} to the month of {curr_date}. Make sure you only get the data posted during that period. List as a table, with PE/PS/Cash flow/ etc", + } + ], + } + ], + text={"format": {"type": "text"}}, + reasoning={}, + tools=[ + { + "type": "web_search_preview", + "user_location": {"type": "approximate"}, + "search_context_size": "low", + } + ], + temperature=1, + max_output_tokens=4096, + top_p=1, + store=True, + ) + + return response.output[1].content[0].text + +#region Deprecated Stock Utilities +@deprecated("Utilities only for stocks are deprecated.") +def get_finnhub_news( + ticker: Annotated[ + str, + "Search query of a company's, e.g. 'AAPL, TSM, etc.", + ], + curr_date: Annotated[str, "Current date in yyyy-mm-dd format"], + look_back_days: Annotated[int, "how many days to look back"], +): + """ + Retrieve news about a company within a time frame + + Args + ticker (str): ticker for the company you are interested in + start_date (str): Start date in yyyy-mm-dd format + end_date (str): End date in yyyy-mm-dd format + Returns + str: dataframe containing the news of the company in the time frame + + """ + + start_date = datetime.strptime(curr_date, "%Y-%m-%d") + before = start_date - relativedelta(days=look_back_days) + before = before.strftime("%Y-%m-%d") + + result = get_data_in_range(ticker, before, curr_date, "news_data", DATA_DIR) + + if len(result) == 0: + return "" + + combined_result = "" + for day, data in result.items(): + if len(data) == 0: + continue + for entry in data: + current_news = ( + "### " + entry["headline"] + f" ({day})" + "\n" + entry["summary"] + ) + combined_result += current_news + "\n\n" + + return f"## {ticker} News, from {before} to {curr_date}:\n" + str(combined_result) + +@deprecated("Utilities only for stocks are deprecated.") +def get_finnhub_company_insider_sentiment( + ticker: Annotated[str, "ticker symbol for the company"], + curr_date: Annotated[ + str, + "current date of you are trading at, yyyy-mm-dd", + ], + look_back_days: Annotated[int, "number of days to look back"], +): + """ + Retrieve insider sentiment about a company (retrieved from public SEC information) for the past 15 days + Args: + ticker (str): ticker symbol of the company + curr_date (str): current date you are trading on, yyyy-mm-dd + Returns: + str: a report of the sentiment in the past 15 days starting at curr_date + """ + + date_obj = datetime.strptime(curr_date, "%Y-%m-%d") + before = date_obj - relativedelta(days=look_back_days) + before = before.strftime("%Y-%m-%d") + + data = get_data_in_range(ticker, before, curr_date, "insider_senti", DATA_DIR) + + if len(data) == 0: + return "" + + result_str = "" + seen_dicts = [] + for date, senti_list in data.items(): + for entry in senti_list: + if entry not in seen_dicts: + result_str += f"### {entry['year']}-{entry['month']}:\nChange: {entry['change']}\nMonthly Share Purchase Ratio: {entry['mspr']}\n\n" + seen_dicts.append(entry) + + return ( + f"## {ticker} Insider Sentiment Data for {before} to {curr_date}:\n" + + result_str + + "The change field refers to the net buying/selling from all insiders' transactions. The mspr field refers to monthly share purchase ratio." + ) + +@deprecated("Utilities only for stocks are deprecated.") +def get_finnhub_company_insider_transactions( + ticker: Annotated[str, "ticker symbol"], + curr_date: Annotated[ + str, + "current date you are trading at, yyyy-mm-dd", + ], + look_back_days: Annotated[int, "how many days to look back"], +): + """ + Retrieve insider transcaction information about a company (retrieved from public SEC information) for the past 15 days + 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 the company's insider transaction/trading informtaion in the past 15 days + """ + + date_obj = datetime.strptime(curr_date, "%Y-%m-%d") + before = date_obj - relativedelta(days=look_back_days) + before = before.strftime("%Y-%m-%d") + + data = get_data_in_range(ticker, before, curr_date, "insider_trans", DATA_DIR) + + if len(data) == 0: + return "" + + result_str = "" + + seen_dicts = [] + for date, senti_list in data.items(): + for entry in senti_list: + if entry not in seen_dicts: + result_str += f"### Filing Date: {entry['filingDate']}, {entry['name']}:\nChange:{entry['change']}\nShares: {entry['share']}\nTransaction Price: {entry['transactionPrice']}\nTransaction Code: {entry['transactionCode']}\n\n" + seen_dicts.append(entry) + + return ( + f"## {ticker} insider transactions from {before} to {curr_date}:\n" + + result_str + + "The change field reflects the variation in share count—here a negative number indicates a reduction in holdings—while share specifies the total number of shares involved. The transactionPrice denotes the per-share price at which the trade was executed, and transactionDate marks when the transaction occurred. The name field identifies the insider making the trade, and transactionCode (e.g., S for sale) clarifies the nature of the transaction. FilingDate records when the transaction was officially reported, and the unique id links to the specific SEC filing, as indicated by the source. Additionally, the symbol ties the transaction to a particular company, isDerivative flags whether the trade involves derivative securities, and currency notes the currency context of the transaction." + ) + +@deprecated("Utilities only for stocks are deprecated.") +def get_simfin_balance_sheet( + ticker: Annotated[str, "ticker symbol"], + freq: Annotated[ + str, + "reporting frequency of the company's financial history: annual / quarterly", + ], + curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], +): + data_path = os.path.join( + DATA_DIR, + "fundamental_data", + "simfin_data_all", + "balance_sheet", + "companies", + "us", + f"us-balance-{freq}.csv", + ) + df = pd.read_csv(data_path, sep=";") + + # Convert date strings to datetime objects and remove any time components + df["Report Date"] = pd.to_datetime(df["Report Date"], utc=True).dt.normalize() + df["Publish Date"] = pd.to_datetime(df["Publish Date"], utc=True).dt.normalize() + + # Convert the current date to datetime and normalize + curr_date_dt = pd.to_datetime(curr_date, utc=True).normalize() + + # Filter the DataFrame for the given ticker and for reports that were published on or before the current date + filtered_df = df[(df["Ticker"] == ticker) & (df["Publish Date"] <= curr_date_dt)] + + # Check if there are any available reports; if not, return a notification + if filtered_df.empty: + print("No balance sheet available before the given current date.") + return "" + + # Get the most recent balance sheet by selecting the row with the latest Publish Date + latest_balance_sheet = filtered_df.loc[filtered_df["Publish Date"].idxmax()] + + # drop the SimFinID column + latest_balance_sheet = latest_balance_sheet.drop("SimFinId") + + return ( + f"## {freq} balance sheet for {ticker} released on {str(latest_balance_sheet['Publish Date'])[0:10]}: \n" + + str(latest_balance_sheet) + + "\n\nThis includes metadata like reporting dates and currency, share details, and a breakdown of assets, liabilities, and equity. Assets are grouped as current (liquid items like cash and receivables) and noncurrent (long-term investments and property). Liabilities are split between short-term obligations and long-term debts, while equity reflects shareholder funds such as paid-in capital and retained earnings. Together, these components ensure that total assets equal the sum of liabilities and equity." + ) + +@deprecated("Utilities only for stocks are deprecated.") +def get_simfin_cashflow( + ticker: Annotated[str, "ticker symbol"], + freq: Annotated[ + str, + "reporting frequency of the company's financial history: annual / quarterly", + ], + curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], +): + data_path = os.path.join( + DATA_DIR, + "fundamental_data", + "simfin_data_all", + "cash_flow", + "companies", + "us", + f"us-cashflow-{freq}.csv", + ) + df = pd.read_csv(data_path, sep=";") + + # Convert date strings to datetime objects and remove any time components + df["Report Date"] = pd.to_datetime(df["Report Date"], utc=True).dt.normalize() + df["Publish Date"] = pd.to_datetime(df["Publish Date"], utc=True).dt.normalize() + + # Convert the current date to datetime and normalize + curr_date_dt = pd.to_datetime(curr_date, utc=True).normalize() + + # Filter the DataFrame for the given ticker and for reports that were published on or before the current date + filtered_df = df[(df["Ticker"] == ticker) & (df["Publish Date"] <= curr_date_dt)] + + # Check if there are any available reports; if not, return a notification + if filtered_df.empty: + print("No cash flow statement available before the given current date.") + return "" + + # Get the most recent cash flow statement by selecting the row with the latest Publish Date + latest_cash_flow = filtered_df.loc[filtered_df["Publish Date"].idxmax()] + + # drop the SimFinID column + latest_cash_flow = latest_cash_flow.drop("SimFinId") + + return ( + f"## {freq} cash flow statement for {ticker} released on {str(latest_cash_flow['Publish Date'])[0:10]}: \n" + + str(latest_cash_flow) + + "\n\nThis includes metadata like reporting dates and currency, share details, and a breakdown of cash movements. Operating activities show cash generated from core business operations, including net income adjustments for non-cash items and working capital changes. Investing activities cover asset acquisitions/disposals and investments. Financing activities include debt transactions, equity issuances/repurchases, and dividend payments. The net change in cash represents the overall increase or decrease in the company's cash position during the reporting period." + ) + +@deprecated("Utilities only for stocks are deprecated.") +def get_simfin_income_statements( + ticker: Annotated[str, "ticker symbol"], + freq: Annotated[ + str, + "reporting frequency of the company's financial history: annual / quarterly", + ], + curr_date: Annotated[str, "current date you are trading at, yyyy-mm-dd"], +): + data_path = os.path.join( + DATA_DIR, + "fundamental_data", + "simfin_data_all", + "income_statements", + "companies", + "us", + f"us-income-{freq}.csv", + ) + df = pd.read_csv(data_path, sep=";") + + # Convert date strings to datetime objects and remove any time components + df["Report Date"] = pd.to_datetime(df["Report Date"], utc=True).dt.normalize() + df["Publish Date"] = pd.to_datetime(df["Publish Date"], utc=True).dt.normalize() + + # Convert the current date to datetime and normalize + curr_date_dt = pd.to_datetime(curr_date, utc=True).normalize() + + # Filter the DataFrame for the given ticker and for reports that were published on or before the current date + filtered_df = df[(df["Ticker"] == ticker) & (df["Publish Date"] <= curr_date_dt)] + + # Check if there are any available reports; if not, return a notification + if filtered_df.empty: + print("No income statement available before the given current date.") + return "" + + # Get the most recent income statement by selecting the row with the latest Publish Date + latest_income = filtered_df.loc[filtered_df["Publish Date"].idxmax()] + + # drop the SimFinID column + latest_income = latest_income.drop("SimFinId") + + return ( + f"## {freq} income statement for {ticker} released on {str(latest_income['Publish Date'])[0:10]}: \n" + + str(latest_income) + + "\n\nThis includes metadata like reporting dates and currency, share details, and a comprehensive breakdown of the company's financial performance. Starting with Revenue, it shows Cost of Revenue and resulting Gross Profit. Operating Expenses are detailed, including SG&A, R&D, and Depreciation. The statement then shows Operating Income, followed by non-operating items and Interest Expense, leading to Pretax Income. After accounting for Income Tax and any Extraordinary items, it concludes with Net Income, representing the company's bottom-line profit or loss for the period." + ) + +@deprecated("Utilities only for stocks are deprecated.") def get_stock_stats_indicators_window( symbol: Annotated[str, "ticker symbol of the company"], indicator: Annotated[str, "technical indicator to get the analysis and report of"], @@ -702,7 +814,7 @@ def get_stock_stats_indicators_window( return result_str - +@deprecated("Utilities only for stocks are deprecated.") def get_stockstats_indicator( symbol: Annotated[str, "ticker symbol of the company"], indicator: Annotated[str, "technical indicator to get the analysis and report of"], @@ -731,7 +843,7 @@ def get_stockstats_indicator( return str(indicator_value) - +@deprecated("Utilities only for stocks are deprecated.") def get_YFin_data_window( symbol: Annotated[str, "ticker symbol of the company"], curr_date: Annotated[str, "Start date in yyyy-mm-dd format"], @@ -772,7 +884,7 @@ def get_YFin_data_window( + df_string ) - +@deprecated("Utilities only for stocks are deprecated.") def get_YFin_data_online( symbol: Annotated[str, "ticker symbol of the company"], start_date: Annotated[str, "Start date in yyyy-mm-dd format"], @@ -814,7 +926,7 @@ def get_YFin_data_online( return header + csv_string - +@deprecated("Utilities only for stocks are deprecated.") def get_YFin_data( symbol: Annotated[str, "ticker symbol of the company"], start_date: Annotated[str, "Start date in yyyy-mm-dd format"], @@ -848,117 +960,4 @@ def get_YFin_data( filtered_data = filtered_data.reset_index(drop=True) return filtered_data - - -def get_stock_news_openai(ticker, curr_date): - config = get_config() - client = OpenAI( - base_url=config["backend_url"], - api_key=os.getenv(config["api_key_env_name"]) - ) - - response = client.responses.create( - model=config["quick_think_llm"], - input=[ - { - "role": "system", - "content": [ - { - "type": "input_text", - "text": f"Can you search Social Media for {ticker} from 7 days before {curr_date} to {curr_date}? Make sure you only get the data posted during that period.", - } - ], - } - ], - text={"format": {"type": "text"}}, - reasoning={}, - tools=[ - { - "type": "web_search_preview", - "user_location": {"type": "approximate"}, - "search_context_size": "low", - } - ], - temperature=1, - max_output_tokens=4096, - top_p=1, - store=True, - ) - - return response.output[1].content[0].text - - -def get_global_news_openai(curr_date): - config = get_config() - client = OpenAI( - base_url=config["backend_url"], - api_key=os.getenv(config["api_key_env_name"]) - ) - - response = client.responses.create( - model=config["quick_think_llm"], - input=[ - { - "role": "system", - "content": [ - { - "type": "input_text", - "text": f"Can you search global or macroeconomics news from 7 days before {curr_date} to {curr_date} that would be informative for trading purposes? Make sure you only get the data posted during that period.", - } - ], - } - ], - text={"format": {"type": "text"}}, - reasoning={}, - tools=[ - { - "type": "web_search_preview", - "user_location": {"type": "approximate"}, - "search_context_size": "low", - } - ], - temperature=1, - max_output_tokens=4096, - top_p=1, - store=True, - ) - - return response.output[1].content[0].text - - -def get_fundamentals_openai(ticker, curr_date): - config = get_config() - client = OpenAI( - base_url=config["backend_url"], - api_key=os.getenv(config["api_key_env_name"]) - ) - - response = client.responses.create( - model=config["quick_think_llm"], - input=[ - { - "role": "system", - "content": [ - { - "type": "input_text", - "text": f"Can you search Fundamental for discussions on {ticker} during of the month before {curr_date} to the month of {curr_date}. Make sure you only get the data posted during that period. List as a table, with PE/PS/Cash flow/ etc", - } - ], - } - ], - text={"format": {"type": "text"}}, - reasoning={}, - tools=[ - { - "type": "web_search_preview", - "user_location": {"type": "approximate"}, - "search_context_size": "low", - } - ], - temperature=1, - max_output_tokens=4096, - top_p=1, - store=True, - ) - - return response.output[1].content[0].text +#endregion \ No newline at end of file diff --git a/tradingagents/dataflows/stockstats_utils.py b/tradingagents/dataflows/stockstats_utils.py index 78ffb220..544f7c7d 100644 --- a/tradingagents/dataflows/stockstats_utils.py +++ b/tradingagents/dataflows/stockstats_utils.py @@ -5,7 +5,8 @@ from typing import Annotated import os from .config import get_config - +from warnings import deprecated +@deprecated("Utilities only for stocks are deprecated.") class StockstatsUtils: @staticmethod def get_stock_stats( diff --git a/tradingagents/dataflows/yfin_utils.py b/tradingagents/dataflows/yfin_utils.py index bd7ca324..01f6efd5 100644 --- a/tradingagents/dataflows/yfin_utils.py +++ b/tradingagents/dataflows/yfin_utils.py @@ -1,5 +1,4 @@ # gets data/stats - import yfinance as yf from typing import Annotated, Callable, Any, Optional from pandas import DataFrame @@ -19,7 +18,8 @@ def init_ticker(func: Callable) -> Callable: return wrapper - +from warnings import deprecated +@deprecated("Utilities only for stocks are deprecated.") @decorate_all_methods(init_ticker) class YFinanceUtils: diff --git a/tradingagents/default_config.py b/tradingagents/default_config.py index 25a51594..339f844b 100644 --- a/tradingagents/default_config.py +++ b/tradingagents/default_config.py @@ -18,12 +18,11 @@ DEFAULT_CONFIG = { "quick_think_llm": "qwen-turbo", "backend_url": "https://dashscope.aliyuncs.com/compatible-mode/v1", "api_key_env_name": "DASHSCOPE_API_KEY", + "max_tokens": 1000, # Maximum tokens for LLM responses # Debate and discussion settings "max_debate_rounds": 1, "max_risk_discuss_rounds": 1, "max_recur_limit": 200, - # Tool settings - "online_tools": True, # Language settings "language": "zh", # 支持 'zh' 或 'en' } diff --git a/tradingagents/graph/propagation.py b/tradingagents/graph/propagation.py index 58ebd0a8..90427598 100644 --- a/tradingagents/graph/propagation.py +++ b/tradingagents/graph/propagation.py @@ -11,7 +11,7 @@ from tradingagents.agents.utils.agent_states import ( class Propagator: """Handles state initialization and propagation through the graph.""" - def __init__(self, max_recur_limit=100): + def __init__(self, max_recur_limit=200): """Initialize with configuration parameters.""" self.max_recur_limit = max_recur_limit diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index 4fab9c0e..1d5b5fbf 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -117,44 +117,27 @@ class TradingAgentsGraph: return { "market": ToolNode( [ - # online tools - self.toolkit.get_binance_data, - self.toolkit.get_stockstats_indicators_report_online, - # offline tools - self.toolkit.get_YFin_data, - self.toolkit.get_stockstats_indicators_report, + self.toolkit.get_binance_data ] ), "social": ToolNode( [ - # online tools self.toolkit.get_stock_news_openai, - # offline tools self.toolkit.get_reddit_stock_info, ] ), "news": ToolNode( [ - # online tools - self.toolkit.get_global_news_openai, - self.toolkit.get_google_news, + # self.toolkit.get_global_news_openai, + # self.toolkit.get_google_news, self.toolkit.get_blockbeats_news, self.toolkit.get_coindesk_news, - # offline tools - self.toolkit.get_finnhub_news, - self.toolkit.get_reddit_news, + # self.toolkit.get_reddit_news, ] ), "fundamentals": ToolNode( [ - # online tools - self.toolkit.get_fundamentals_openai, - # offline tools - self.toolkit.get_finnhub_company_insider_sentiment, - self.toolkit.get_finnhub_company_insider_transactions, - self.toolkit.get_simfin_balance_sheet, - self.toolkit.get_simfin_cashflow, - self.toolkit.get_simfin_income_stmt, + self.toolkit.get_fundamentals_openai ] ), }