pub struct Wallet { /* private fields */ }Expand description
Represents a wallet (portfolio) containing multiple positions.
Implementations§
Source§impl Wallet
impl Wallet
Sourcepub fn with_cash(base_currency: impl Into<String>, cash: Money) -> Self
pub fn with_cash(base_currency: impl Into<String>, cash: Money) -> Self
Creates a wallet with initial cash balance.
Sourcepub fn base_currency(&self) -> &str
pub fn base_currency(&self) -> &str
Returns the base currency.
Sourcepub fn positions_mut(&mut self) -> &mut Vec<Position>
pub fn positions_mut(&mut self) -> &mut Vec<Position>
Returns a mutable reference to positions.
Sourcepub fn add_position(&mut self, position: Position)
pub fn add_position(&mut self, position: Position)
Adds a position to the wallet.
Sourcepub fn remove_position(&mut self, symbol: &str) -> Option<Position>
pub fn remove_position(&mut self, symbol: &str) -> Option<Position>
Removes a position by symbol.
Sourcepub fn get_position(&self, symbol: &str) -> Option<&Position>
pub fn get_position(&self, symbol: &str) -> Option<&Position>
Gets a position by symbol.
Sourcepub fn get_position_mut(&mut self, symbol: &str) -> Option<&mut Position>
pub fn get_position_mut(&mut self, symbol: &str) -> Option<&mut Position>
Gets a mutable position by symbol.
Sourcepub fn subtract_cash(&mut self, amount: Money)
pub fn subtract_cash(&mut self, amount: Money)
Subtracts from the cash balance.
Sourcepub fn total_positions_value(&self) -> Money
pub fn total_positions_value(&self) -> Money
Calculates the total market value of all positions.
Sourcepub fn total_value(&self) -> Money
pub fn total_value(&self) -> Money
Calculates the total portfolio value (cash + positions).
Sourcepub fn current_allocation(&self) -> DesiredAllocation
pub fn current_allocation(&self) -> DesiredAllocation
Calculates the current allocation percentages.
Sourcepub fn cash_percentage(&self) -> Decimal
pub fn cash_percentage(&self) -> Decimal
Calculates the cash percentage of total portfolio.
Sourcepub fn position_count(&self) -> usize
pub fn position_count(&self) -> usize
Returns the number of positions.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Wallet
impl<'de> Deserialize<'de> for Wallet
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>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Wallet
Auto Trait Implementations§
impl Forget for Wallet
impl Freeze for Wallet
impl Move for Wallet
impl RefUnwindSafe for Wallet
impl Send for Wallet
impl Sync for Wallet
impl Unpin for Wallet
impl UnsafeUnpin for Wallet
impl UnwindSafe for Wallet
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
Mutably borrows from an owned value. Read more