수정본

This commit is contained in:
2026-02-22 17:23:20 +09:00
parent b147498c31
commit 32e2263f0a
109 changed files with 13979 additions and 4580 deletions

View File

@@ -6,11 +6,14 @@ import logging
from config import settings
from claude_client import claude_client
from perplexity_client import perplexity_client
from mcp_tools import mcp_tools
# AI 클라이언트 선택
ai_client = perplexity_client if settings.AI_PROVIDER == "perplexity" else claude_client
# AI_PROVIDER에 따라 클라이언트 동적 선택
if settings.AI_PROVIDER == "gemini":
from gemini_client import gemini_client
ai_client = gemini_client
else:
ai_client = claude_client
# 로깅 설정
logging.basicConfig(
@@ -61,7 +64,7 @@ async def health_check():
"status": "healthy",
"ai_provider": settings.AI_PROVIDER,
"claude_configured": bool(settings.ANTHROPIC_API_KEY),
"perplexity_configured": bool(settings.PERPLEXITY_API_KEY)
"gemini_configured": bool(settings.GEMINI_API_KEY),
}
@@ -102,7 +105,18 @@ async def analyze(request: AnalysisRequest):
detail="rule and market_data are required"
)
result = await ai_client.validate_trading_rule(rule, market_data)
# 뉴스 정보 추가 수집
stock_code = market_data.get("stock_code")
news_data = []
if stock_code:
try:
news_result = await mcp_tools.get_news(stock_code, limit=settings.NEWS_LIMIT)
if "news" in news_result:
news_data = news_result["news"]
except Exception as e:
logger.warning(f"Failed to fetch news for validation: {e}")
result = await ai_client.validate_trading_rule(rule, market_data, news_data)
return {
"analysis_type": analysis_type,
"result": result
@@ -162,6 +176,49 @@ async def analyze(request: AnalysisRequest):
"analysis_type": analysis_type,
"result": result
}
elif analysis_type == "RULE_OPTIMIZATION":
# 트레이딩 규칙 최적화/생성
stock_code = data.get("stock_code")
market_data = data.get("market_data")
if not stock_code or not market_data:
raise HTTPException(
status_code=400,
detail="stock_code and market_data are required"
)
# 뉴스 정보 추가 수집
news_data = []
try:
news_result = await mcp_tools.get_news(stock_code, limit=settings.NEWS_LIMIT)
if "news" in news_result:
news_data = news_result["news"]
except Exception as e:
logger.warning(f"Failed to fetch news for optimization: {e}")
result = await ai_client.optimize_trading_rules(stock_code, market_data, news_data)
return {
"analysis_type": analysis_type,
"result": result
}
elif analysis_type == "GENERATE_JOURNAL":
# 매매일지 생성
trade_info = data.get("trade_info")
market_data = data.get("market_data")
if not trade_info or not market_data:
raise HTTPException(
status_code=400,
detail="trade_info and market_data are required"
)
result = await ai_client.generate_trade_journal(trade_info, market_data)
return {
"analysis_type": analysis_type,
"result": result
}
else:
raise HTTPException(