Files
ai-exchange/scripts/run_trading_runtime.py
2026-05-12 08:54:45 +08:00

43 lines
1.4 KiB
Python

from __future__ import annotations
from pathlib import Path
import json
import os
import sys
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
sys.path.insert(0, str(ROOT))
from src.services.runtime import get_trading_runtime_service
def main(env=None) -> int:
env = os.environ if env is None else env
output_json = _get_bool(env, "TRADING_RUNTIME_OUTPUT_JSON", False)
run_once = _get_bool(env, "TRADING_RUNTIME_RUN_ONCE", True)
service = get_trading_runtime_service()
payload = service.run_once() if run_once else service.status()
if output_json:
print(json.dumps(payload, ensure_ascii=False, sort_keys=True))
else:
incident_summary = dict(payload.get("incident_summary") or {})
print(f"Trading runtime: {payload.get('scheduler_state')} / {payload.get('supervisor_state', 'stopped')}")
print(f"Blockers: {', '.join(payload.get('current_blockers') or []) or 'none'}")
print(
"Incident journal: "
f"{incident_summary.get('status', 'idle')} / {incident_summary.get('incident_count', 0)}"
)
return 0 if not payload.get("current_blockers") else 2
def _get_bool(env, key: str, default: bool) -> bool:
value = env.get(key)
if value is None or value == "":
return default
return str(value).strip().lower() in {"1", "true", "yes", "on"}
if __name__ == "__main__":
raise SystemExit(main())