feat: add portfolio snapshot read layer

This commit is contained in:
2026-06-06 09:33:00 +09:00
parent 56e977a7ad
commit ca757009f5
51 changed files with 3565 additions and 51 deletions
+17
View File
@@ -11,6 +11,7 @@ import threading
from typing import Optional
from trex_core.application.broker_port import (
BalanceItem,
FillStatus,
OrderAck,
OrderRequest,
@@ -94,3 +95,19 @@ class PaperBroker:
return False
o.cancelled = True
return True
def get_balance(self) -> list[BalanceItem]:
"""Deterministic per-symbol fill aggregate (REQ-031 AC-3).
Aggregates buys − sells across all filled (or partially filled)
paper orders, drops zero-qty rows (Design Decision 7).
"""
with self._lock:
balances: dict[str, int] = {}
for o in self._orders.values():
if o.filled <= 0:
continue
sign = 1 if o.side == "buy" else -1
balances[o.symbol] = balances.get(o.symbol, 0) + sign * int(o.filled)
return [BalanceItem(symbol=sym, hldg_qty=qty)
for sym, qty in balances.items() if qty != 0]