|
import sys |
|
import os |
|
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
|
from zacks import find_rank_1_stocks |
|
from .state import AgentState, AgentState2 |
|
|
|
def zacks_analyzer(state: AgentState2) -> AgentState2: |
|
"""Fetches high-rank stocks from Zacks for potential new investments.""" |
|
try: |
|
|
|
high_rank_stocks = find_rank_1_stocks(n=15) |
|
|
|
|
|
|
|
|
|
state["high_rank_stocks"] = high_rank_stocks |
|
|
|
|
|
stock_symbols = [stock['symbol'] for stock in high_rank_stocks] |
|
state["messages"] = state.get("messages", []) + [{ |
|
"role": "ai", |
|
"content": f"[ZacksAnalyzer] I've identified {len(high_rank_stocks)} high-ranked stocks from Zacks: {', '.join(stock_symbols)}" |
|
}] |
|
|
|
except Exception as e: |
|
|
|
state["messages"] = state.get("messages", []) + [{ |
|
"role": "ai", |
|
"content": f"[ZacksAnalyzer] Error fetching high-rank stocks: {str(e)}" |
|
}] |
|
state["high_rank_stocks"] = [] |
|
|
|
return state |