33 lines
1.6 KiB
Python
33 lines
1.6 KiB
Python
from langchain_core.tools import tool
|
|
from typing import Annotated
|
|
from tradingagents.dataflows.interface import route_to_vendor
|
|
|
|
@tool
|
|
def get_indicators(
|
|
symbol: Annotated[str, "ticker symbol of the company"],
|
|
indicator: Annotated[str, "technical indicator name or a comma-separated list of indicator names for batch retrieval"],
|
|
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 one or more technical indicators 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): One technical indicator name, e.g. 'rsi', 'macd', or a comma-separated batch such as 'macd,rsi,atr,close_50_sma'.
|
|
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 requested technical indicator output(s). Batch requests are recommended to reduce repeated tool calls.
|
|
"""
|
|
# LLMs sometimes pass multiple indicators as a comma-separated string;
|
|
# split and process each individually.
|
|
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)
|