pub struct Position { /* private fields */ }Expand description
Represents a position (holding) in the portfolio.
Implementations§
Source§impl Position
impl Position
Sourcepub fn new(
symbol: impl Into<String>,
exchange: impl Into<String>,
quantity: Decimal,
current_price: Money,
) -> Self
pub fn new( symbol: impl Into<String>, exchange: impl Into<String>, quantity: Decimal, current_price: Money, ) -> Self
Creates a new Position.
Sourcepub fn builder(
symbol: impl Into<String>,
exchange: impl Into<String>,
) -> PositionBuilder
pub fn builder( symbol: impl Into<String>, exchange: impl Into<String>, ) -> PositionBuilder
Creates a Position builder for more complex construction.
Sourcepub fn instrument_id(&self) -> Option<&str>
pub fn instrument_id(&self) -> Option<&str>
Returns the instrument ID if set.
Sourcepub const fn current_price(&self) -> &Money
pub const fn current_price(&self) -> &Money
Returns the current price.
Sourcepub const fn average_cost(&self) -> Option<&Money>
pub const fn average_cost(&self) -> Option<&Money>
Returns the average cost if set.
Sourcepub const fn is_blocked(&self) -> bool
pub const fn is_blocked(&self) -> bool
Returns whether the position is blocked.
Sourcepub const fn blocked_lots(&self) -> u32
pub const fn blocked_lots(&self) -> u32
Returns the number of blocked lots.
Sourcepub fn market_value(&self) -> Money
pub fn market_value(&self) -> Money
Calculates the total market value of the position.
Sourcepub fn tradeable_lots(&self) -> u32
pub fn tradeable_lots(&self) -> u32
Calculates the number of tradeable lots (total - blocked).
Sourcepub fn unrealized_pnl(&self) -> Option<Money>
pub fn unrealized_pnl(&self) -> Option<Money>
Calculates the unrealized P&L if average cost is known.
Sourcepub fn unrealized_pnl_percent(&self) -> Option<Decimal>
pub fn unrealized_pnl_percent(&self) -> Option<Decimal>
Calculates the unrealized P&L percentage if average cost is known.
Sourcepub fn update_price(&mut self, price: Money)
pub fn update_price(&mut self, price: Money)
Updates the current price.
Sourcepub fn update_quantity(&mut self, quantity: Decimal)
pub fn update_quantity(&mut self, quantity: Decimal)
Updates the quantity.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
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 Position
Auto Trait Implementations§
impl Forget for Position
impl Freeze for Position
impl Move for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnsafeUnpin for Position
impl UnwindSafe for Position
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