feat: add get fear & greed tool
This commit is contained in:
parent
9bd13690ac
commit
b049568274
|
|
@ -1,7 +1,7 @@
|
|||
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
|
||||
import time
|
||||
import json
|
||||
from tradingagents.agents.utils.agent_utils import get_news
|
||||
from tradingagents.agents.utils.agent_utils import get_news, get_fear_and_greed
|
||||
from tradingagents.dataflows.config import get_config
|
||||
|
||||
|
||||
|
|
@ -13,6 +13,7 @@ def create_social_media_analyst(llm):
|
|||
|
||||
tools = [
|
||||
get_news,
|
||||
get_fear_and_greed,
|
||||
]
|
||||
|
||||
system_message = (
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ from tradingagents.agents.utils.news_data_tools import (
|
|||
get_insider_transactions,
|
||||
get_global_news
|
||||
)
|
||||
from tradingagents.agents.utils.sentiment_tools import (
|
||||
get_fear_and_greed,
|
||||
)
|
||||
|
||||
def create_msg_delete():
|
||||
def delete_messages(state):
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
from langchain_core.tools import tool
|
||||
from typing import Annotated
|
||||
from tradingagents.dataflows.interface import route_to_vendor
|
||||
|
||||
@tool
|
||||
def get_fear_and_greed(
|
||||
look_back_days: Annotated[int, "how many days to look back"] = 30,
|
||||
) -> str:
|
||||
"""
|
||||
Retrieve the latest Fear and Greed Index.
|
||||
Uses the configured sentiment_analysis vendor.
|
||||
Args:
|
||||
look_back_days (int): How many days to look back, default is 30
|
||||
Returns:
|
||||
str: A formatted string containing the Fear and Greed Index.
|
||||
"""
|
||||
return route_to_vendor("get_fear_and_greed", look_back_days)
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Annotated
|
||||
|
||||
# Import from vendor-specific modules
|
||||
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 .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, get_fear_and_greed
|
||||
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_stock_news_openai, get_global_news_openai, get_fundamentals_openai
|
||||
|
|
@ -50,6 +50,7 @@ TOOLS_CATEGORIES = {
|
|||
"get_global_news",
|
||||
"get_insider_sentiment",
|
||||
"get_insider_transactions",
|
||||
"get_fear_and_greed"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
@ -114,6 +115,9 @@ VENDOR_METHODS = {
|
|||
"yfinance": get_yfinance_insider_transactions,
|
||||
"local": get_finnhub_company_insider_transactions,
|
||||
},
|
||||
"get_fear_and_greed": {
|
||||
"local": get_fear_and_greed,
|
||||
},
|
||||
}
|
||||
|
||||
def get_category_for_method(method: str) -> str:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from typing import Annotated
|
||||
import pandas as pd
|
||||
import os
|
||||
import requests
|
||||
from .config import DATA_DIR
|
||||
from datetime import datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
|
@ -472,4 +473,30 @@ def get_reddit_company_news(
|
|||
else:
|
||||
news_str += f"### {post['title']}\n\n{post['content']}\n\n"
|
||||
|
||||
return f"##{query} News Reddit, from {start_date} to {end_date}:\n\n{news_str}"
|
||||
return f"##{query} News Reddit, from {start_date} to {end_date}:\n\n{news_str}"
|
||||
|
||||
|
||||
def get_fear_and_greed(
|
||||
look_back_days: Annotated[int, "how many days to look back"] = 30,
|
||||
) -> str:
|
||||
"""
|
||||
Retrieve the latest Fear and Greed Index.
|
||||
Args:
|
||||
look_back_days (int): How many days to look back, default is 30
|
||||
Returns:
|
||||
str: A formatted string containing the Fear and Greed Index.
|
||||
"""
|
||||
|
||||
url = f"https://api.alternative.me/fng/?limit={look_back_days}&date_format=world"
|
||||
response = requests.get(url)
|
||||
|
||||
data = response.json().get("data", [])
|
||||
|
||||
if len(data) == 0:
|
||||
return ""
|
||||
|
||||
result_str = "## Fear and Greed Index Data:\n\n"
|
||||
for entry in data:
|
||||
result_str += f"### Date: {entry['timestamp']}\nFear and Greed Index: {entry['value']}\nClassification: {entry['value_classification']}\n\n"
|
||||
|
||||
return result_str
|
||||
Loading…
Reference in New Issue