32 lines
1013 B
Python
32 lines
1013 B
Python
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter
|
|
from datetime import datetime, timezone
|
|
|
|
from app.config import settings
|
|
from app.api.trading import simulation_state
|
|
from app.streaming.binance_hub import hub as binance_hub
|
|
from app.streaming.alpha_hub import alpha_hub
|
|
|
|
router = APIRouter(prefix="/status", tags=["Status"])
|
|
|
|
|
|
@router.get("")
|
|
async def get_status():
|
|
pos = simulation_state.get("position")
|
|
eq = float(simulation_state.get("cash", 0.0)) + (
|
|
float(pos["quantity"]) * float(pos["avg_price"]) if pos else 0.0
|
|
)
|
|
return {
|
|
"time": datetime.now(timezone.utc).isoformat(),
|
|
"app": {"name": settings.APP_NAME, "version": settings.APP_VERSION},
|
|
"simulation": {
|
|
"cash": float(simulation_state.get("cash", 0.0)),
|
|
"equity_est": eq,
|
|
"open_position": bool(pos),
|
|
},
|
|
"streams": {
|
|
"binance": binance_hub.get_status(),
|
|
"alpha_vantage": alpha_hub.get_status(),
|
|
},
|
|
} |