From 4ff4a6eb3cb83823e79e784472d13b20d6afaaf4 Mon Sep 17 00:00:00 2001 From: rdyzakya Date: Fri, 26 Dec 2025 01:31:50 +0800 Subject: [PATCH] add get white paper, get market capitalization, get fundamental data of crypto --- .../agents/analysts/fundamentals_analyst.py | 11 +++--- tradingagents/agents/utils/agent_utils.py | 4 +- .../agents/utils/fundamental_data_tools.py | 26 ++++++++++++- .../dataflows/coin_gecko_fundamentals.py | 21 +++++++++++ tradingagents/dataflows/interface.py | 24 +++++++++--- tradingagents/dataflows/openai.py | 37 ++++++++++++++++++- tradingagents/graph/trading_graph.py | 14 ++++--- 7 files changed, 117 insertions(+), 20 deletions(-) create mode 100644 tradingagents/dataflows/coin_gecko_fundamentals.py diff --git a/tradingagents/agents/analysts/fundamentals_analyst.py b/tradingagents/agents/analysts/fundamentals_analyst.py index e20139cb..95eb67b5 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, MessagesPlaceholder import time import 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_whitepaper, get_market_cap from tradingagents.dataflows.config import get_config @@ -13,15 +13,14 @@ def create_fundamentals_analyst(llm): tools = [ get_fundamentals, - get_balance_sheet, - get_cashflow, - get_income_statement, + get_whitepaper, + get_market_cap ] system_message = ( - "You are a researcher tasked with analyzing fundamental information over the past week about a company. Please write a comprehensive report of the company's fundamental information such as financial documents, company profile, basic company financials, and company financial history to gain a full view of the company's fundamental information to inform traders. Make sure to include as much detail as possible. Do not simply state the trends are mixed, provide detailed and finegrained analysis and insights that may help traders make decisions." + "You are a researcher tasked with analyzing fundamental information over the past week about a crypto-currency coin. Please write a comprehensive report of the coin's fundamental information such as fundamental information, whitepaper, and global market capitalization to gain a full view of the coin's fundamental information to inform traders. Make sure to include as much detail as possible. Do not simply state the trends are mixed, provide detailed and finegrained analysis and insights that may help traders make decisions." + " Make sure to append a Markdown table at the end of the report to organize key points in the report, organized and easy to read." - + " Use the available tools: `get_fundamentals` for comprehensive company analysis, `get_balance_sheet`, `get_cashflow`, and `get_income_statement` for specific financial statements.", + + " Use the available tools: `get_fundamentals` for comprehensive coin analysis, `get_whitepaper`, and `get_market_cap` for specific information.", ) prompt = ChatPromptTemplate.from_messages( diff --git a/tradingagents/agents/utils/agent_utils.py b/tradingagents/agents/utils/agent_utils.py index 6cf294a1..144f887d 100644 --- a/tradingagents/agents/utils/agent_utils.py +++ b/tradingagents/agents/utils/agent_utils.py @@ -11,7 +11,9 @@ from tradingagents.agents.utils.fundamental_data_tools import ( get_fundamentals, get_balance_sheet, get_cashflow, - get_income_statement + get_income_statement, + get_whitepaper, + get_market_cap ) from tradingagents.agents.utils.news_data_tools import ( get_news, diff --git a/tradingagents/agents/utils/fundamental_data_tools.py b/tradingagents/agents/utils/fundamental_data_tools.py index 47f6f2eb..7c14fbff 100644 --- a/tradingagents/agents/utils/fundamental_data_tools.py +++ b/tradingagents/agents/utils/fundamental_data_tools.py @@ -74,4 +74,28 @@ def get_income_statement( Returns: str: A formatted report containing income statement data """ - return route_to_vendor("get_income_statement", ticker, freq, curr_date) \ No newline at end of file + return route_to_vendor("get_income_statement", ticker, freq, curr_date) + +@tool +def get_whitepaper( + ticker: Annotated[str, "ticker symbol"], +) -> str: + """ + Retrieve the whitepaper for a given ticker symbol. + Uses the configured fundamental_data vendor. + Args: + ticker (str): Ticker symbol of the cryptocurrency + Returns: + str: A formatted string containing the whitepaper link or content + """ + return route_to_vendor("get_whitepaper", ticker) + +@tool +def get_market_cap() -> str: + """ + Retrieve the market capitalization percentages for cryptocurrencies. + Uses the configured fundamental_data vendor. + Returns: + str: A formatted string containing market capitalization percentages + """ + return route_to_vendor("get_market_cap") \ No newline at end of file diff --git a/tradingagents/dataflows/coin_gecko_fundamentals.py b/tradingagents/dataflows/coin_gecko_fundamentals.py new file mode 100644 index 00000000..7e8f5759 --- /dev/null +++ b/tradingagents/dataflows/coin_gecko_fundamentals.py @@ -0,0 +1,21 @@ +import requests +from .alpha_vantage_common import API_BASE_URL + +def get_market_cap() -> str: + """ + Retrieve the market capitalization percentage data for various cryptocurrencies using CoinGecko. + + Returns: + str: Market capitalization percentage data for cryptocurrencies + """ + endpoint = f"https://api.coingecko.com/api/v3/global" + response = requests.get(endpoint) + response.raise_for_status() + data = response.json() + market_cap_pct = data.get("data", {}).get("market_cap_percentage", {}) + # return json.dumps(result, indent=2) + result = "# Market Capitalization Percentage Data\n\n" + for coin, percentage in market_cap_pct.items(): + # Format each line as "Coin: XX.XX%" + result += f"- {coin.upper()}: {percentage:.2f}%\n" + return result \ No newline at end of file diff --git a/tradingagents/dataflows/interface.py b/tradingagents/dataflows/interface.py index 5941a629..00989541 100644 --- a/tradingagents/dataflows/interface.py +++ b/tradingagents/dataflows/interface.py @@ -4,7 +4,7 @@ from typing import Annotated from .local import get_YFin_data, get_finnhub_news, get_finnhub_company_insider_sentiment, get_finnhub_company_insider_transactions, get_simfin_balance_sheet, get_simfin_cashflow, get_simfin_income_statements, get_reddit_global_news, get_reddit_company_news from .y_finance import get_YFin_data_online, get_stock_stats_indicators_window, get_balance_sheet as get_yfinance_balance_sheet, get_cashflow as get_yfinance_cashflow, get_income_statement as get_yfinance_income_statement, get_insider_transactions as get_yfinance_insider_transactions from .google import get_google_news -from .openai import get_crypto_news_openai, get_global_news_openai, get_fundamentals_openai +from .openai import get_crypto_news_openai, get_global_news_openai, get_fundamentals_openai, get_whitepaper_openai from .alpha_vantage import ( get_stock as get_alpha_vantage_stock, get_indicator as get_alpha_vantage_indicator, @@ -17,6 +17,7 @@ from .alpha_vantage import ( ) from .alpha_vantage_common import AlphaVantageRateLimitError from .telegram import get_crypto_news_telegram +from .coin_gecko_fundamentals import get_market_cap as get_coin_gecko_market_cap # Configuration and routing logic from .config import get_config @@ -39,9 +40,11 @@ TOOLS_CATEGORIES = { "description": "Company fundamentals", "tools": [ "get_fundamentals", - "get_balance_sheet", - "get_cashflow", - "get_income_statement" + # "get_balance_sheet", + # "get_cashflow", + # "get_income_statement", + "get_whitepaper", + "get_market_cap" ] }, "news_data": { @@ -59,7 +62,10 @@ VENDOR_LIST = [ "local", "yfinance", "openai", - "google" + "google", + "telegram", + "coin_gecko", + "alpha_vantage", ] # Mapping of methods to their vendor-specific implementations @@ -78,9 +84,15 @@ VENDOR_METHODS = { }, # fundamental_data "get_fundamentals": { - "alpha_vantage": get_alpha_vantage_fundamentals, + # "alpha_vantage": get_alpha_vantage_fundamentals, "openai": get_fundamentals_openai, }, + "get_whitepaper": { + "openai": get_whitepaper_openai, + }, + "get_market_cap" : { + "coin_gecko": get_coin_gecko_market_cap + }, "get_balance_sheet": { "alpha_vantage": get_alpha_vantage_balance_sheet, "yfinance": get_yfinance_balance_sheet, diff --git a/tradingagents/dataflows/openai.py b/tradingagents/dataflows/openai.py index 7b543f90..c75151e2 100644 --- a/tradingagents/dataflows/openai.py +++ b/tradingagents/dataflows/openai.py @@ -117,7 +117,42 @@ def get_fundamentals_openai(ticker, curr_date): "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": 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": f"Can you search Fundamental data on {ticker} crypto-currency coin before {curr_date} to {curr_date}. Make sure you only get the data posted during that period. The data includes purpose, use case, technology, token utility, tokenomics, team & organization, development activity, ecosystem & adoption, and governance & community.", + } + ], + } + ], + 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_whitepaper_openai(symbol): + config = get_config() + client = OpenAI(base_url=config["backend_url"]) + + response = client.responses.create( + model=config["quick_think_llm"], + input=[ + { + "role": "system", + "content": [ + { + "type": "input_text", + "text": f"Give me the summary of {symbol} crypto coin white paper.", } ], } diff --git a/tradingagents/graph/trading_graph.py b/tradingagents/graph/trading_graph.py index 40cdff75..aefc110d 100644 --- a/tradingagents/graph/trading_graph.py +++ b/tradingagents/graph/trading_graph.py @@ -27,6 +27,8 @@ from tradingagents.agents.utils.agent_utils import ( get_stock_data, get_indicators, get_fundamentals, + get_whitepaper, + get_market_cap, get_balance_sheet, get_cashflow, get_income_statement, @@ -142,17 +144,19 @@ class TradingAgentsGraph: # News and insider information get_news, get_global_news, - get_insider_sentiment, - get_insider_transactions, + # get_insider_sentiment, + # get_insider_transactions, ] ), "fundamentals": ToolNode( [ # Fundamental analysis tools get_fundamentals, - get_balance_sheet, - get_cashflow, - get_income_statement, + get_whitepaper, + get_market_cap, + # get_balance_sheet, + # get_cashflow, + # get_income_statement, ] ), }