feat: persist skipped ledger fills
Co-authored-by: genichin <4282227+genichin@users.noreply.github.com>
This commit is contained in:
co-authored by
genichin
parent
df0258bc36
commit
76cde2edd0
@@ -0,0 +1,89 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import UTC, date, datetime
|
||||
from uuid import uuid4
|
||||
|
||||
from trex_core.adapters.persistence.ledger_skip_store import PostgreSQLLedgerSkipStore
|
||||
|
||||
|
||||
def test_ledger_skip_store_round_trips_and_dedupes(pg_clean):
|
||||
store = PostgreSQLLedgerSkipStore(pg_clean)
|
||||
slot_id = uuid4()
|
||||
|
||||
record, notify = store.record_skip(
|
||||
instance_key="inst-1",
|
||||
slot_id=slot_id,
|
||||
portfolio_id="PF-1",
|
||||
symbol="005930",
|
||||
order_id="O-1",
|
||||
execution_id=None,
|
||||
side="buy",
|
||||
qty=10.0,
|
||||
price=1000.0,
|
||||
executed_at=datetime(2026, 8, 24, 0, 0, tzinfo=UTC),
|
||||
order_venue="SOR",
|
||||
execution_venue="unknown",
|
||||
skip_reason="missing_execution_id",
|
||||
)
|
||||
again, notify_again = store.record_skip(
|
||||
instance_key="inst-1",
|
||||
slot_id=slot_id,
|
||||
portfolio_id="PF-1",
|
||||
symbol="005930",
|
||||
order_id="O-1",
|
||||
execution_id=None,
|
||||
side="buy",
|
||||
qty=10.0,
|
||||
price=1000.0,
|
||||
executed_at=datetime(2026, 8, 24, 0, 0, tzinfo=UTC),
|
||||
order_venue="SOR",
|
||||
execution_venue="unknown",
|
||||
skip_reason="missing_execution_id",
|
||||
)
|
||||
|
||||
assert notify is True
|
||||
assert notify_again is False
|
||||
assert again.skip_key == record.skip_key
|
||||
listed = store.list_records(instance_key="inst-1", status="unresolved")
|
||||
assert len(listed) == 1
|
||||
assert listed[0].skip_reason == "missing_execution_id"
|
||||
|
||||
|
||||
def test_ledger_skip_store_filters_and_resolves(pg_clean):
|
||||
store = PostgreSQLLedgerSkipStore(pg_clean)
|
||||
slot_id = uuid4()
|
||||
record, _ = store.record_skip(
|
||||
instance_key="inst-1",
|
||||
slot_id=slot_id,
|
||||
portfolio_id="PF-2",
|
||||
symbol="005930",
|
||||
order_id="O-2",
|
||||
execution_id="E-2",
|
||||
side="sell",
|
||||
qty=5.0,
|
||||
price=2000.0,
|
||||
executed_at=datetime(2026, 8, 24, 2, 0, tzinfo=UTC),
|
||||
order_venue="KRX",
|
||||
execution_venue="NXTX",
|
||||
skip_reason="unsupported_execution_venue",
|
||||
)
|
||||
|
||||
rows = store.list_records(
|
||||
instance_key="inst-1",
|
||||
portfolio_id="PF-2",
|
||||
on_date=date(2026, 8, 24),
|
||||
status="unresolved",
|
||||
)
|
||||
assert [row.skip_key for row in rows] == [record.skip_key]
|
||||
|
||||
resolved = store.resolve_for_fill(
|
||||
instance_key="inst-1",
|
||||
slot_id=slot_id,
|
||||
side="sell",
|
||||
order_id="O-2",
|
||||
execution_id="E-2",
|
||||
resolution_reason="manual_ledger_backfill",
|
||||
)
|
||||
assert len(resolved) == 1
|
||||
assert resolved[0].status == "resolved"
|
||||
assert resolved[0].resolution_reason == "manual_ledger_backfill"
|
||||
@@ -26,6 +26,7 @@ _EXPECTED_TABLES = {
|
||||
"ledger_outbox", # BAT-006 / REQ-019
|
||||
"snapshot_pause", # BAT-008 / REQ-032
|
||||
"broker_account_snapshot", # dcy-041 / GitHub #45
|
||||
"ledger_skip", # GitHub #68 skipped-ledger durable audit
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user