Initial commit: Gold Trading Simulator with AI-powered analysis
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from app.services.openrouter import openrouter_service
|
||||
from app.schemas.schemas import AIAnalysisRequest, AIAnalysisResponse
|
||||
from app.services.decisions import log_decision
|
||||
|
||||
router = APIRouter(prefix="/ai", tags=["AI Analysis"])
|
||||
|
||||
|
||||
@router.post("/analyze", response_model=AIAnalysisResponse)
|
||||
async def analyze_scenario(request: AIAnalysisRequest):
|
||||
"""
|
||||
Analyze trading scenario using AI (Claude 3.5 Sonnet via OpenRouter)
|
||||
|
||||
Provides:
|
||||
- Trading recommendation (BUY/SELL/HOLD)
|
||||
- Confidence level
|
||||
- Detailed reasoning
|
||||
- Support and resistance levels
|
||||
- Risk assessment
|
||||
"""
|
||||
try:
|
||||
analysis = await openrouter_service.analyze_scenario(request)
|
||||
# Log decision (best-effort) with minimal metadata
|
||||
try:
|
||||
log_decision(
|
||||
symbol="XAU/USD",
|
||||
timeframe="unknown",
|
||||
style="unknown",
|
||||
recommendation=analysis.recommendation.value if hasattr(analysis, 'recommendation') else str(analysis.recommendation),
|
||||
confidence=float(analysis.confidence),
|
||||
risk_level=analysis.risk_level.value if hasattr(analysis, 'risk_level') else str(analysis.risk_level),
|
||||
rationale=analysis.reasoning,
|
||||
inputs_hash=None,
|
||||
cost={},
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return analysis
|
||||
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"AI analysis failed: {str(e)}"
|
||||
)
|
||||
Reference in New Issue
Block a user