feat: paginate KIS balance inquiries
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
"""Position reconciliation tests (REQ-031)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from trex_core.application.broker_port import BalanceItem
|
||||
import pytest
|
||||
|
||||
from trex_core.application.broker_port import BalanceItem, BrokerBalanceError
|
||||
from trex_core.application.portfolio import PortfolioItem, SnapshotStore
|
||||
from trex_core.application.reconciliation import reconcile_positions
|
||||
|
||||
@@ -16,6 +18,11 @@ class FakeBroker:
|
||||
def get_balance(self): return list(self._b)
|
||||
|
||||
|
||||
class FailingBroker(FakeBroker):
|
||||
def get_balance(self):
|
||||
raise BrokerBalanceError("malformed_response")
|
||||
|
||||
|
||||
def _store_with(*items):
|
||||
store = SnapshotStore()
|
||||
store.swap(list(items))
|
||||
@@ -47,6 +54,20 @@ def test_subsequent_match_auto_clears_warning():
|
||||
assert store.warnings() == set()
|
||||
|
||||
|
||||
def test_reconcile_positions_accepts_symbol_from_complete_later_page_snapshot():
|
||||
store = _store_with(
|
||||
PortfolioItem(portfolio_id="pf-later", symbol="000660", cash_balance=0, asset_quantity=4),
|
||||
)
|
||||
|
||||
decisions = reconcile_positions(
|
||||
store=store,
|
||||
broker=FakeBroker([BalanceItem("000660", 4)]),
|
||||
)
|
||||
|
||||
assert decisions == {"pf-later": "ok"}
|
||||
assert store.warnings() == set()
|
||||
|
||||
|
||||
def test_multiple_portfolios_same_symbol_aggregate():
|
||||
store = _store_with(
|
||||
PortfolioItem(portfolio_id="pf-A", symbol="005930",
|
||||
@@ -86,3 +107,14 @@ def test_paper_broker_returns_deterministic_balance():
|
||||
syms = {b.symbol for b in broker.get_balance()}
|
||||
assert "000660" not in syms # net 0 → dropped
|
||||
assert "005930" in syms
|
||||
|
||||
|
||||
def test_reconcile_positions_propagates_balance_failure_without_warning_write():
|
||||
store = _store_with(
|
||||
PortfolioItem(portfolio_id="pf-A", symbol="005930", cash_balance=0, asset_quantity=10),
|
||||
)
|
||||
|
||||
with pytest.raises(BrokerBalanceError, match="malformed_response"):
|
||||
reconcile_positions(store=store, broker=FailingBroker([]))
|
||||
|
||||
assert store.warnings() == set()
|
||||
|
||||
Reference in New Issue
Block a user