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 assetFuture- Exchange-traded futures contractPerpetual- 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
impl Leg
Sourcepub fn spot(position: SpotPosition) -> Self
pub fn spot(position: SpotPosition) -> Self
Creates a new spot leg from a SpotPosition.
Sourcepub fn future(position: FuturePosition) -> Self
pub fn future(position: FuturePosition) -> Self
Creates a new future leg from a FuturePosition.
Sourcepub fn perpetual(position: PerpetualPosition) -> Self
pub fn perpetual(position: PerpetualPosition) -> Self
Creates a new perpetual leg from a PerpetualPosition.
Sourcepub fn is_perpetual(&self) -> bool
pub fn is_perpetual(&self) -> bool
Returns true if this is a perpetual leg.
Sourcepub fn is_linear(&self) -> bool
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.
Sourcepub fn is_derivative(&self) -> bool
pub fn is_derivative(&self) -> bool
Returns true if this is a derivative (option, future, perpetual).
Sourcepub fn is_margined(&self) -> bool
pub fn is_margined(&self) -> bool
Returns true if this leg has margin requirements.
Sourcepub fn has_expiration(&self) -> bool
pub fn has_expiration(&self) -> bool
Returns true if this leg has an expiration date.
Sourcepub fn as_option(&self) -> Option<&Position>
pub fn as_option(&self) -> Option<&Position>
Returns the underlying option position if this is an Option leg.
Sourcepub fn as_spot(&self) -> Option<&SpotPosition>
pub fn as_spot(&self) -> Option<&SpotPosition>
Returns the underlying spot position if this is a Spot leg.
Sourcepub fn as_future(&self) -> Option<&FuturePosition>
pub fn as_future(&self) -> Option<&FuturePosition>
Returns the underlying future position if this is a Future leg.
Sourcepub fn as_perpetual(&self) -> Option<&PerpetualPosition>
pub fn as_perpetual(&self) -> Option<&PerpetualPosition>
Returns the underlying perpetual position if this is a Perpetual leg.
Sourcepub fn as_option_mut(&mut self) -> Option<&mut Position>
pub fn as_option_mut(&mut self) -> Option<&mut Position>
Returns a mutable reference to the underlying option position.
Sourcepub fn as_spot_mut(&mut self) -> Option<&mut SpotPosition>
pub fn as_spot_mut(&mut self) -> Option<&mut SpotPosition>
Returns a mutable reference to the underlying spot position.
Sourcepub fn as_future_mut(&mut self) -> Option<&mut FuturePosition>
pub fn as_future_mut(&mut self) -> Option<&mut FuturePosition>
Returns a mutable reference to the underlying future position.
Sourcepub fn as_perpetual_mut(&mut self) -> Option<&mut PerpetualPosition>
pub fn as_perpetual_mut(&mut self) -> Option<&mut PerpetualPosition>
Returns a mutable reference to the underlying perpetual position.
Sourcepub fn leg_type_name(&self) -> &'static str
pub fn leg_type_name(&self) -> &'static str
Returns a string describing the leg type.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Leg
impl<'de> Deserialize<'de> for Leg
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 From<FuturePosition> for Leg
impl From<FuturePosition> for Leg
Source§fn from(position: FuturePosition) -> Self
fn from(position: FuturePosition) -> Self
Source§impl From<PerpetualPosition> for Leg
impl From<PerpetualPosition> for Leg
Source§fn from(position: PerpetualPosition) -> Self
fn from(position: PerpetualPosition) -> Self
Source§impl From<SpotPosition> for Leg
impl From<SpotPosition> for Leg
Source§fn from(position: SpotPosition) -> Self
fn from(position: SpotPosition) -> Self
Source§impl LegAble for Leg
impl LegAble for Leg
Source§fn notional_value(&self, price: Positive) -> Result<Positive, PositionError>
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).