Expand description
Settlement persistence operations.
Free functions that take &mut PgConnection so they can be called
from any context (DatabaseHandler trait impl, transaction closures, tests).
Previously lived as private methods on DieselEventHandler.
Functionsยง
- claim_
settlement_ in_ tx - Idempotent settlement claim: inserts expiration + payout + ledger event in one transaction. Panics on invariant violations (data corruption). Returns whether this was a new claim or a duplicate replay.
- extract_
expiry_ ts - Parse a symbol string and extract its expiry timestamp.
- insert_
settlement_ ๐ledger_ event_ in_ tx - insert_
settlement_ ๐payout_ in_ tx - load_
settlement_ ๐payout_ in_ tx - lock_
and_ ๐validate_ existing_ settlement_ claim_ in_ tx - mark_
settlement_ ๐payout_ applied_ in_ tx - observe_
applied_ settlement_ in_ tx - Read-only validation of an already-applied settlement (standby replay path). Panics on any inconsistency between the replay and the persisted state.
- query_
total_ fill_ volume - Total fill count and notional volume across all fills.
- settlement_
ledger_ delta_ for_ margin_ mode - Compute the ledger cash delta for a settlement based on margin mode. Standard mode uses settlement_value; portfolio mode uses net_pnl.
- validate_
existing_ ๐settlement_ claim_ readonly - validate_
existing_ ๐settlement_ ledger_ in_ tx - validate_
existing_ ๐settlement_ ledger_ readonly - validate_
existing_ ๐settlement_ payout_ facts - validate_
settlement_ economics_ tuple - Validate settlement economics (entry price, cost basis, net PnL) and return as a tuple.
- validate_
settlement_ ๐ledger_ deltas