pub enum PositionError {
StrategyError(StrategyErrorKind),
ValidationError(PositionValidationErrorKind),
LimitError(PositionLimitErrorKind),
UpdateError(PositionUpdateErrorKind),
DecimalError(DecimalError),
PositiveError(PositiveError),
Options(OptionsError),
}Expand description
Represents errors that can occur when managing positions in strategies
This enum provides a top-level categorization of position-related errors, grouping them by their source or nature. It helps with routing errors to appropriate handlers and providing context-aware error messages.
§Variants
-
StrategyError- Errors related to strategy operations such as configuration issues or capacity limitations. -
ValidationError- Errors related to position validation including issues with size, price, or compatibility with strategy requirements. -
LimitError- Errors related to position limits such as maximum number of positions or maximum exposure thresholds.
§Usage
This error type is typically used in trading systems where positions need to be validated, managed, and executed within the context of trading strategies.
Variants§
StrategyError(StrategyErrorKind)
Errors related to strategy operations
ValidationError(PositionValidationErrorKind)
Errors related to position validation
LimitError(PositionLimitErrorKind)
Errors related to position limits
UpdateError(PositionUpdateErrorKind)
Error during position update
This variant is triggered when attempts to update option position parameters or data fail. Errors related to position update
DecimalError(DecimalError)
Decimal arithmetic failures propagated from monetary-flow computations (overflow, division by zero, conversion).
Produced when a checked Decimal helper in model::decimal
surfaces a crate::error::DecimalError from inside a
Position method (for example pnl_at_expiration or
unrealized_pnl). Propagated transparently via the
#[from] cascade so callers keep matching PositionError.
PositiveError(PositiveError)
Positive arithmetic failures propagated from cost and fee
computations (overflow, division by zero, broken positivity
invariant).
Produced when a checked Positive helper surfaces a
positive::PositiveError from inside a Position method (for
example total_cost or fees, where the premium and the fees are
accumulated and then scaled by the contract quantity). Propagated
transparently via the #[from] cascade so callers keep matching
PositionError.
Options(OptionsError)
Contract-level failures propagated from the option the position holds.
Produced when Options::intrinsic_value surfaces an
crate::error::OptionsError inside a Position or Leg P&L
method. Both types are core-owned, so the position layer reports a
contract failure with its own error instead of borrowing the pricing
layer’s (roadmap M1-10).
Implementations§
Source§impl PositionError
Factory methods for creating position-related errors
impl PositionError
Factory methods for creating position-related errors
This implementation provides a set of convenience factory methods for creating different types of position errors. These methods create properly structured error instances with clear, descriptive information about what went wrong.
§Methods
These factory methods simplify error creation throughout the codebase and ensure that errors have consistent formatting and information.
Sourcepub fn unsupported_operation(strategy_type: &str, operation: &str) -> Self
pub fn unsupported_operation(strategy_type: &str, operation: &str) -> Self
Creates an error for operations not supported by a specific strategy type
§Parameters
strategy_type- The name or identifier of the strategy that doesn’t support the operationoperation- The name of the unsupported operation that was attempted
§Returns
A PositionError::StrategyError variant with UnsupportedOperation details
Sourcepub fn strategy_full(strategy_type: &str, max_positions: usize) -> Self
pub fn strategy_full(strategy_type: &str, max_positions: usize) -> Self
Creates an error when a strategy has reached its maximum position capacity
§Parameters
strategy_type- The name or identifier of the strategy that is at capacitymax_positions- The maximum number of positions the strategy can hold
§Returns
A PositionError::StrategyError variant with StrategyFull details
Sourcepub fn invalid_position_size(size: f64, reason: &str) -> Self
pub fn invalid_position_size(size: f64, reason: &str) -> Self
Sourcepub fn invalid_position_type(position_side: Side, reason: String) -> Self
pub fn invalid_position_type(position_side: Side, reason: String) -> Self
Sourcepub fn invalid_position_style(style: OptionStyle, reason: String) -> Self
pub fn invalid_position_style(style: OptionStyle, reason: String) -> Self
Sourcepub fn invalid_position(reason: &str) -> Self
pub fn invalid_position(reason: &str) -> Self
Sourcepub fn invalid_position_update(field: String, reason: String) -> Self
pub fn invalid_position_update(field: String, reason: String) -> Self
Trait Implementations§
Source§impl Debug for PositionError
impl Debug for PositionError
Source§impl Display for PositionError
impl Display for PositionError
Source§impl Error for PositionError
impl Error for PositionError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()