mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-27 15:02:39 +03:00
- interface -> router; symbol_utils -> symbols, which also takes safe_ticker_component - utils is split: get_current_date to date_window, the HTTP helpers to net - dataflows imports are absolute; the NoMarketDataError re-export from symbols is gone
40 lines
1.7 KiB
Python
40 lines
1.7 KiB
Python
from typing import Annotated
|
|
|
|
from langchain_core.tools import tool
|
|
from langgraph.prebuilt import InjectedState
|
|
|
|
from tradingagents.dataflows.date_window import as_of
|
|
from tradingagents.dataflows.router import route_to_vendor
|
|
|
|
|
|
@tool
|
|
def get_indicators(
|
|
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,
|
|
trade_date: Annotated[str, InjectedState("trade_date")] = "",
|
|
) -> str:
|
|
"""
|
|
Retrieve a single technical indicator for a given ticker symbol.
|
|
Uses the configured technical_indicators vendor.
|
|
Args:
|
|
symbol (str): Ticker symbol of the company, e.g. AAPL, TSM
|
|
indicator (str): A single technical indicator name, e.g. 'rsi', 'macd'. Call this tool once per indicator.
|
|
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 technical indicators for the specified ticker symbol and indicator.
|
|
"""
|
|
# LLMs sometimes pass multiple indicators as a comma-separated string;
|
|
# split and process each individually.
|
|
curr_date = as_of(curr_date, trade_date)
|
|
indicators = [i.strip().lower() for i in indicator.split(",") if i.strip()]
|
|
results = []
|
|
for ind in indicators:
|
|
try:
|
|
results.append(route_to_vendor("get_indicators", symbol, ind, curr_date, look_back_days))
|
|
except ValueError as e:
|
|
results.append(str(e))
|
|
return "\n\n".join(results)
|