feat: add bounded KIS account read recovery
This commit is contained in:
@@ -8,6 +8,7 @@ from __future__ import annotations
|
||||
from trex_core.adapters.broker.paper import PaperBroker
|
||||
from trex_core.adapters.persistence.in_memory_intent_store import InMemoryIntentStore
|
||||
from trex_core.application.broker_port import (
|
||||
BalanceItem,
|
||||
CancelOutcome,
|
||||
CancelState,
|
||||
FillStatus,
|
||||
@@ -182,6 +183,37 @@ def test_full_sell_qty_is_broker_balance():
|
||||
assert repo.fetch_slot(sid).status is SlotState.INACTIVE # full exit
|
||||
|
||||
|
||||
def test_pending_sell_uses_injected_bounded_balance_reader():
|
||||
class LiveReadFailPaper(PaperBroker):
|
||||
fail_live_balance = False
|
||||
|
||||
def get_balance(self):
|
||||
if self.fail_live_balance:
|
||||
raise AssertionError("raw balance reader must not be called")
|
||||
return super().get_balance()
|
||||
|
||||
broker = LiveReadFailPaper(fill_after_polls=0)
|
||||
repo, svc, intents, execution = _wire(broker)
|
||||
sid = _buy(intents, qty=10).slot_id
|
||||
execution.run_once()
|
||||
svc.sell(sid, actor="t", reason="full")
|
||||
broker.fail_live_balance = True
|
||||
broker._fill_after = 5
|
||||
|
||||
snapshot_execution = ExecutionService(
|
||||
svc,
|
||||
repo,
|
||||
broker,
|
||||
instance_key=INST,
|
||||
balance_reader=lambda: [BalanceItem("005931", 10)],
|
||||
)
|
||||
snapshot_execution.run_once()
|
||||
|
||||
sell_orders = [o for o in broker._orders.values() if o.side == "sell"]
|
||||
assert len(sell_orders) == 1 and sell_orders[0].qty == 10
|
||||
assert repo.fetch_slot(sid).status is SlotState.PENDING_SELL
|
||||
|
||||
|
||||
def test_partial_sell_qty_is_min_intent_broker():
|
||||
"""dcy-021/REQ-062 (D4): partial sell dispatches min(intent qty, broker);
|
||||
remainder stays holding (broker-authoritative qty), cost basis preserved."""
|
||||
|
||||
Reference in New Issue
Block a user