feat: use broker-authoritative qty in slots RPC holdings
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
832dcb5fbb
commit
30bcbe1d12
@@ -1,7 +1,7 @@
|
||||
"""Bounded account-read recovery (dcy-041 / GitHub #45)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -37,7 +37,7 @@ class FakeAccountBroker:
|
||||
|
||||
|
||||
def _wire():
|
||||
now = [datetime(2026, 7, 29, tzinfo=timezone.utc)]
|
||||
now = [datetime(2026, 7, 29, tzinfo=UTC)]
|
||||
broker = FakeAccountBroker()
|
||||
store = InMemoryAccountSnapshotStore()
|
||||
service = AccountSnapshotService(
|
||||
@@ -162,3 +162,18 @@ def test_invalid_or_missing_buy_notional_fails_closed():
|
||||
assert service.buy_guard(qty=1, limit_price=None) == (
|
||||
"account_snapshot_price_required"
|
||||
)
|
||||
|
||||
|
||||
def test_slots_rpc_uses_snapshot_only_with_sell_ttl_freshness():
|
||||
broker, _, service, now = _wire()
|
||||
assert service.refresh()
|
||||
broker.balance = [BalanceItem("005930", 999)]
|
||||
|
||||
holdings, captured_at = service.holdings_for_slots_rpc()
|
||||
assert holdings == [BalanceItem("005930", 2)]
|
||||
assert captured_at == now[0]
|
||||
|
||||
now[0] += timedelta(seconds=3601)
|
||||
with pytest.raises(AccountSnapshotUnavailable) as raised:
|
||||
service.holdings_for_slots_rpc()
|
||||
assert raised.value.code == "expired"
|
||||
|
||||
Reference in New Issue
Block a user