Trait PositionExt

Source
pub trait PositionExt<const DECIMALS: u8>: Position<DECIMALS> {
    // Provided methods
    fn will_collateral_be_sufficient(
        &self,
        prices: &Prices<Self::Num>,
        delta: &CollateralDelta<Self::Num>,
    ) -> Result<WillCollateralBeSufficient<Self::Signed>> { ... }
    fn collateral_price<'a>(
        &self,
        prices: &'a Prices<Self::Num>,
    ) -> &'a Price<Self::Num> { ... }
    fn collateral_value(&self, prices: &Prices<Self::Num>) -> Result<Self::Num> { ... }
    fn pnl_value(
        &self,
        prices: &Prices<Self::Num>,
        size_delta_usd: &Self::Num,
    ) -> Result<(Self::Signed, Self::Signed, Self::Num)> { ... }
    fn validate(
        &self,
        prices: &Prices<Self::Num>,
        should_validate_min_position_size: bool,
        should_validate_min_collateral_usd: bool,
    ) -> Result<()> { ... }
    fn check_liquidatable(
        &self,
        prices: &Prices<Self::Num>,
        should_validate_min_collateral_usd: bool,
    ) -> Result<Option<LiquidatableReason>> { ... }
    fn position_price_impact(
        &self,
        size_delta_usd: &Self::Signed,
    ) -> Result<Self::Signed> { ... }
    fn capped_positive_position_price_impact(
        &self,
        index_token_price: &Price<Self::Num>,
        size_delta_usd: &Self::Signed,
    ) -> Result<Self::Signed> { ... }
    fn capped_position_price_impact(
        &self,
        index_token_price: &Price<Self::Num>,
        size_delta_usd: &Self::Signed,
    ) -> Result<(Self::Signed, Self::Num)> { ... }
    fn pending_borrowing_fee_value(&self) -> Result<Self::Num> { ... }
    fn pending_funding_fees(&self) -> Result<FundingFees<Self::Num>> { ... }
    fn position_fees(
        &self,
        collateral_token_price: &Price<Self::Num>,
        size_delta_usd: &Self::Num,
        is_positive_impact: bool,
        is_liquidation: bool,
    ) -> Result<PositionFees<Self::Num>> { ... }
}
Expand description

Extension trait for Position with utils.

Provided Methods§

Source

fn will_collateral_be_sufficient( &self, prices: &Prices<Self::Num>, delta: &CollateralDelta<Self::Num>, ) -> Result<WillCollateralBeSufficient<Self::Signed>>

Check that whether the collateral will be sufficient after paying the given realized_pnl and applying delta_size.

  • Returns the remaining collateral value if sufficient, None otherwise.
  • Returns Err if failed to finish the calculation.
Source

fn collateral_price<'a>( &self, prices: &'a Prices<Self::Num>, ) -> &'a Price<Self::Num>

Get collateral price.

Source

fn collateral_value(&self, prices: &Prices<Self::Num>) -> Result<Self::Num>

Get collateral value.

Source

fn pnl_value( &self, prices: &Prices<Self::Num>, size_delta_usd: &Self::Num, ) -> Result<(Self::Signed, Self::Signed, Self::Num)>

Calculate the pnl value when decreased by the given delta size.

Returns (pnl_value, uncapped_pnl_value, size_delta_in_tokens)

Source

fn validate( &self, prices: &Prices<Self::Num>, should_validate_min_position_size: bool, should_validate_min_collateral_usd: bool, ) -> Result<()>

Validate the position.

Source

fn check_liquidatable( &self, prices: &Prices<Self::Num>, should_validate_min_collateral_usd: bool, ) -> Result<Option<LiquidatableReason>>

Check if the position is liquidatable.

Return LiquidatableReason if it is liquidatable, None otherwise.

Source

fn position_price_impact( &self, size_delta_usd: &Self::Signed, ) -> Result<Self::Signed>

Get position price impact.

Source

fn capped_positive_position_price_impact( &self, index_token_price: &Price<Self::Num>, size_delta_usd: &Self::Signed, ) -> Result<Self::Signed>

Get position price impact usd and cap the value if it is positive.

Source

fn capped_position_price_impact( &self, index_token_price: &Price<Self::Num>, size_delta_usd: &Self::Signed, ) -> Result<(Self::Signed, Self::Num)>

Get capped position price impact usd.

Compare to PositionExt::capped_positive_position_price_impact, this method will also cap the negative impact and return the difference before capping.

Source

fn pending_borrowing_fee_value(&self) -> Result<Self::Num>

Get pending borrowing fee value of this position.

Source

fn pending_funding_fees(&self) -> Result<FundingFees<Self::Num>>

Get pending funding fees.

Source

fn position_fees( &self, collateral_token_price: &Price<Self::Num>, size_delta_usd: &Self::Num, is_positive_impact: bool, is_liquidation: bool, ) -> Result<PositionFees<Self::Num>>

Calculates the PositionFees generated by changing the position size by the specified size_delta_usd.

Implementors§

Source§

impl<const DECIMALS: u8, P: Position<DECIMALS>> PositionExt<DECIMALS> for P