Skip to content

"Vibe-Trading: Your Personal Trading Agent"

Merge pull request #424 from shadowinlife/refactor/api-server-complete-modular

Haozhe Wub37da118fb07
diff --cc agent/api_server.py
index a675908a3,eb6c3fd20..181ab4661
--- a/agent/api_server.py
+++ b/agent/api_server.py
@@@ -926,18 -220,10 +220,12 @@@ from src.api.uploads_routes import (
_UPLOAD_CHUNK_SIZE,
)
-
- # ============================================================================
- # Channel routes registration - after require_auth is defined
- # ============================================================================
-
+ # --- Channels ---
from src.api.channels_routes import register_channels_routes # noqa: E402
-
register_channels_routes(app)
+from src.api.qveris_routes import qveris_router # noqa: E402 # QVERIS-INTEGRATION
+app.include_router(qveris_router) # QVERIS-INTEGRATION
- # Re-export for test monkeypatch compatibility
from src.api.channels_routes import ( # noqa: F401, E402
ChannelPairingCommandRequest,
)
@@@ -997,20 -267,14 +269,18 @@@ from src.api.live_routes import ( # no
from src.api.alpha_routes import register_alpha_routes # noqa: E402
register_alpha_routes(app)
-# --- Research Card ---
-from src.research_card.api import register_research_card_routes # noqa: E402
-register_research_card_routes(app)
-# --- Scheduled Research ---
+# ============================================================================
+# Scheduled Research Routes - defined in src/api/scheduled_routes.py
+# ============================================================================
+#
+# Lightweight CRUD endpoints backed by ScheduledResearchJobStore. The endpoint
+# handlers only record and expose jobs; the optional executor lifecycle is
+# guarded separately by VIBE_TRADING_ENABLE_SCHEDULER.
+
from src.api.scheduled_routes import register_scheduled_routes # noqa: E402
-
register_scheduled_routes(app)
- # Re-exported for backward-compatibility / external consumers
from src.api.scheduled_routes import ( # noqa: E402, F401
CreateScheduledRunRequest,
ScheduledRunResponse,
diff --cc agent/src/api/models.py
index 000000000,5ced0ef8c..81595a17a
mode 000000,100644..100644
--- a/agent/src/api/models.py
+++ b/agent/src/api/models.py
@@@ -1,0 -1,91 +1,90 @@@
+ """Pydantic response models shared across API route modules."""
+
+ from __future__ import annotations
+
+ from typing import Any, Dict, List, Optional
+
+ from pydantic import BaseModel, Field
+
+
+ class Artifact(BaseModel):
+ """Artifact file metadata."""
+
+ name: str = Field(..., description="File name")
+ path: str = Field(..., description="File path")
+ type: str = Field(..., description="File type: csv, json, txt, etc.")
+ size: int = Field(..., description="Size in bytes")
+ exists: bool = Field(..., description="Whether the file exists")
+
+
+ class BacktestMetrics(BaseModel):
+ """Backtest summary metrics."""
+
+ model_config = {"extra": "allow"}
+
+ final_value: float = Field(..., description="Ending portfolio value")
+ total_return: float = Field(..., description="Total return")
+ annual_return: float = Field(..., description="Annualized return")
+ max_drawdown: float = Field(..., description="Max drawdown")
+ sharpe: float = Field(..., description="Sharpe ratio")
+ win_rate: float = Field(..., description="Win rate")
+ trade_count: int = Field(..., description="Number of trades")
+
+
+ class RAGSelection(BaseModel):
+ """RAG routing result."""
+
+ selected_api: str = Field(..., description="Selected API code")
+ selected_name: str = Field(..., description="Selected API name")
+ selected_score: float = Field(..., description="Match score")
+
+
+ class RunInfo(BaseModel):
+ """Compact run row for list views."""
+
+ run_id: str
+ status: str
+ created_at: str
+ prompt: Optional[str] = None
+ total_return: Optional[float] = None
+ sharpe: Optional[float] = None
+ codes: List[str] = Field(default_factory=list)
+ start_date: Optional[str] = None
+ end_date: Optional[str] = None
+
+
+ class RunResponse(BaseModel):
+ """API response payload for a single run."""
+
+ status: str = Field(..., description="Run status: success, failed, aborted")
+ run_id: str = Field(..., description="Run identifier")
+ elapsed_seconds: float = Field(..., description="Execution time in seconds")
+ reason: Optional[str] = Field(None, description="Failure reason when available")
+
+ planner_output: Optional[Dict[str, Any]] = Field(None, description="Planner output")
+ strategy_spec: Optional[Dict[str, Any]] = Field(None, description="Strategy specification")
+ rag_selection: Optional[RAGSelection] = Field(None, description="Selected RAG metadata")
+
+ metrics: Optional[BacktestMetrics] = Field(None, description="Backtest metrics")
+ artifacts: List[Artifact] = Field(default_factory=list, description="Run artifacts")
+ run_card: Optional[Dict[str, Any]] = Field(None, description="Trust Layer run card payload")
- research_card: Optional[Dict[str, Any]] = Field(None, description="IRR-AGL research card payload")
+ llm_usage: Optional[Dict[str, Any]] = Field(None, description="Provider-reported AgentLoop usage summary")
+
+ equity_curve: Optional[List[Dict[str, Any]]] = Field(None, description="Equity preview")
+ trade_log: Optional[List[Dict[str, Any]]] = Field(None, description="Trade preview")
+
+ artifacts_equity_csv: Optional[List[Dict[str, Any]]] = Field(None, description="Full equity rows")
+ artifacts_metrics_csv: Optional[List[Dict[str, Any]]] = Field(None, description="Full metrics rows")
+ artifacts_trades_csv: Optional[List[Dict[str, Any]]] = Field(None, description="Full trade rows")
+ validation: Optional[Dict[str, Any]] = Field(None, description="Statistical validation results")
+
+ run_directory: str = Field(..., description="Run directory path")
+ run_stage: Optional[str] = Field(None, description="UI-facing run stage")
+ run_context: Optional[Dict[str, Any]] = Field(None, description="Normalized request context")
+ price_series: Optional[Dict[str, List[Dict[str, Any]]]] = Field(None, description="Grouped OHLC series")
+ indicator_series: Optional[Dict[str, Dict[str, List[Dict[str, Any]]]]] = Field(
+ None,
+ description="Grouped indicator overlays",
+ )
+ trade_markers: Optional[List[Dict[str, Any]]] = Field(None, description="Trade markers for charts")
+ run_logs: Optional[List[Dict[str, Any]]] = Field(None, description="Structured stdout/stderr lines")