Skip to main content

PositionError

Enum PositionError 

Source
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

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.

Source

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 operation
  • operation - The name of the unsupported operation that was attempted
§Returns

A PositionError::StrategyError variant with UnsupportedOperation details

Source

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 capacity
  • max_positions - The maximum number of positions the strategy can hold
§Returns

A PositionError::StrategyError variant with StrategyFull details

Source

pub fn invalid_position_size(size: f64, reason: &str) -> Self

Creates an error for invalid position size values

§Parameters
  • size - The invalid position size value
  • reason - A description of why the size is invalid
§Returns

A PositionError::ValidationError variant with InvalidSize details

Source

pub fn invalid_position_type(position_side: Side, reason: String) -> Self

Creates an error for incompatible position side/direction

§Parameters
  • position_side - The position side (Long or Short) that is incompatible
  • reason - A description of why the position side is incompatible
§Returns

A PositionError::ValidationError variant with IncompatibleSide details

Source

pub fn invalid_position_style(style: OptionStyle, reason: String) -> Self

Creates an error for incompatible option style

§Parameters
  • style - The option style (Call or Put) that is incompatible
  • reason - A description of why the option style is incompatible
§Returns

A PositionError::ValidationError variant with IncompatibleStyle details

Source

pub fn invalid_position(reason: &str) -> Self

Creates a generic invalid position error

§Parameters
  • reason - A description of why the position is invalid
§Returns

A PositionError::ValidationError variant with InvalidPosition details

Source

pub fn invalid_position_update(field: String, reason: String) -> Self

Creates an error for invalid position update

§Parameters
  • field - The option position field that failed to update
  • reason - A description of why the option position field failed to update
§Returns

A PositionError::UpdateError variant with PositionFieldUpdateFailure details

Trait Implementations§

Source§

impl Debug for PositionError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PositionError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for PositionError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<DecimalError> for PositionError

Source§

fn from(source: DecimalError) -> Self

Converts to this type from the input type.
Source§

impl From<OptionsError> for PositionError

Source§

fn from(source: OptionsError) -> Self

Converts to this type from the input type.
Source§

impl From<PositiveError> for PositionError

Source§

fn from(source: PositiveError) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more