test: cover KIS pagination consumer seams
This commit is contained in:
@@ -92,7 +92,24 @@ def test_strategy_quantity_above_raw_broker_total_fails_closed(tmp_path):
|
||||
assert exc.value.code == "ownership_mismatch"
|
||||
|
||||
|
||||
def test_projection_includes_strategy_symbol_alongside_first_page_manual_holding(tmp_path):
|
||||
def _paged_kis_for_ownership(kis_balance_broker_factory, strategy_qty):
|
||||
return kis_balance_broker_factory([
|
||||
{
|
||||
"rows": [{"pdno": "005930", "hldg_qty": "19"}],
|
||||
"tr_cont": "F",
|
||||
"fk": "A",
|
||||
"nk": "1",
|
||||
},
|
||||
{
|
||||
"rows": [{"pdno": "000660", "hldg_qty": str(strategy_qty)}],
|
||||
"tr_cont": "E",
|
||||
},
|
||||
])
|
||||
|
||||
|
||||
def test_projection_includes_strategy_symbol_from_actual_later_kis_page(
|
||||
tmp_path, kis_balance_broker_factory
|
||||
):
|
||||
store = StrategyOwnershipStore(tmp_path / "ownership.json")
|
||||
store.apply_fill(
|
||||
execution_id="buy-1",
|
||||
@@ -100,12 +117,32 @@ def test_projection_includes_strategy_symbol_alongside_first_page_manual_holding
|
||||
side="buy",
|
||||
quantity=4,
|
||||
)
|
||||
broker = OwnershipAwareBroker(
|
||||
FakeBroker([BalanceItem("005930", 19), BalanceItem("000660", 4)]),
|
||||
store,
|
||||
)
|
||||
delegate, calls = _paged_kis_for_ownership(kis_balance_broker_factory, 4)
|
||||
broker = OwnershipAwareBroker(delegate, store)
|
||||
|
||||
assert broker.get_balance() == [BalanceItem("000660", 4)]
|
||||
assert len(calls) == 2
|
||||
assert "tr_cont" not in calls[0]["headers"]
|
||||
assert calls[1]["headers"]["tr_cont"] == "N"
|
||||
|
||||
|
||||
def test_projection_detects_mismatch_from_actual_later_kis_page(
|
||||
tmp_path, kis_balance_broker_factory
|
||||
):
|
||||
store = StrategyOwnershipStore(tmp_path / "ownership.json")
|
||||
store.apply_fill(
|
||||
execution_id="buy-1",
|
||||
symbol="000660",
|
||||
side="buy",
|
||||
quantity=4,
|
||||
)
|
||||
delegate, calls = _paged_kis_for_ownership(kis_balance_broker_factory, 3)
|
||||
broker = OwnershipAwareBroker(delegate, store)
|
||||
|
||||
with pytest.raises(BrokerBalanceError) as exc:
|
||||
broker.get_balance()
|
||||
assert exc.value.code == "ownership_mismatch"
|
||||
assert len(calls) == 2
|
||||
|
||||
|
||||
def test_sell_cannot_reduce_below_strategy_owned_zero(tmp_path):
|
||||
|
||||
Reference in New Issue
Block a user