Reorganize UI for external trading workflow with manual trade logging
- Restructure tabs to analysis-focused workflow: * Analysis Hub: AI analysis, risk management, manual trade logger * Daily Prep: Market summary, alerts, checklist, news, trading plan * Journal & Review: Trading journal, habit tracker, advanced analytics * Live Charts: Technical analysis with streaming charts - Add ManualTradeLogger component for logging trades from MT5/TradingView/cTrader - Remove execution-focused components (TradeControls, PortfolioTracker) - Update XAU/USD price to realistic ,084.99 - Add indicator preferences and AI plan service - Add comprehensive documentation on decision coverage and implementation
This commit is contained in:
+78
-2
@@ -1,7 +1,18 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
|
||||
from app.services.openrouter import openrouter_service
|
||||
from app.schemas.schemas import AIAnalysisRequest, AIAnalysisResponse
|
||||
from app.schemas.schemas import (
|
||||
AIAnalysisRequest,
|
||||
AIAnalysisResponse,
|
||||
AIPlanGenerationRequest,
|
||||
AIPlanGenerationResponse,
|
||||
AIPlanFeedback
|
||||
)
|
||||
from app.services.decisions import log_decision
|
||||
from app.services.ai_plan_service import ai_plan_service
|
||||
from app.db.database import get_db
|
||||
|
||||
router = APIRouter(prefix="/ai", tags=["AI Analysis"])
|
||||
|
||||
@@ -41,3 +52,68 @@ async def analyze_scenario(request: AIAnalysisRequest):
|
||||
raise HTTPException(
|
||||
status_code=500, detail=f"AI analysis failed: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@router.post("/generate-plan", response_model=AIPlanGenerationResponse)
|
||||
async def generate_trading_plan(
|
||||
request: AIPlanGenerationRequest,
|
||||
user_id: Optional[str] = None,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""
|
||||
Generate a comprehensive daily trading plan using AI
|
||||
|
||||
Uses user's indicator preferences and market data to create:
|
||||
- Market bias (BULLISH/BEARISH/NEUTRAL)
|
||||
- Entry zones and targets
|
||||
- Support and resistance levels
|
||||
- Risk management parameters
|
||||
- Trading strategy notes
|
||||
"""
|
||||
try:
|
||||
plan = await ai_plan_service.generate_plan(db, request, user_id)
|
||||
return plan
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"AI plan generation failed: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@router.get("/plans/history", response_model=List[AIPlanGenerationResponse])
|
||||
async def get_plan_history(
|
||||
user_id: Optional[str] = None,
|
||||
limit: int = 10,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""Get historical AI-generated trading plans"""
|
||||
try:
|
||||
plans = await ai_plan_service.get_plan_history(db, user_id, limit)
|
||||
return plans
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"Failed to fetch plan history: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@router.post("/plans/feedback")
|
||||
async def submit_plan_feedback(
|
||||
feedback: AIPlanFeedback,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
"""Submit feedback on an AI-generated plan"""
|
||||
try:
|
||||
plan = await ai_plan_service.submit_feedback(
|
||||
db,
|
||||
feedback.plan_id,
|
||||
feedback.accepted,
|
||||
feedback.modified,
|
||||
feedback.feedback
|
||||
)
|
||||
return {"success": True, "message": "Feedback submitted successfully"}
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status_code=500,
|
||||
detail=f"Failed to submit feedback: {str(e)}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user