38 lines
846 B
Python
38 lines
846 B
Python
from fastapi import APIRouter
|
|
from fastapi.responses import JSONResponse
|
|
|
|
import dependencies
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/health")
|
|
async def health():
|
|
ib_connected = False
|
|
account = None
|
|
try:
|
|
ib_inst = dependencies.get_ib()
|
|
ib_connected = ib_inst.isConnected()
|
|
accounts = ib_inst.managedAccounts()
|
|
account = accounts[0] if accounts else None
|
|
except Exception:
|
|
pass
|
|
|
|
db_ok = False
|
|
try:
|
|
cur = dependencies.get_db_cursor()
|
|
cur.execute("SELECT 1")
|
|
db_ok = True
|
|
except Exception:
|
|
pass
|
|
|
|
return JSONResponse(
|
|
{
|
|
"status": "ok" if (ib_connected and db_ok) else "degraded",
|
|
"ib_connected": ib_connected,
|
|
"account": account,
|
|
"db_ok": db_ok,
|
|
"version": "3.0",
|
|
}
|
|
)
|