feat: add bounded KIS account read recovery
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from decimal import Decimal
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -14,6 +15,10 @@ from trex_core.application.broker_port import (
|
||||
FillStatus,
|
||||
OrderAck,
|
||||
)
|
||||
from trex_core.application.account_snapshot import (
|
||||
AccountSnapshotService,
|
||||
InMemoryAccountSnapshotStore,
|
||||
)
|
||||
|
||||
|
||||
class FakeBroker:
|
||||
@@ -36,6 +41,12 @@ class FakeBroker:
|
||||
def get_balance(self):
|
||||
return self.balance
|
||||
|
||||
def account_scope_hash(self):
|
||||
return "c" * 64
|
||||
|
||||
def get_available_cash(self, *, price_check_code="005930"):
|
||||
return 1_000_000
|
||||
|
||||
def get_current_price(self, symbol, market="J"):
|
||||
return Decimal("1")
|
||||
|
||||
@@ -90,3 +101,28 @@ def test_sell_cannot_reduce_below_strategy_owned_zero(tmp_path):
|
||||
side="sell",
|
||||
quantity=1,
|
||||
)
|
||||
|
||||
|
||||
def test_account_snapshot_keeps_manual_holdings_outside_strategy_scope(tmp_path):
|
||||
ownership = StrategyOwnershipStore(tmp_path / "ownership.json")
|
||||
ownership.apply_fill(
|
||||
execution_id="buy-1",
|
||||
symbol="005930",
|
||||
side="buy",
|
||||
quantity=2,
|
||||
)
|
||||
broker = OwnershipAwareBroker(
|
||||
FakeBroker([BalanceItem("005930", 21), BalanceItem("000660", 1)]),
|
||||
ownership,
|
||||
)
|
||||
snapshots = InMemoryAccountSnapshotStore()
|
||||
service = AccountSnapshotService(
|
||||
broker=broker,
|
||||
store=snapshots,
|
||||
clock=lambda: datetime(2026, 7, 29, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
assert service.refresh()
|
||||
snapshot = snapshots.load("c" * 64)
|
||||
assert snapshot is not None
|
||||
assert snapshot.holdings == (BalanceItem("005930", 2),)
|
||||
|
||||
Reference in New Issue
Block a user