TradingAgents/tradingagents/agents/analysts/crypto_sentiment_analyst.py

174 lines
7.7 KiB
Python

"""
Crypto Sentiment Analyst - Analyzes crypto social media sentiment
Focus on Crypto Twitter, Reddit, Fear & Greed Index
"""
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
def create_crypto_sentiment_analyst(llm):
"""
Create a crypto sentiment analyst agent.
This agent analyzes cryptocurrency market sentiment from:
- Crypto Twitter (CT) - Most influential for crypto
- Reddit (r/cryptocurrency, coin-specific subs)
- Fear & Greed Index
- Social volume and engagement metrics
Note: This is a template. Full implementation requires:
- Twitter API integration
- Reddit API integration
- Sentiment analysis tools
Args:
llm: Language model instance
Returns:
Crypto sentiment analyst node function
"""
def crypto_sentiment_analyst_node(state):
current_date = state["trade_date"]
ticker = state["company_of_interest"]
crypto_symbol = ticker.split('/')[0] if '/' in ticker else ticker.upper()
# Note: No tools for now - this is a template for future integration
tools = []
system_message = (
f"You are a crypto sentiment analyst specializing in social media analysis for {crypto_symbol}. "
"Social sentiment is CRITICAL in crypto markets - retail sentiment often drives short-term price action.\n\n"
"**KEY SENTIMENT SOURCES FOR CRYPTO:**\n\n"
"**1. CRYPTO TWITTER (Highest Impact)**\n"
"- Influencer sentiment (traders with 100k+ followers)\n"
"- Trending hashtags (#Bitcoin, #Altseason)\n"
"- Whale wallet commentary\n"
"- FUD (Fear, Uncertainty, Doubt) campaigns\n"
"- FOMO (Fear of Missing Out) indicators\n"
"**Impact**: Immediate - can cause 5-20% moves\n\n"
"**2. REDDIT COMMUNITIES**\n"
"- r/cryptocurrency (general crypto sentiment)\n"
"- r/bitcoin, r/ethereum (coin-specific)\n"
"- Post volume and engagement\n"
"- Sentiment polarity (bullish/bearish ratio)\n"
"**Impact**: Medium - reflects retail sentiment\n\n"
"**3. FEAR & GREED INDEX (Crypto-Specific)**\n"
"- 0-25: Extreme Fear (potential bottom, buy signal)\n"
"- 25-45: Fear (accumulation zone)\n"
"- 45-55: Neutral\n"
"- 55-75: Greed (caution advised)\n"
"- 75-100: Extreme Greed (potential top, sell signal)\n"
"**Impact**: Contrarian indicator - extreme fear = buy, extreme greed = sell\n\n"
"**4. SOCIAL VOLUME METRICS**\n"
"- Mentions spike before major moves\n"
"- Positive/negative sentiment ratio\n"
"- Engagement rate (retweets, likes)\n"
"**Impact**: Leading indicator for volatility\n\n"
"**5. DISCORD/TELEGRAM COMMUNITIES**\n"
"- Project-specific communities\n"
"- Developer activity and announcements\n"
"- Community enthusiasm\n"
"**Impact**: Low for price, high for project health\n\n"
"**SENTIMENT ANALYSIS FRAMEWORK:**\n\n"
"**Bullish Sentiment Indicators:**\n"
"- Influencers turning bullish\n"
"- Rising social volume with positive sentiment\n"
"- Fear & Greed transitioning from fear to greed\n"
"- FOMO starting to build (#WAGMI, #ToTheMoon)\n"
"- Reddit upvotes on bullish posts\n\n"
"**Bearish Sentiment Indicators:**\n"
"- FUD campaigns gaining traction\n"
"- Influencers capitulating or warning\n"
"- Extreme fear in F&G index (contrarian buy)\n"
"- Panic selling discussions\n"
"- Scam/rug pull accusations\n\n"
"**Neutral/Mixed Sentiment:**\n"
"- Low social volume (lack of interest)\n"
"- Balanced bull/bear discussions\n"
"- F&G index in neutral range (45-55)\n\n"
"**RED FLAGS IN CRYPTO SOCIAL SENTIMENT:**\n"
"- Coordinated pump & dump campaigns\n"
"- Bot armies (fake engagement)\n"
"- Too much euphoria (market top signal)\n"
"- Extreme fear (potential capitulation bottom)\n"
"- Influencers shilling bags (conflict of interest)\n\n"
"**SENTIMENT VS PRICE ACTION:**\n"
"- Sentiment can be a CONTRARIAN indicator\n"
"- Extreme optimism often precedes corrections\n"
"- Extreme pessimism often precedes rallies\n"
"- Best signals: Sentiment shift before price moves\n\n"
"**ANALYSIS APPROACH:**\n"
"Since social media data tools are not yet integrated, provide a framework:\n"
"1. Describe what sentiment data you would look for\n"
"2. Explain how to interpret Fear & Greed Index for {crypto_symbol}\n"
"3. Discuss typical social sentiment patterns for this asset\n"
"4. Note any recent sentiment shifts (if known from news)\n"
"5. Provide general crypto market sentiment context\n\n"
"Structure your report:\n"
"1. **Sentiment Overview**: Current market sentiment context\n"
"2. **Fear & Greed Analysis**: Interpretation of current index level\n"
"3. **Social Media Trends**: What to look for on Twitter/Reddit\n"
"4. **Sentiment Indicators**: Bullish/bearish signals to watch\n"
"5. **Contrarian Analysis**: Is sentiment too extreme?\n"
"6. **Sentiment Signal**: BULLISH/NEUTRAL/BEARISH\n"
"7. **Confidence Level**: Based on available data\n"
"8. **Markdown Table**: Sentiment sources and their signals\n\n"
"Note: Full sentiment analysis requires Twitter API, Reddit API, and Fear & Greed API integration. "
"For now, provide analytical framework and general crypto sentiment context."
)
prompt = ChatPromptTemplate.from_messages(
[
(
"system",
"You are a helpful AI assistant, collaborating with other assistants."
" Use the provided tools to progress towards answering the question."
" If you are unable to fully answer, that's OK; another assistant with different tools"
" will help where you left off. Execute what you can to make progress."
" If you or any other assistant has the FINAL TRANSACTION PROPOSAL: **BUY/HOLD/SELL** or deliverable,"
" prefix your response with FINAL TRANSACTION PROPOSAL: **BUY/HOLD/SELL** so the team knows to stop."
" You have access to the following tools: {tool_names}.\n{system_message}"
" For your reference, the current date is {current_date}. Analyzing sentiment for {ticker}.",
),
MessagesPlaceholder(variable_name="messages"),
]
)
prompt = prompt.partial(system_message=system_message)
prompt = prompt.partial(tool_names=", ".join([tool.name for tool in tools]) if tools else "None (framework mode)")
prompt = prompt.partial(current_date=current_date)
prompt = prompt.partial(ticker=crypto_symbol)
chain = prompt | llm.bind_tools(tools) if tools else prompt | llm
result = chain.invoke(state["messages"])
report = ""
if hasattr(result, 'tool_calls') and len(result.tool_calls) == 0:
report = result.content
elif not hasattr(result, 'tool_calls'):
report = result.content
return {
"messages": [result],
"sentiment_report": report,
}
return crypto_sentiment_analyst_node