feat: paginate KIS balance inquiries
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user