Files
ai-exchange/src/api/broker_state.py
T
2026-05-08 08:09:00 +08:00

22 lines
819 B
Python

from src.services.broker import BrokerReadModelService
from src.services.execution import ExecutionService
def get_broker_state(instrument_id: int) -> dict:
execution_service = ExecutionService()
refs = execution_service.build_execution_dashboard_items(instrument_id=instrument_id, limit=100)
known_order_ids = []
open_execution_count = 0
for item in refs:
if item.get("execution_status") == "open":
open_execution_count += 1
known_order_ids.extend(list(item.get("broker_order_ids") or []))
snapshot = BrokerReadModelService().fetch_snapshot(
instrument_id=instrument_id,
known_execution_refs={
"broker_order_ids": known_order_ids,
"open_execution_count": open_execution_count,
},
)
return snapshot.to_dict()