pub struct SpotPosition {
pub symbol: String,
pub quantity: Positive,
pub cost_basis: Positive,
pub side: Side,
pub date: DateTime<Utc>,
pub open_fee: Positive,
pub close_fee: Positive,
}Expand description
Represents a spot/underlying asset position.
A spot position represents direct ownership of an asset without any derivative characteristics. This includes stocks, cryptocurrency spot holdings, forex spot, and commodities held for delivery.
§Fields
symbol- The ticker symbol or identifier of the assetquantity- The number of units heldcost_basis- The average acquisition price per unitside- Whether the position is Long (owned) or Short (borrowed/sold)date- The timestamp when the position was openedopen_fee- Transaction fee paid to open the positionclose_fee- Transaction fee to be paid when closing the position
Fields§
§symbol: StringThe ticker symbol or identifier of the underlying asset.
quantity: PositiveThe number of units held in this position.
cost_basis: PositiveThe average cost per unit at which the position was acquired.
side: SideThe direction of the position (Long = owned, Short = borrowed).
date: DateTime<Utc>The timestamp when this position was opened.
open_fee: PositiveThe fee paid to open this position.
close_fee: PositiveThe fee to be paid when closing this position.
Implementations§
Source§impl SpotPosition
impl SpotPosition
Sourcepub fn new(
symbol: String,
quantity: Positive,
cost_basis: Positive,
side: Side,
date: DateTime<Utc>,
open_fee: Positive,
close_fee: Positive,
) -> Self
pub fn new( symbol: String, quantity: Positive, cost_basis: Positive, side: Side, date: DateTime<Utc>, open_fee: Positive, close_fee: Positive, ) -> Self
Creates a new spot position.
§Arguments
symbol- The ticker symbol of the assetquantity- Number of units to holdcost_basis- Average price per unitside- Long or Short positiondate- Position open timestampopen_fee- Fee to open the positionclose_fee- Fee to close the position
§Returns
A new SpotPosition instance.
Sourcepub fn initial_value(&self) -> Result<Positive, PositionError>
pub fn initial_value(&self) -> Result<Positive, PositionError>
Returns the total value of the position at the cost basis.
This represents the initial investment (for long) or proceeds (for short).
§Errors
Returns PositionError::PositiveError when the product leaves the
Positive range; Positive * Positive aborted on it (#788).
Sourcepub fn market_value(
&self,
current_price: Positive,
) -> Result<Positive, PositionError>
pub fn market_value( &self, current_price: Positive, ) -> Result<Positive, PositionError>
Returns the current market value at a given price.
§Arguments
current_price- The current market price per unit
§Errors
Returns PositionError::PositiveError when the product leaves the
Positive range (#788).
Sourcepub fn percentage_return(
&self,
current_price: Positive,
) -> Result<Decimal, PositionError>
pub fn percentage_return( &self, current_price: Positive, ) -> Result<Decimal, PositionError>
Calculates the percentage return on the position.
§Arguments
current_price- The current market price per unit
§Returns
The percentage return as a Decimal (e.g., 0.10 = 10% gain).
§Errors
Returns PositionError::DecimalError when the return leaves the
Decimal range: a cost basis near zero against a large price, where
the division aborted with Division overflowed (#788).
Sourcepub fn break_even_price(&self) -> Result<Positive, PositionError>
pub fn break_even_price(&self) -> Result<Positive, PositionError>
Calculates the break-even price including fees.
For long positions: cost_basis + (total_fees / quantity) For short positions: cost_basis - (total_fees / quantity), floored at zero.
§Errors
Returns PositionError::PositiveError when the fee total, the fee
per unit or the long break-even leaves the Positive range: a
quantity near zero against large fees, where the division aborted
with Positive arithmetic overflow in div (#788).