pub struct Position {
pub option: Options,
pub premium: Positive,
pub date: DateTime<Utc>,
pub open_fee: Positive,
pub close_fee: Positive,
pub epic: Option<String>,
pub extra_fields: Option<Value>,
}Expand description
The Position struct represents a financial position in an options market.
This structure encapsulates all the necessary information to track an options position, including the underlying option details, costs associated with the position, and the date when the position was opened. It provides methods for analyzing profitability, time metrics, and position characteristics.
§Examples
use optionstratlib::{Options, Side, OptionStyle};
use positive::pos_or_panic;
use chrono::Utc;
use tracing::info;
use optionstratlib::model::Position;
use optionstratlib::model::utils::create_sample_option_simplest;
let option = create_sample_option_simplest(OptionStyle::Call, Side::Long);
let position = Position::new(
option,
pos_or_panic!(5.25), // premium per contract
Utc::now(), // position open date
pos_or_panic!(0.65), // opening fee per contract
pos_or_panic!(0.65), // closing fee per contract
None,
None,
);
let total_cost = position.total_cost()?;
info!("Total position cost: {}", total_cost);Fields§
§option: OptionsThe detailed options contract information, including the type, strike price, expiration, underlying asset details, and other option-specific parameters.
The premium paid or received per contract. For long positions, this represents the cost per contract; for short positions, this is the credit received.
date: DateTime<Utc>The date and time when the position was opened, used for calculating time-based metrics like days held and days to expiration.
open_fee: PositiveThe fee paid to open the position per contract. This typically includes broker commissions and exchange fees.
close_fee: PositiveThe fee that will be paid to close the position per contract. This is used in profit/loss calculations to account for all transaction costs.
epic: Option<String>Identifier for the position in an external system or platform
extra_fields: Option<Value>Additional custom data fields for the position stored as JSON
Implementations§
Source§impl Position
impl Position
Sourcepub fn new(
option: Options,
premium: Positive,
date: DateTime<Utc>,
open_fee: Positive,
close_fee: Positive,
epic: Option<String>,
extra_fields: Option<Value>,
) -> Self
pub fn new( option: Options, premium: Positive, date: DateTime<Utc>, open_fee: Positive, close_fee: Positive, epic: Option<String>, extra_fields: Option<Value>, ) -> Self
Creates a new options position.
This constructor initializes a new Position instance representing an options trade,
capturing all essential information for position tracking and analysis.
§Parameters
-
option- The options contract details including type (call/put), strike price, expiration date, underlying asset information, and other option parameters. -
premium- The premium paid (for long positions) or received (for short positions) per contract, represented as a positive value. -
date- The timestamp when the position was opened, used for calculating time-based metrics like days to expiration and position duration. -
open_fee- The transaction costs paid to open the position per contract, including broker commissions and exchange fees. -
close_fee- The anticipated transaction costs to close the position per contract, used for accurate profit/loss calculations.
§Returns
Returns a new Position instance containing the provided information.
§Examples
use optionstratlib::{Options, Side, OptionStyle};
use positive::pos_or_panic;
use chrono::Utc;
use optionstratlib::model::Position;
use optionstratlib::model::utils::create_sample_option_simplest;
let option = create_sample_option_simplest(OptionStyle::Call, Side::Long);
let position = Position::new(
option,
pos_or_panic!(5.25), // premium per contract
Utc::now(), // position open date
pos_or_panic!(0.65), // opening fee per contract
pos_or_panic!(0.65), // closing fee per contract
None, // epic (optional)
None, // extra fields (optional)
);Sourcepub fn total_cost(&self) -> Result<Positive, PositionError>
pub fn total_cost(&self) -> Result<Positive, PositionError>
Calculates the total cost of the position based on the option’s side and fees.
Depending on whether the position is long or short, different components contribute to the total cost calculation:
- For a long position, the total cost includes the premium, open fee, and close fee multiplied by the option’s quantity.
- For a short position, the total cost includes only the open fee and close fee multiplied by the option’s quantity.
§Returns
A f64 representing the total cost of the position. THE VALUE IS ALWAYS POSITIVE
§Errors
Currently infallible — long positions accumulate only
non-negative Positive terms and short positions delegate
to fees(), which is itself infallible under the current
implementation. The Result signature is retained so future
implementations that validate fee configuration or surface
overflow on Positive arithmetic can return
PositionError without a breaking change.
Calculates the premium received from an options position.
This method determines the premium amount received based on the position’s side:
- For long positions, it returns zero as the trader pays premium (doesn’t receive any)
- For short positions, it returns the total premium received (premium per contract × quantity)
The result is always returned as a Positive value, ensuring non-negative amounts.
§Returns
Result<Positive, PositionError>- A result containing the premium received as aPositivevalue if successful, or aPositionErrorif any calculation errors occur.
§Examples
use optionstratlib::{ Side, OptionStyle};
use positive::pos_or_panic;
use optionstratlib::model::Position;
use optionstratlib::model::utils::create_sample_option_simplest;
use chrono::Utc;
use tracing::info;
// Create a short position
let option = create_sample_option_simplest(OptionStyle::Call, Side::Short);
let position = Position::new(
option,
pos_or_panic!(5.25), // premium per contract
Utc::now(), // position open date
pos_or_panic!(0.65), // opening fee
pos_or_panic!(0.65), // closing fee
None, // epic (optional)
None, // extra fields (optional)
);
// Calculate premium received
let received = position.premium_received()?;
info!("Premium received: {}", received);§Errors
Currently infallible — long positions return
Ok(Positive::ZERO) (no premium received) and short
positions return Ok(self.premium * self.option.quantity).
The Result signature is retained so future implementations
that treat long-side calls as a programmer error, or that
surface overflow on the premium × quantity product, can
return PositionError without a breaking change.
Calculates the net premium received for the position.
This method determines the premium amount received after accounting for costs, which is relevant primarily for short positions. For long positions, this always returns zero as premium is paid rather than received.
For short positions, the method calculates the difference between the premium received and the total costs incurred. If this value is positive (meaning the premium exceeds the costs), it represents the maximum potential profit for the position. If negative, the position is considered invalid as it would represent a guaranteed loss.
§Returns
Ok(Positive)- The net premium received as a non-negative valueErr(PositionError)- If the position is invalid because the premium received is less than the costs, resulting in a guaranteed loss
§Errors
Propagates any PositionError raised by total_cost() (no
variant is surfaced under the current implementation, but
the call site keeps the ? for forward compatibility).
When the short-side net amount premium − total_cost is
negative the function returns Ok(Positive::ZERO) (clamped)
rather than an error, so a guaranteed-loss short position is
reported as zero net received rather than as a failure.
Sourcepub fn pnl_at_expiration(
&self,
price: &Option<&Positive>,
) -> Result<Decimal, PricingError>
pub fn pnl_at_expiration( &self, price: &Option<&Positive>, ) -> Result<Decimal, PricingError>
Calculates the profit and loss (PnL) at the option’s expiration.
This function determines the total profit or loss that would be realized when the option position expires, taking into account the intrinsic value at expiration, the cost to establish the position, and any premiums received.
§Arguments
price- An optional reference to a positive decimal value representing the underlying asset price at expiration. If None is provided, the calculation will use the current underlying price stored in the option.
§Returns
Result<Decimal, PricingError>- The calculated profit or loss as a Decimal value, or an error if the calculation fails.
§Examples
// Assuming position is a properly initialized Position
use chrono::Utc;
use optionstratlib::model::utils::create_sample_option_simplest;
use optionstratlib::{OptionStyle, Side};
use positive::pos_or_panic;
use optionstratlib::model::Position;
let option = create_sample_option_simplest(OptionStyle::Call, Side::Short);
let position = Position::new(
option,
pos_or_panic!(5.25), // premium per contract
Utc::now(), // position open date
pos_or_panic!(0.65), // opening fee
pos_or_panic!(0.65), // closing fee
None, // epic (optional)
None, // extra fields (optional)
);
let current_price = pos_or_panic!(105.0);
// Calculate PnL at expiration with specified price
let pnl_specific = position.pnl_at_expiration(&Some(¤t_price))?;
// Calculate PnL at expiration using the option's current underlying price
let pnl_current = position.pnl_at_expiration(&None)?;§Errors
Propagates any OptionsError returned by the underlying payoff
evaluation (Options::intrinsic_value or Options::payoff),
wrapped as PricingError::OptionError.
Sourcepub fn unrealized_pnl(&self, price: Positive) -> Result<Decimal, PositionError>
pub fn unrealized_pnl(&self, price: Positive) -> Result<Decimal, PositionError>
Calculates the unrealized profit and loss (PnL) for an options position at a given price.
This method computes the current theoretical profit or loss of the position if it were to be closed at the specified price, taking into account the premium paid/received and all transaction fees (both opening and closing fees).
The calculation differs based on the position side:
- For long positions: (current_price - premium - open_fee - close_fee) * quantity
- For short positions: (premium - current_price - open_fee - close_fee) * quantity
§Parameters
price- APositivevalue representing the current price of the option
§Returns
Result<Decimal, PositionError>- The calculated unrealized PnL as aDecimalif successful, or aPositionErrorif the calculation fails
§Example
use chrono::Utc;
use tracing::info;
use optionstratlib::model::Position;
use optionstratlib::model::utils::create_sample_option_simplest;
use optionstratlib::{ OptionStyle, Side};
use positive::pos_or_panic;
let current_price = pos_or_panic!(6.50);
let option = create_sample_option_simplest(OptionStyle::Call, Side::Short);
let position = Position::new(
option,
pos_or_panic!(5.25), // premium per contract
Utc::now(), // position open date
pos_or_panic!(0.65), // opening fee
pos_or_panic!(0.65), // closing fee
None, // epic (optional)
None, // extra fields (optional)
);
let unrealized_pnl = position.unrealized_pnl(current_price)?;
info!("Current unrealized PnL: {}", unrealized_pnl);§Errors
Returns PositionError wrapping any
PositionValidationErrorKind surfaced by the internal Black–Scholes
evaluation, or PositionError::PricingError when the
implied-volatility recomputation at price fails.
Sourcepub fn days_held(&self) -> Result<Positive, PositionError>
pub fn days_held(&self) -> Result<Positive, PositionError>
Calculates the number of days the position has been held.
This method computes the difference between the current UTC date and the
position’s opening date, returning the result as a Positive value.
The calculation uses Chrono’s num_days method to determine the precise
number of whole days between the position’s date and current time.
§Returns
Ok(Positive)- The number of days the position has been held as a positive valueErr(PositionError)- If there’s an error during the calculation or validation
§Errors
Returns PositionError wrapping a
PositionValidationErrorKind::InvalidPositionSize if the elapsed
day-count is negative (future-dated open date) or cannot be
represented as a Positive.
Sourcepub fn days_to_expiration(&self) -> Result<Positive, PositionError>
pub fn days_to_expiration(&self) -> Result<Positive, PositionError>
Calculates the number of days remaining until the option expires.
This function determines the time to expiration in days based on the option’s expiration date format. It handles both explicit day counts and datetime-based expiration dates.
§Returns
Ok(Positive)- The number of days to expiration as a positive valueErr(PositionError)- If the calculation fails due to issues with the position data
For datetime-based expirations, the function calculates the difference between the expiration date and the current date, converting the result to days.
§Errors
Returns PositionError wrapping the underlying
expiration_date::error::ExpirationDateError when the expiration
cannot be converted (e.g. a past datetime that would produce a
negative day count).
Sourcepub fn is_long(&self) -> bool
pub fn is_long(&self) -> bool
Determines if the position is a long position.
This method checks the side attribute of the option to determine the directionality of the position. Long positions profit when the underlying asset’s price increases.
§Returns
trueif the position is longfalseif the position is short
Sourcepub fn is_short(&self) -> bool
pub fn is_short(&self) -> bool
Determines if the position is a short position.
This method checks the side attribute of the option to determine the directionality of the position. Short positions profit when the underlying asset’s price decreases.
§Returns
trueif the position is shortfalseif the position is long
Sourcepub fn net_cost(&self) -> Result<Decimal, PositionError>
pub fn net_cost(&self) -> Result<Decimal, PositionError>
Calculates the net cost of the position based on the option’s side and fees.
This method calculates the net cost of a position by determining whether the position is long or short and then computing the respective costs:
- For a long position, the net cost is equivalent to the
total_cost()of the position. - For a short position, the net cost is calculated by subtracting the premium from the sum of the open and close fees, and then multiplying the result by the option’s quantity.
§Returns
A Decimal representing the net cost of the position.
The value should be positive but if the fee is higher than the premium it will be negative
in short positions
§Errors
Currently only propagates arithmetic-failure variants surfaced by the
premium × quantity and fee additions; in practice infallible for all
valid positions, but the Result signature is retained to let
callers handle future overflow paths uniformly.
Sourcepub fn break_even(&self) -> Option<Positive>
pub fn break_even(&self) -> Option<Positive>
Calculates the break-even price for an options position.
This method determines the price of the underlying asset at which the position will neither make a profit nor a loss. The calculation varies based on both the side of the position (Long/Short) and the option style (Call/Put).
The break-even price is an important reference point for options traders as it represents the threshold price that the underlying asset must cross for the position to become profitable, accounting for all costs associated with the position.
§Formula by position type:
- Long Call: Strike Price + Total Cost per Contract
- Short Call: Strike Price + Premium - Total Cost per Contract
- Long Put: Strike Price - Total Cost per Contract
- Short Put: Strike Price - Premium + Total Cost per Contract
§Returns
Some(Positive)containing the break-even price if the position has non-zero quantityNoneif the position has zero quantity (no contracts) or if the position total cost cannot be calculated
Sourcepub fn fees(&self) -> Result<Positive, PositionError>
pub fn fees(&self) -> Result<Positive, PositionError>
Calculates the total transaction fees for the position.
This method computes the sum of opening and closing fees for the position, scaled by the quantity of options contracts. These fees typically include broker commissions, exchange fees, and other transaction costs.
§Returns
Ok(Positive)- The total fees as a positive valueErr(PositionError)- If there’s an issue calculating the fees
§Errors
Currently infallible in practice; the Result signature is retained
so that future fee models that can overflow Positive (e.g. tiered
fee schedules multiplied by very large quantities) can surface their
failures without a breaking API change.
Sourcepub fn validate(&self) -> bool
pub fn validate(&self) -> bool
Validates the position to ensure it meets all necessary conditions for trading.
This method performs a series of checks to determine if the position is valid:
- For short positions, verifies that:
- Premium is greater than zero
- Premium exceeds the sum of opening and closing fees
- Validates the underlying option parameters
§Returns
trueif the position is valid and meets all conditionsfalseotherwise, with specific failure reasons logged via debug messages
§Examples
use optionstratlib::model::{Position, Options};
use optionstratlib::{Side, OptionStyle};
use positive::pos_or_panic;
use optionstratlib::model::utils::create_sample_option_simplest;
use chrono::Utc;
// Create a valid position
let option = create_sample_option_simplest(OptionStyle::Call, Side::Long);
let position = Position::new(
option,
pos_or_panic!(5.25),
Utc::now(),
pos_or_panic!(0.65),
pos_or_panic!(0.65),
None, // epic (optional)
None, // extra fields (optional)
);
assert!(position.validate());Trait Implementations§
Source§impl BasicAble for Position
impl BasicAble for Position
Source§fn set_implied_volatility(
&mut self,
_volatility: &Positive,
) -> Result<(), StrategyError>
fn set_implied_volatility( &mut self, _volatility: &Positive, ) -> Result<(), StrategyError>
Updates the volatility for the strategy.
§Parameters
_volatility: A reference to aPositivevalue representing the new volatility to set.
§Returns
Ok(()): If the update operation succeeds (currently unimplemented).Err(StrategyError): If there is an error during the update process (place-holder as functionality is not implemented).
§Notes
This method is currently unimplemented, and calling it will result in the unimplemented! macro being triggered, which causes a panic.
This function is a stub and should be implemented to handle setting the volatility specific to the strategy.
Source§fn get_title(&self) -> String
fn get_title(&self) -> String
Source§fn get_option_basic_type(&self) -> HashSet<OptionBasicType<'_>>
fn get_option_basic_type(&self) -> HashSet<OptionBasicType<'_>>
Source§fn get_symbol(&self) -> &str
fn get_symbol(&self) -> &str
get_symbol
method of the one_option object. Read moreSource§fn get_strike(&self) -> HashMap<OptionBasicType<'_>, &Positive>
fn get_strike(&self) -> HashMap<OptionBasicType<'_>, &Positive>
Source§fn get_strikes(&self) -> Vec<&Positive>
fn get_strikes(&self) -> Vec<&Positive>
Source§fn get_type(&self) -> &OptionType
fn get_type(&self) -> &OptionType
Source§fn get_style(&self) -> HashMap<OptionBasicType<'_>, &OptionStyle>
fn get_style(&self) -> HashMap<OptionBasicType<'_>, &OptionStyle>
Source§fn get_expiration(&self) -> HashMap<OptionBasicType<'_>, &ExpirationDate>
fn get_expiration(&self) -> HashMap<OptionBasicType<'_>, &ExpirationDate>
Source§fn get_implied_volatility(&self) -> HashMap<OptionBasicType<'_>, &Positive>
fn get_implied_volatility(&self) -> HashMap<OptionBasicType<'_>, &Positive>
Source§fn get_quantity(&self) -> HashMap<OptionBasicType<'_>, &Positive>
fn get_quantity(&self) -> HashMap<OptionBasicType<'_>, &Positive>
Source§fn get_underlying_price(&self) -> &Positive
fn get_underlying_price(&self) -> &Positive
Source§fn get_risk_free_rate(&self) -> HashMap<OptionBasicType<'_>, &Decimal>
fn get_risk_free_rate(&self) -> HashMap<OptionBasicType<'_>, &Decimal>
Source§fn get_dividend_yield(&self) -> HashMap<OptionBasicType<'_>, &Positive>
fn get_dividend_yield(&self) -> HashMap<OptionBasicType<'_>, &Positive>
Source§fn one_option(&self) -> &Options
fn one_option(&self) -> &Options
Options value. Read moreSource§fn one_option_mut(&mut self) -> &mut Options
fn one_option_mut(&mut self) -> &mut Options
Options value. Read moreSource§fn set_expiration_date(
&mut self,
expiration_date: ExpirationDate,
) -> Result<(), StrategyError>
fn set_expiration_date( &mut self, expiration_date: ExpirationDate, ) -> Result<(), StrategyError>
Source§fn set_underlying_price(
&mut self,
_price: &Positive,
) -> Result<(), StrategyError>
fn set_underlying_price( &mut self, _price: &Positive, ) -> Result<(), StrategyError>
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>,
Source§impl Graph for Position
Implementation of the Graph trait for the Position struct, enabling graphical representation
of financial options positions.
impl Graph for Position
Implementation of the Graph trait for the Position struct, enabling graphical representation
of financial options positions.
This implementation provides methods to visualize the profit/loss (PnL) profile of an options position across different price levels of the underlying asset. It handles the generation of appropriate title, data values for plotting, and special chart elements like break-even points.
The visualization capabilities allow traders to analyze the potential outcomes of their options positions at expiration across various price scenarios.
Source§fn graph_data(&self) -> GraphData
fn graph_data(&self) -> GraphData
Source§fn graph_config(&self) -> GraphConfig
fn graph_config(&self) -> GraphConfig
Source§impl Greeks for Position
Implementation of the Greeks trait for the Position struct.
impl Greeks for Position
Implementation of the Greeks trait for the Position struct.
This implementation allows a Position to calculate option Greeks (delta, gamma,
theta, vega, rho, etc.) by accessing its underlying option contract. The implementation
provides a way to expose the position’s option for use in Greek calculations.
Source§fn get_options(&self) -> Result<Vec<&Options>, GreeksError>
fn get_options(&self) -> Result<Vec<&Options>, GreeksError>
Returns a vector containing a reference to the option contract associated with this position.
This method satisfies the Greeks trait requirement by providing access to the
option contract that will be used for calculating various Greek values.
§Returns
Ok(Vec<&Options>)- A vector containing a reference to the position’s underlying optionErr(GreeksError)- If there is an error accessing the option data
Source§fn greeks(&self) -> Result<Greek, GreeksError>
fn greeks(&self) -> Result<Greek, GreeksError>
Greek struct. Read moreSource§fn delta(&self) -> Result<Decimal, GreeksError>
fn delta(&self) -> Result<Decimal, GreeksError>
Source§fn gamma(&self) -> Result<Decimal, GreeksError>
fn gamma(&self) -> Result<Decimal, GreeksError>
Source§fn theta(&self) -> Result<Decimal, GreeksError>
fn theta(&self) -> Result<Decimal, GreeksError>
Source§fn vega(&self) -> Result<Decimal, GreeksError>
fn vega(&self) -> Result<Decimal, GreeksError>
Source§fn rho(&self) -> Result<Decimal, GreeksError>
fn rho(&self) -> Result<Decimal, GreeksError>
Source§fn rho_d(&self) -> Result<Decimal, GreeksError>
fn rho_d(&self) -> Result<Decimal, GreeksError>
Source§fn alpha(&self) -> Result<Decimal, GreeksError>
fn alpha(&self) -> Result<Decimal, GreeksError>
Source§fn vanna(&self) -> Result<Decimal, GreeksError>
fn vanna(&self) -> Result<Decimal, GreeksError>
Source§fn vomma(&self) -> Result<Decimal, GreeksError>
fn vomma(&self) -> Result<Decimal, GreeksError>
Source§fn veta(&self) -> Result<Decimal, GreeksError>
fn veta(&self) -> Result<Decimal, GreeksError>
Source§impl PnLCalculator for Position
§Position Profit and Loss (PnL) Calculator
This trait implementation provides methods to calculate the profit and loss (PnL)
for option positions under different market scenarios.
impl PnLCalculator for Position
§Position Profit and Loss (PnL) Calculator
This trait implementation provides methods to calculate the profit and loss (PnL) for option positions under different market scenarios.
The implementation offers two main calculations:
- Current PnL based on updated market conditions
- PnL at expiration based on a projected underlying price
These calculations are essential for risk management, position monitoring, and strategy planning in options trading.
Source§fn calculate_pnl(
&self,
underlying_price: &Positive,
expiration_date: ExpirationDate,
implied_volatility: &Positive,
) -> Result<PnL, PricingError>
fn calculate_pnl( &self, underlying_price: &Positive, expiration_date: ExpirationDate, implied_volatility: &Positive, ) -> Result<PnL, PricingError>
Calculates the current unrealized profit and loss for an option position based on updated market conditions.
This method computes the difference between the option’s price at entry and its current theoretical price using the Black-Scholes model. It factors in changes to:
- The underlying asset price
- Time to expiration
- Implied volatility
§Arguments
underlying_price- The current price of the underlying assetexpiration_date- The updated expiration date for the calculationimplied_volatility- The current implied volatility of the option
§Returns
Result<PnL, PricingError>- A PnL object containing unrealized profit/loss and position cost details, or an error if the calculation fails
Source§fn calculate_pnl_at_expiration(
&self,
underlying_price: &Positive,
) -> Result<PnL, PricingError>
fn calculate_pnl_at_expiration( &self, underlying_price: &Positive, ) -> Result<PnL, PricingError>
Calculates the expected profit and loss at option expiration for a given underlying price.
This method determines the realized profit or loss that would occur if the option expires with the underlying at the specified price. It uses intrinsic value calculation at expiration rather than Black-Scholes pricing.
§Arguments
underlying_price- The projected price of the underlying asset at expiration
§Returns
Result<PnL, PricingError>- A PnL object containing realized profit/loss and position cost details, or an error if the calculation fails
Source§fn diff_position_pnl(&self, position: &Position) -> Result<PnL, PricingError>
fn diff_position_pnl(&self, position: &Position) -> Result<PnL, PricingError>
Source§fn adjustments_pnl(
&self,
_adjustments: &DeltaAdjustment,
) -> Result<PnL, PricingError>
fn adjustments_pnl( &self, _adjustments: &DeltaAdjustment, ) -> Result<PnL, PricingError>
Source§impl Profit for Position
Implementation of the Profit trait for the Position struct.
impl Profit for Position
Implementation of the Profit trait for the Position struct.
This allows calculating the profit of a position at a given price by using the position’s profit and loss (PnL) calculation at expiration.
Source§fn calculate_profit_at(&self, price: &Positive) -> Result<Decimal, PricingError>
fn calculate_profit_at(&self, price: &Positive) -> Result<Decimal, PricingError>
Calculates the profit of the position at a specific price.
This method computes the profit or loss that would be realized if the position were to expire with the underlying asset at the specified price.
§Parameters
price- The price at which to calculate the profit, represented as a Positive value.
§Returns
Result<Decimal, PricingError>- The calculated profit as a Decimal if successful, or an error if the calculation fails.
Source§fn get_point_at_price(
&self,
_price: &Positive,
) -> Result<(Decimal, Decimal), PricingError>
fn get_point_at_price( &self, _price: &Positive, ) -> Result<(Decimal, Decimal), PricingError>
impl StructuralPartialEq for Position
Source§impl TradeAble for Position
impl TradeAble for Position
Source§impl TradeStatusAble for Position
impl TradeStatusAble for Position
Source§fn open(&self) -> Result<Trade, TradeError>
fn open(&self) -> Result<Trade, TradeError>
open: Return a Trade instance representing the trade in its open status or a
TradeError if the transition is invalid. Read moreSource§fn close(&self) -> Result<Trade, TradeError>
fn close(&self) -> Result<Trade, TradeError>
closed: Return a Trade instance representing the trade in its closed status or a
TradeError if the transition is invalid. Read moreSource§fn expired(&self) -> Result<Trade, TradeError>
fn expired(&self) -> Result<Trade, TradeError>
expired: Return a Trade instance representing the trade in its expired status or a
TradeError if the transition is invalid. Read moreSource§fn exercised(&self) -> Result<Trade, TradeError>
fn exercised(&self) -> Result<Trade, TradeError>
exercised: Return a Trade instance representing the trade in its exercised status or a
TradeError if the transition is invalid. Read moreSource§fn assigned(&self) -> Result<Trade, TradeError>
fn assigned(&self) -> Result<Trade, TradeError>
assigned: Return a Trade instance representing the trade in its assigned status or a
TradeError if the transition is invalid. Read moreSource§fn status_other(&self) -> Result<Trade, TradeError>
fn status_other(&self) -> Result<Trade, TradeError>
status_other: Return a Trade instance representing undeclared status or a
TradeError if the transition is invalid. Read moreSource§impl TransactionAble for Position
impl TransactionAble for Position
Source§fn add_transaction(
&mut self,
_transaction: Transaction,
) -> Result<(), TransactionError>
fn add_transaction( &mut self, _transaction: Transaction, ) -> Result<(), TransactionError>
Position does not track an internal transaction history.
This impl is intentionally unsupported; callers that need
transaction tracking should store transactions in a
higher-level container.
§Errors
Always returns a TransactionError — this operation is
intentionally unsupported on Position.
Source§fn get_transactions(&self) -> Result<Vec<Transaction>, TransactionError>
fn get_transactions(&self) -> Result<Vec<Transaction>, TransactionError>
See Self::add_transaction — this method is intentionally
unsupported on Position and always errors.
§Errors
Always returns a TransactionError::NotImplemented —
this operation is intentionally unsupported on Position.
Auto Trait Implementations§
impl Freeze 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
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>,
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 moreSource§impl<T> PartialSchema for Twhere
T: ComposeSchema + ?Sized,
impl<T> PartialSchema for Twhere
T: ComposeSchema + ?Sized,
Source§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Scalar for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.