fix: trading status and metrics endpoints now read real portfolio state instead of hardcoded zeros

This commit is contained in:
Celes Renata
2026-04-16 14:02:38 +00:00
parent 5cc64498c0
commit 14e411daf9
+19 -9
View File
@@ -192,15 +192,21 @@ async def trading_status() -> dict[str, Any]:
if engine is None:
raise HTTPException(503, "Engine not initialised")
ps = engine.portfolio_state
active_pool = ps.active_pool if ps else 0.0
reserve_pool = ps.reserve_pool if ps else 0.0
portfolio_heat = ps.portfolio_heat if ps else 0.0
open_positions = ps.open_position_count if ps else 0
return {
"enabled": engine.config.enabled,
"paused": not engine.running,
"risk_tier": engine.config.risk_tier,
"circuit_breaker_status": "inactive",
"active_pool": 0.0,
"reserve_pool": 0.0,
"portfolio_heat": 0.0,
"open_positions": 0,
"active_pool": active_pool,
"reserve_pool": reserve_pool,
"portfolio_heat": portfolio_heat,
"open_positions": open_positions,
"last_decision_at": None,
}
@@ -272,11 +278,15 @@ async def list_decisions(
@app.get("/api/trading/metrics")
async def current_metrics() -> dict[str, Any]:
"""Return current performance metrics (placeholder)."""
"""Return current performance metrics."""
if engine is None:
raise HTTPException(503, "Engine not initialised")
ps = engine.portfolio_state
return {
"total_portfolio_value": 0.0,
"active_pool": 0.0,
"reserve_pool": 0.0,
"total_portfolio_value": ps.total_value if ps else 0.0,
"active_pool": ps.active_pool if ps else 0.0,
"reserve_pool": ps.reserve_pool if ps else 0.0,
"unrealized_pnl": 0.0,
"realized_pnl": 0.0,
"daily_pnl": 0.0,
@@ -284,7 +294,7 @@ async def current_metrics() -> dict[str, Any]:
"profit_factor": 0.0,
"sharpe_ratio": 0.0,
"max_drawdown": 0.0,
"portfolio_heat": 0.0,
"portfolio_heat": ps.portfolio_heat if ps else 0.0,
}