22 lines
819 B
Python
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()
|