fix: trading status and metrics endpoints now read real portfolio state instead of hardcoded zeros
This commit is contained in:
+19
-9
@@ -192,15 +192,21 @@ async def trading_status() -> dict[str, Any]:
|
|||||||
if engine is None:
|
if engine is None:
|
||||||
raise HTTPException(503, "Engine not initialised")
|
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 {
|
return {
|
||||||
"enabled": engine.config.enabled,
|
"enabled": engine.config.enabled,
|
||||||
"paused": not engine.running,
|
"paused": not engine.running,
|
||||||
"risk_tier": engine.config.risk_tier,
|
"risk_tier": engine.config.risk_tier,
|
||||||
"circuit_breaker_status": "inactive",
|
"circuit_breaker_status": "inactive",
|
||||||
"active_pool": 0.0,
|
"active_pool": active_pool,
|
||||||
"reserve_pool": 0.0,
|
"reserve_pool": reserve_pool,
|
||||||
"portfolio_heat": 0.0,
|
"portfolio_heat": portfolio_heat,
|
||||||
"open_positions": 0,
|
"open_positions": open_positions,
|
||||||
"last_decision_at": None,
|
"last_decision_at": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -272,11 +278,15 @@ async def list_decisions(
|
|||||||
|
|
||||||
@app.get("/api/trading/metrics")
|
@app.get("/api/trading/metrics")
|
||||||
async def current_metrics() -> dict[str, Any]:
|
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 {
|
return {
|
||||||
"total_portfolio_value": 0.0,
|
"total_portfolio_value": ps.total_value if ps else 0.0,
|
||||||
"active_pool": 0.0,
|
"active_pool": ps.active_pool if ps else 0.0,
|
||||||
"reserve_pool": 0.0,
|
"reserve_pool": ps.reserve_pool if ps else 0.0,
|
||||||
"unrealized_pnl": 0.0,
|
"unrealized_pnl": 0.0,
|
||||||
"realized_pnl": 0.0,
|
"realized_pnl": 0.0,
|
||||||
"daily_pnl": 0.0,
|
"daily_pnl": 0.0,
|
||||||
@@ -284,7 +294,7 @@ async def current_metrics() -> dict[str, Any]:
|
|||||||
"profit_factor": 0.0,
|
"profit_factor": 0.0,
|
||||||
"sharpe_ratio": 0.0,
|
"sharpe_ratio": 0.0,
|
||||||
"max_drawdown": 0.0,
|
"max_drawdown": 0.0,
|
||||||
"portfolio_heat": 0.0,
|
"portfolio_heat": ps.portfolio_heat if ps else 0.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user