pub trait Ledger: Send + Sync {
// Required methods
fn get_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
) -> Pin<Box<dyn Future<Output = Result<Decimal, LedgerError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn apply_pnl<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
realized_pnl: Decimal,
) -> Pin<Box<dyn Future<Output = Result<(), LedgerError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn set_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
balance: Decimal,
) -> Pin<Box<dyn Future<Output = Result<(), LedgerError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided method
fn apply_premium<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
premium_delta: Decimal,
) -> Pin<Box<dyn Future<Output = Result<(), LedgerError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
Durable account balance persistence interface.
The engine-owned BalanceLedger is authoritative for runtime reads. This
trait exists for DB persistence adapters and tests that exercise durable
account balance writes:
- Position closes (realized PnL)
- Explicit deposits/withdrawals
- Premium settlement for Standard margin mode
Opening positions does NOT touch the ledger in Portfolio mode.
Required Methods§
Sourcefn get_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
) -> Pin<Box<dyn Future<Output = Result<Decimal, LedgerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
) -> Pin<Box<dyn Future<Output = Result<Decimal, LedgerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Get the current collateral balance for an account.
Returns 0 if the account doesn’t exist (lazy account creation).
Sourcefn apply_pnl<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
realized_pnl: Decimal,
) -> Pin<Box<dyn Future<Output = Result<(), LedgerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn apply_pnl<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
realized_pnl: Decimal,
) -> Pin<Box<dyn Future<Output = Result<(), LedgerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Apply realized PnL to an account’s collateral balance.
This is called when positions are closed:
- Positive realized_pnl: balance increases (profitable close)
- Negative realized_pnl: balance decreases (losing close)
Creates the account if it doesn’t exist.
Sourcefn set_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
balance: Decimal,
) -> Pin<Box<dyn Future<Output = Result<(), LedgerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn set_balance<'life0, 'life1, 'async_trait>(
&'life0 self,
wallet: &'life1 WalletAddress,
balance: Decimal,
) -> Pin<Box<dyn Future<Output = Result<(), LedgerError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Set the balance directly (for deposits, withdrawals, and tests).
Creates the account if it doesn’t exist.
Provided Methods§
Apply option premium settlement to an account’s balance.
This is called for Standard margin mode accounts on option fills:
- Negative premium_delta: balance decreases (buying options)
- Positive premium_delta: balance increases (selling options)
Creates the account if it doesn’t exist.
Note: For Portfolio margin mode, this is NOT called - premium is financed via margin instead of directly debiting the balance.