fix: add logging config to trading engine, add /api/trading/debug diagnostic endpoint
This commit is contained in:
@@ -27,6 +27,12 @@ from services.trading.engine import TradingEngine
|
||||
|
||||
logger = logging.getLogger("trading_engine")
|
||||
|
||||
# Configure logging so we can actually see what's happening
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
|
||||
)
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Module-level state
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -188,6 +194,38 @@ async def ready() -> dict[str, bool]:
|
||||
return {"ready": is_ready}
|
||||
|
||||
|
||||
@app.get("/api/trading/debug")
|
||||
async def debug_state() -> dict[str, Any]:
|
||||
"""Diagnostic endpoint — shows engine internals for troubleshooting."""
|
||||
if engine is None:
|
||||
return {"engine": None, "reason": "engine not initialised"}
|
||||
|
||||
ps = engine.portfolio_state
|
||||
task_states = {}
|
||||
for t in engine._tasks:
|
||||
task_states[t.get_name()] = "done" if t.done() else "running"
|
||||
if t.done() and t.exception():
|
||||
task_states[t.get_name()] = f"failed: {t.exception()}"
|
||||
|
||||
return {
|
||||
"running": engine.running,
|
||||
"has_pool": engine.pool is not None,
|
||||
"has_redis": engine.redis is not None,
|
||||
"config_enabled": engine.config.enabled,
|
||||
"polling_interval": engine.config.polling_interval_seconds,
|
||||
"last_poll": str(engine._last_poll_timestamp),
|
||||
"portfolio_state": {
|
||||
"active_pool": ps.active_pool if ps else 0,
|
||||
"reserve_pool": ps.reserve_pool if ps else 0,
|
||||
"total_value": ps.total_value if ps else 0,
|
||||
"open_positions": ps.open_position_count if ps else 0,
|
||||
},
|
||||
"risk_tier": engine._active_risk_tier.name if engine._active_risk_tier else "none",
|
||||
"tasks": task_states,
|
||||
"processed_rec_count": len(engine.processed_recommendation_ids),
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Engine Status & Control
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user