pub struct WalletAccount {
pub base: BaseAccount,
pub balances_locked: AHashMap<(InstrumentId, Currency), Money>,
}Fields§
§base: BaseAccount§balances_locked: AHashMap<(InstrumentId, Currency), Money>Per-(instrument, currency) locked balances (transient, not persisted).
Implementations§
Source§impl WalletAccount
impl WalletAccount
Sourcepub fn new_checked(
event: AccountState,
calculate_account_state: bool,
) -> CorrectnessResult<Self>
pub fn new_checked( event: AccountState, calculate_account_state: bool, ) -> CorrectnessResult<Self>
Creates a new WalletAccount instance.
§Errors
Returns an error if the initial event is not a valid wallet account state.
Sourcepub fn new(event: AccountState, calculate_account_state: bool) -> Self
pub fn new(event: AccountState, calculate_account_state: bool) -> Self
Creates a new WalletAccount instance.
§Panics
Panics if the initial event is not a valid wallet account state.
Sourcepub fn update_balance_locked(
&mut self,
instrument_id: InstrumentId,
locked: Money,
) -> Result<()>
pub fn update_balance_locked( &mut self, instrument_id: InstrumentId, locked: Money, ) -> Result<()>
Updates the locked balance for the given instrument and currency.
§Errors
Returns an error if locked is negative, the wallet has no observed balance for its
currency, or the local reservations cannot produce a valid balance.
Sourcepub fn clear_balance_locked(&mut self, instrument_id: InstrumentId)
pub fn clear_balance_locked(&mut self, instrument_id: InstrumentId)
Clears all locked balances for the given instrument ID.
Sourcepub fn update_balances(&mut self, balances: &[AccountBalance]) -> Result<()>
pub fn update_balances(&mut self, balances: &[AccountBalance]) -> Result<()>
Updates the account balances, rejecting negative totals.
A wallet balance is an observed on-chain amount and cannot become negative.
§Errors
Returns an error if any balance has a negative total, currencies are duplicated, or the local reservations cannot produce valid balances.
pub const fn is_unleveraged(&self) -> bool
Sourcepub fn recalculate_balance(&mut self, currency: Currency)
pub fn recalculate_balance(&mut self, currency: Currency)
Recalculates the account balance for the specified currency based on per-instrument locks.
Sums all per-instrument locked amounts for the currency and updates the balance. If the total locked exceeds the total balance, clamps to total (free = 0).
Source§impl WalletAccount
impl WalletAccount
Sourcepub fn py_new(
event: AccountState,
calculate_account_state: bool,
) -> PyResult<Self>
pub fn py_new( event: AccountState, calculate_account_state: bool, ) -> PyResult<Self>
Creates a new WalletAccount instance.
Methods from Deref<Target = BaseAccount>§
Sourcepub fn base_balance(
&self,
currency: Option<Currency>,
) -> Option<&AccountBalance>
pub fn base_balance( &self, currency: Option<Currency>, ) -> Option<&AccountBalance>
Returns a reference to the AccountBalance for the specified currency, or None if absent.
§Panics
Panics if currency is None and self.base_currency is None.
Sourcepub fn base_balance_total(&self, currency: Option<Currency>) -> Option<Money>
pub fn base_balance_total(&self, currency: Option<Currency>) -> Option<Money>
Returns the total Money balance for the specified currency, or None if absent.
§Panics
Panics if currency is None and self.base_currency is None.
pub fn base_balances_total(&self) -> IndexMap<Currency, Money>
Sourcepub fn base_balance_free(&self, currency: Option<Currency>) -> Option<Money>
pub fn base_balance_free(&self, currency: Option<Currency>) -> Option<Money>
Returns the free Money balance for the specified currency, or None if absent.
§Panics
Panics if currency is None and self.base_currency is None.
pub fn base_balances_free(&self) -> IndexMap<Currency, Money>
Sourcepub fn base_balance_locked(&self, currency: Option<Currency>) -> Option<Money>
pub fn base_balance_locked(&self, currency: Option<Currency>) -> Option<Money>
Returns the locked Money balance for the specified currency, or None if absent.
§Panics
Panics if currency is None and self.base_currency is None.
pub fn base_balances_locked(&self) -> IndexMap<Currency, Money>
pub fn base_last_event(&self) -> Option<AccountState>
Sourcepub fn update_balances(&mut self, balances: &[AccountBalance])
pub fn update_balances(&mut self, balances: &[AccountBalance])
Updates the account balances with the provided list of AccountBalance instances.
Note: This method does NOT validate negative balances. Derived account types
(CashAccount, MarginAccount) should perform their own validation in apply():
MarginAccount: allows negative balances (normal for margin trading)CashAccount: rejects negative unlessallow_borrowingis true
Sourcepub fn update_commissions(&mut self, commission: Money)
pub fn update_commissions(&mut self, commission: Money)
Updates the account commissions with the provided amount.
§Panics
Panics if the accumulated commission exceeds Money bounds. Operational callers should
use Self::try_update_commissions when the input is not already known to fit.
Sourcepub fn try_update_commissions(&mut self, commission: Money) -> Result<()>
pub fn try_update_commissions(&mut self, commission: Money) -> Result<()>
Sourcepub fn commission(&self, currency: &Currency) -> Option<Money>
pub fn commission(&self, currency: &Currency) -> Option<Money>
Returns the total commission for the specified currency.
Sourcepub fn commissions(&self) -> AHashMap<Currency, Money>
pub fn commissions(&self) -> AHashMap<Currency, Money>
Returns a map of all commissions by currency.
Sourcepub fn base_apply(&mut self, event: AccountState)
pub fn base_apply(&mut self, event: AccountState)
Applies an AccountState event, updating balances.
§Panics
Panics if event.account_id does not match this account’s ID.
Sourcepub fn base_purge_account_events(
&mut self,
ts_now: UnixNanos,
lookback_secs: u64,
)
pub fn base_purge_account_events( &mut self, ts_now: UnixNanos, lookback_secs: u64, )
Purges all account state events which are outside the lookback window.
Guaranteed to retain at least the latest event.
§Panics
Panics if the purging implementation is changed and all events are purged.
Sourcepub fn base_calculate_balance_locked(
&mut self,
instrument: &InstrumentAny,
side: OrderSide,
quantity: Quantity,
price: Price,
use_quote_for_inverse: Option<bool>,
) -> Result<Money>
pub fn base_calculate_balance_locked( &mut self, instrument: &InstrumentAny, side: OrderSide, quantity: Quantity, price: Price, use_quote_for_inverse: Option<bool>, ) -> Result<Money>
Calculates the amount of balance to lock for a new order based on the given side, quantity, and price.
§Errors
Returns an error if the locked amount cannot be represented in the target currency.
Sourcepub fn base_calculate_pnls(
&self,
instrument: &InstrumentAny,
fill: &OrderFilled,
_position: Option<Position>,
) -> Result<Vec<Money>>
pub fn base_calculate_pnls( &self, instrument: &InstrumentAny, fill: &OrderFilled, _position: Option<Position>, ) -> Result<Vec<Money>>
Calculates profit and loss amounts for a filled order.
For cash accounts, this calculates the balance impact of a fill:
- BUY: gain base currency quantity, lose quote currency notional.
- SELL: lose base currency quantity, gain quote currency notional.
Note: Unlike betting accounts, cash accounts do NOT cap to position quantity. The full fill quantity is used for PnL calculation.
§Errors
Returns an error if a PnL amount cannot be represented in the target currency.
Sourcepub fn base_calculate_commission(
&self,
instrument: &InstrumentAny,
last_qty: Quantity,
last_px: Price,
liquidity_side: LiquiditySide,
use_quote_for_inverse: Option<bool>,
) -> Result<Money>
pub fn base_calculate_commission( &self, instrument: &InstrumentAny, last_qty: Quantity, last_px: Price, liquidity_side: LiquiditySide, use_quote_for_inverse: Option<bool>, ) -> Result<Money>
Calculates commission fees for a filled order.
§Errors
Returns an error if liquidity_side is invalid, the notional value cannot be calculated,
or the commission cannot be represented in the target currency.
Trait Implementations§
Source§impl Account for WalletAccount
impl Account for WalletAccount
fn id(&self) -> AccountId
fn account_type(&self) -> AccountType
fn base_currency(&self) -> Option<Currency>
fn is_cash_account(&self) -> bool
fn is_margin_account(&self) -> bool
fn calculated_account_state(&self) -> bool
fn balance_total(&self, currency: Option<Currency>) -> Option<Money>
fn balances_total(&self) -> IndexMap<Currency, Money>
fn balance_free(&self, currency: Option<Currency>) -> Option<Money>
fn balances_free(&self) -> IndexMap<Currency, Money>
fn balance_locked(&self, currency: Option<Currency>) -> Option<Money>
fn balances_locked(&self) -> IndexMap<Currency, Money>
fn balance(&self, currency: Option<Currency>) -> Option<&AccountBalance>
fn last_event(&self) -> Option<AccountState>
fn events(&self) -> Vec<AccountState>
fn event_count(&self) -> usize
fn currencies(&self) -> Vec<Currency>
fn starting_balances(&self) -> IndexMap<Currency, Money>
fn balances(&self) -> IndexMap<Currency, AccountBalance>
Source§fn apply(&mut self, event: AccountState) -> Result<()>
fn apply(&mut self, event: AccountState) -> Result<()>
fn purge_account_events(&mut self, ts_now: UnixNanos, lookback_secs: u64)
Source§fn calculate_balance_locked(
&mut self,
instrument: &InstrumentAny,
side: OrderSide,
quantity: Quantity,
price: Price,
use_quote_for_inverse: Option<bool>,
) -> Result<Money>
fn calculate_balance_locked( &mut self, instrument: &InstrumentAny, side: OrderSide, quantity: Quantity, price: Price, use_quote_for_inverse: Option<bool>, ) -> Result<Money>
Source§fn calculate_pnls(
&self,
instrument: &InstrumentAny,
fill: &OrderFilled,
position: Option<Position>,
) -> Result<Vec<Money>>
fn calculate_pnls( &self, instrument: &InstrumentAny, fill: &OrderFilled, position: Option<Position>, ) -> Result<Vec<Money>>
Source§fn calculate_commission(
&self,
instrument: &InstrumentAny,
last_qty: Quantity,
last_px: Price,
liquidity_side: LiquiditySide,
use_quote_for_inverse: Option<bool>,
) -> Result<Money>
fn calculate_commission( &self, instrument: &InstrumentAny, last_qty: Quantity, last_px: Price, liquidity_side: LiquiditySide, use_quote_for_inverse: Option<bool>, ) -> Result<Money>
Source§impl Clone for WalletAccount
impl Clone for WalletAccount
Source§fn clone(&self) -> WalletAccount
fn clone(&self) -> WalletAccount
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for WalletAccount
impl Debug for WalletAccount
Source§impl Deref for WalletAccount
impl Deref for WalletAccount
Source§impl DerefMut for WalletAccount
impl DerefMut for WalletAccount
impl DerefToPyAny for WalletAccount
Source§impl<'de> Deserialize<'de> for WalletAccount
impl<'de> Deserialize<'de> for WalletAccount
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl Display for WalletAccount
impl Display for WalletAccount
impl Eq for WalletAccount
Source§impl From<WalletAccount> for AccountAny
impl From<WalletAccount> for AccountAny
Source§fn from(v: WalletAccount) -> AccountAny
fn from(v: WalletAccount) -> AccountAny
Source§impl<'a, 'py> FromPyObject<'a, 'py> for WalletAccountwhere
Self: Clone,
impl<'a, 'py> FromPyObject<'a, 'py> for WalletAccountwhere
Self: Clone,
Source§impl<'py> IntoPyObject<'py> for WalletAccount
impl<'py> IntoPyObject<'py> for WalletAccount
Source§type Target = WalletAccount
type Target = WalletAccount
Source§type Output = Bound<'py, <WalletAccount as IntoPyObject<'py>>::Target>
type Output = Bound<'py, <WalletAccount as IntoPyObject<'py>>::Target>
Source§fn into_pyobject(
self,
py: Python<'py>,
) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
fn into_pyobject( self, py: Python<'py>, ) -> Result<<Self as IntoPyObject<'_>>::Output, <Self as IntoPyObject<'_>>::Error>
Source§impl PartialEq for WalletAccount
impl PartialEq for WalletAccount
Source§impl PyClass for WalletAccount
impl PyClass for WalletAccount
Source§impl PyClassImpl for WalletAccount
impl PyClassImpl for WalletAccount
Source§const IS_BASETYPE: bool = false
const IS_BASETYPE: bool = false
Source§const IS_SUBCLASS: bool = false
const IS_SUBCLASS: bool = false
Source§const IS_MAPPING: bool = false
const IS_MAPPING: bool = false
Source§const IS_SEQUENCE: bool = false
const IS_SEQUENCE: bool = false
Source§const IS_IMMUTABLE_TYPE: bool = false
const IS_IMMUTABLE_TYPE: bool = false
Source§const RAW_DOC: &'static CStr = c"\x00"
const RAW_DOC: &'static CStr = c"\x00"
Source§const DOC: &'static CStr
const DOC: &'static CStr
text_signature if a constructor is defined. Read moreSource§type Layout = <<WalletAccount as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<WalletAccount>
type Layout = <<WalletAccount as PyClassImpl>::BaseNativeType as PyClassBaseType>::Layout<WalletAccount>
Source§type ThreadChecker = NoopThreadChecker
type ThreadChecker = NoopThreadChecker
type Inventory = Pyo3MethodsInventoryForWalletAccount
Source§type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
type PyClassMutability = <<PyAny as PyClassBaseType>::PyClassMutability as PyClassMutability>::MutableChild
Source§type BaseNativeType = PyAny
type BaseNativeType = PyAny
PyAny by default, and when you declare
#[pyclass(extends=PyDict)], it’s PyDict.fn items_iter() -> PyClassItemsIter
fn lazy_type_object() -> &'static LazyTypeObject<Self>
§fn dict_offset() -> Option<PyObjectOffset>
fn dict_offset() -> Option<PyObjectOffset>
§fn weaklist_offset() -> Option<PyObjectOffset>
fn weaklist_offset() -> Option<PyObjectOffset>
Source§impl PyClassNewTextSignature for WalletAccount
impl PyClassNewTextSignature for WalletAccount
const TEXT_SIGNATURE: &'static str = "(event, calculate_account_state)"
Source§impl PyStubType for WalletAccount
impl PyStubType for WalletAccount
Source§fn type_output() -> TypeInfo
fn type_output() -> TypeInfo
§fn type_input() -> TypeInfo
fn type_input() -> TypeInfo
Source§impl PyTypeInfo for WalletAccount
impl PyTypeInfo for WalletAccount
Source§const NAME: &str = <Self as ::pyo3::PyClass>::NAME
const NAME: &str = <Self as ::pyo3::PyClass>::NAME
prefer using ::type_object(py).name() to get the correct runtime value
Source§const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
const MODULE: Option<&str> = <Self as ::pyo3::impl_::pyclass::PyClassImpl>::MODULE
prefer using ::type_object(py).module() to get the correct runtime value
Source§fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
fn type_object_raw(py: Python<'_>) -> *mut PyTypeObject
§fn type_object(py: Python<'_>) -> Bound<'_, PyType>
fn type_object(py: Python<'_>) -> Bound<'_, PyType>
§fn is_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type or a subclass of this type.§fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
fn is_exact_type_of(object: &Bound<'_, PyAny>) -> bool
object is an instance of this type.Source§impl Serialize for WalletAccount
impl Serialize for WalletAccount
Source§impl TryInto<WalletAccount> for AccountAny
impl TryInto<WalletAccount> for AccountAny
Auto Trait Implementations§
impl Freeze for WalletAccount
impl RefUnwindSafe for WalletAccount
impl Send for WalletAccount
impl Sync for WalletAccount
impl Unpin for WalletAccount
impl UnsafeUnpin for WalletAccount
impl UnwindSafe for WalletAccount
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
impl<'py, T> FromPyObjectOwned<'py> for Twhere
T: for<'a> FromPyObject<'a, 'py>,
§impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
impl<'py, T> IntoPyObjectExt<'py> for Twhere
T: IntoPyObject<'py>,
§fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
fn into_bound_py_any(self, py: Python<'py>) -> Result<Bound<'py, PyAny>, PyErr>
self into an owned Python object, dropping type information.§fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
fn into_py_any(self, py: Python<'py>) -> Result<Py<PyAny>, PyErr>
self into an owned Python object, dropping type information and unbinding it
from the 'py lifetime.§fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
fn into_pyobject_or_pyerr(self, py: Python<'py>) -> Result<Self::Output, PyErr>
self into a Python object. Read more§impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
impl<'py, T> IntoPyObjectNautilusExt<'py> for Twhere
T: IntoPyObjectExt<'py>,
§fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>where
Self: IntoPyObject<'py, Error = !>,
fn into_py_any_unwrap(self, py: Python<'py>) -> Py<PyAny>where
Self: IntoPyObject<'py, Error = !>,
self into a [Py<PyAny>] when the underlying conversion is infallible.§impl<T> PyErrArguments for T
impl<T> PyErrArguments for T
§impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
impl<T> PyTypeCheck for Twhere
T: PyTypeInfo,
§fn type_check(object: &Bound<'_, PyAny>) -> bool
fn type_check(object: &Bound<'_, PyAny>) -> bool
§fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
fn classinfo_object(py: Python<'_>) -> Bound<'_, PyAny>
isinstance and issubclass function. Read more