Skip to main content

Leg

Enum Leg 

Source
pub enum Leg {
    Option(Box<Position>),
    Spot(SpotPosition),
    Future(FuturePosition),
    Perpetual(PerpetualPosition),
}
Expand description

Represents different types of legs in a trading strategy.

This enum provides a unified interface for handling various instrument types in multi-leg strategies, enabling strategies like Covered Call (spot + option), Cash & Carry (spot + perpetual), and other combinations.

§Variants

  • Option - Standard option position (Call or Put)
  • Spot - Direct ownership of underlying asset
  • Future - Exchange-traded futures contract
  • Perpetual - Crypto perpetual swap contract

Variants§

§

Option(Box<Position>)

Standard option position (Call/Put).

§

Spot(SpotPosition)

Spot/underlying asset position.

§

Future(FuturePosition)

Exchange-traded futures contract.

§

Perpetual(PerpetualPosition)

Crypto perpetual swap contract.

Implementations§

Source§

impl Leg

Source

pub fn option(position: Position) -> Self

Creates a new option leg from a Position.

Source

pub fn spot(position: SpotPosition) -> Self

Creates a new spot leg from a SpotPosition.

Source

pub fn future(position: FuturePosition) -> Self

Creates a new future leg from a FuturePosition.

Source

pub fn perpetual(position: PerpetualPosition) -> Self

Creates a new perpetual leg from a PerpetualPosition.

Source

pub fn is_option(&self) -> bool

Returns true if this is an option leg.

Source

pub fn is_spot(&self) -> bool

Returns true if this is a spot leg.

Source

pub fn is_future(&self) -> bool

Returns true if this is a future leg.

Source

pub fn is_perpetual(&self) -> bool

Returns true if this is a perpetual leg.

Source

pub fn is_linear(&self) -> bool

Returns true if this is a linear instrument (spot, future, perpetual).

Linear instruments have constant delta and zero gamma.

Source

pub fn is_derivative(&self) -> bool

Returns true if this is a derivative (option, future, perpetual).

Source

pub fn is_margined(&self) -> bool

Returns true if this leg has margin requirements.

Source

pub fn has_expiration(&self) -> bool

Returns true if this leg has an expiration date.

Source

pub fn as_option(&self) -> Option<&Position>

Returns the underlying option position if this is an Option leg.

Source

pub fn as_spot(&self) -> Option<&SpotPosition>

Returns the underlying spot position if this is a Spot leg.

Source

pub fn as_future(&self) -> Option<&FuturePosition>

Returns the underlying future position if this is a Future leg.

Source

pub fn as_perpetual(&self) -> Option<&PerpetualPosition>

Returns the underlying perpetual position if this is a Perpetual leg.

Source

pub fn as_option_mut(&mut self) -> Option<&mut Position>

Returns a mutable reference to the underlying option position.

Source

pub fn as_spot_mut(&mut self) -> Option<&mut SpotPosition>

Returns a mutable reference to the underlying spot position.

Source

pub fn as_future_mut(&mut self) -> Option<&mut FuturePosition>

Returns a mutable reference to the underlying future position.

Source

pub fn as_perpetual_mut(&mut self) -> Option<&mut PerpetualPosition>

Returns a mutable reference to the underlying perpetual position.

Source

pub fn leg_type_name(&self) -> &'static str

Returns a string describing the leg type.

Trait Implementations§

Source§

impl Clone for Leg

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl ComposeSchema for Leg

Source§

impl Debug for Leg

Source§

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

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

impl<'de> Deserialize<'de> for Leg

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Leg

Source§

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

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

impl From<FuturePosition> for Leg

Source§

fn from(position: FuturePosition) -> Self

Converts to this type from the input type.
Source§

impl From<PerpetualPosition> for Leg

Source§

fn from(position: PerpetualPosition) -> Self

Converts to this type from the input type.
Source§

impl From<Position> for Leg

Source§

fn from(position: Position) -> Self

Converts to this type from the input type.
Source§

impl From<SpotPosition> for Leg

Source§

fn from(position: SpotPosition) -> Self

Converts to this type from the input type.
Source§

impl LegAble for Leg

Source§

fn notional_value(&self, price: Positive) -> Result<Positive, PositionError>

Notional value at price. An option leg covers quantity × contract_size units of the underlying, so its notional is that size times price; the other legs keep quantity × price.

§Errors

Returns PositionError::PositiveError when the product leaves the Positive range (#788).

Source§

fn get_symbol(&self) -> &str

Returns the symbol/ticker of the underlying instrument.
Source§

fn get_quantity(&self) -> Positive

Returns the position quantity in the leg’s native unit (#830). Read more
Source§

fn get_side(&self) -> Side

Returns the position side (Long or Short).
Source§

fn pnl_at_price(&self, price: Positive) -> Result<Decimal, PositionError>

Calculates the profit/loss at a given price. Read more
Source§

fn total_cost(&self) -> Result<Positive, PositionError>

Returns the total cost to establish this position. Read more
Source§

fn fees(&self) -> Result<Positive, PositionError>

Returns the total fees associated with this position. Read more
Source§

fn is_long(&self) -> bool

Checks if this is a long position.
Source§

fn is_short(&self) -> bool

Checks if this is a short position.
Source§

impl PartialEq for Leg

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Leg

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Leg

Source§

impl ToSchema for Leg

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Leg

§

impl RefUnwindSafe for Leg

§

impl Send for Leg

§

impl Sync for Leg

§

impl Unpin for Leg

§

impl UnsafeUnpin for Leg

§

impl UnwindSafe for Leg

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> PartialSchema for T
where T: ComposeSchema + ?Sized,

Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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