pub struct AccountRef<'a>(/* private fields */);Expand description
Lifetime-scoped read borrow of a cached account.
Returned by crate::cache::Cache::account. The borrow drops with the enclosing scope, which
makes any attempt to hold it across a cache mutation panic at runtime: a loud failure beats the
silent staleness that a stored clone would produce.
Method calls on the inner AccountAny resolve via Deref; comparisons against &AccountAny
or owned AccountAny values are direct (account_ref == &account); Debug forwards to the
inner record. Use cloned when an owned snapshot is required (for example,
before crossing a boundary that may dispatch events).
Implementations§
Source§impl<'a> AccountRef<'a>
impl<'a> AccountRef<'a>
Sourcepub fn new(inner: Ref<'a, AccountAny>) -> Self
pub fn new(inner: Ref<'a, AccountAny>) -> Self
Wraps the given Ref borrow.
Sourcepub fn cloned(&self) -> AccountAny
pub fn cloned(&self) -> AccountAny
Returns an owned snapshot of the borrowed account.
Mirrors Option::cloned and Iterator::cloned; the snapshot will not reflect later
mutations of the underlying cell.
Methods from Deref<Target = AccountAny>§
pub fn id(&self) -> AccountId
pub fn last_event(&self) -> Option<AccountState>
pub fn events(&self) -> Vec<AccountState>
pub fn balances(&self) -> IndexMap<Currency, AccountBalance>
pub fn balances_locked(&self) -> IndexMap<Currency, Money>
pub fn base_currency(&self) -> Option<Currency>
Sourcepub fn calculate_pnls(
&self,
instrument: &InstrumentAny,
fill: &OrderFilled,
position: Option<Position>,
) -> Result<Vec<Money>, Error>
pub fn calculate_pnls( &self, instrument: &InstrumentAny, fill: &OrderFilled, position: Option<Position>, ) -> Result<Vec<Money>, Error>
§Errors
Returns an error if calculating P&Ls fails for the underlying account.
Sourcepub fn calculate_commission(
&self,
instrument: &InstrumentAny,
last_qty: Quantity,
last_px: Price,
liquidity_side: LiquiditySide,
use_quote_for_inverse: Option<bool>,
) -> Result<Money, Error>
pub fn calculate_commission( &self, instrument: &InstrumentAny, last_qty: Quantity, last_px: Price, liquidity_side: LiquiditySide, use_quote_for_inverse: Option<bool>, ) -> Result<Money, Error>
§Errors
Returns an error if calculating commission fails for the underlying account.
pub fn balance(&self, currency: Option<Currency>) -> Option<&AccountBalance>
Trait Implementations§
Source§impl AsRef<AccountAny> for AccountRef<'_>
impl AsRef<AccountAny> for AccountRef<'_>
Source§fn as_ref(&self) -> &AccountAny
fn as_ref(&self) -> &AccountAny
Source§impl Debug for AccountRef<'_>
impl Debug for AccountRef<'_>
Source§impl Deref for AccountRef<'_>
impl Deref for AccountRef<'_>
Source§impl<'a> From<Ref<'a, AccountAny>> for AccountRef<'a>
impl<'a> From<Ref<'a, AccountAny>> for AccountRef<'a>
Source§fn from(inner: Ref<'a, AccountAny>) -> Self
fn from(inner: Ref<'a, AccountAny>) -> Self
Source§impl PartialEq<&AccountAny> for AccountRef<'_>
impl PartialEq<&AccountAny> for AccountRef<'_>
Source§fn eq(&self, other: &&AccountAny) -> bool
fn eq(&self, other: &&AccountAny) -> bool
self and other values to be equal, and is used by ==.Source§impl PartialEq<AccountAny> for AccountRef<'_>
impl PartialEq<AccountAny> for AccountRef<'_>
Source§fn eq(&self, other: &AccountAny) -> bool
fn eq(&self, other: &AccountAny) -> bool
self and other values to be equal, and is used by ==.Auto Trait Implementations§
impl<'a> Freeze for AccountRef<'a>
impl<'a> !RefUnwindSafe for AccountRef<'a>
impl<'a> !Send for AccountRef<'a>
impl<'a> !Sync for AccountRef<'a>
impl<'a> Unpin for AccountRef<'a>
impl<'a> UnsafeUnpin for AccountRef<'a>
impl<'a> !UnwindSafe for AccountRef<'a>
Blanket Implementations§
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more