feat: paginate KIS balance inquiries

This commit is contained in:
Hermes Agent
2026-08-10 00:11:04 +09:00
parent 701fb06362
commit 0fa8f39be9
6 changed files with 297 additions and 37 deletions
+38 -1
View File
@@ -3,7 +3,9 @@ from __future__ import annotations
from dataclasses import replace
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 InMemoryReconcileWarningStore
from trex_core.application.reconciliation import reconcile_core_holdings
from trex_core.domain.slot import SlotService, SlotState
@@ -24,6 +26,11 @@ class FakeBroker:
return list(self._b)
class FailingBroker(FakeBroker):
def get_balance(self):
raise BrokerBalanceError("malformed_response")
def _hold(repo, svc, pid, symbol, qty):
repo.reconcile_universe(INST, {pid: "SYM"})
slot = repo.find_slot_by_portfolio(INST, pid)
@@ -77,6 +84,21 @@ def test_ok_when_qty_matches():
assert d[str(slot.slot_id)] == "ok"
def test_later_page_snapshot_symbol_keeps_holding_slot_ok():
repo, svc = _wire()
slot = _hold(repo, svc, "pf-later", "000660", 4)
decisions = reconcile_core_holdings(
slot_repo=repo,
slot_service=svc,
broker=FakeBroker([BalanceItem(symbol="000660", hldg_qty=4)]),
instance_key=INST,
)
assert decisions == {str(slot.slot_id): "ok"}
assert repo.fetch_slot(slot.slot_id).status is SlotState.HOLDING
def test_B_broker_holds_unmanaged_warns():
repo, svc = _wire()
broker = FakeBroker([BalanceItem(symbol="000660", hldg_qty=5)]) # core has none
@@ -149,3 +171,18 @@ def test_other_instance_only_managed_slot_remains_unmanaged_position_without_wri
assert repo.update_calls == writes_before
assert warn_store.list_warned() == set()
assert repo.list_slots(INST) == []
def test_reconcile_core_holdings_propagates_balance_failure_without_slot_write():
repo, svc = _wire()
slot = _hold(repo, svc, "pf-a", "005930", 10)
with pytest.raises(BrokerBalanceError, match="malformed_response"):
reconcile_core_holdings(
slot_repo=repo,
slot_service=svc,
broker=FailingBroker([]),
instance_key=INST,
)
assert repo.fetch_slot(slot.slot_id).status is SlotState.HOLDING