PositionExt

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>, Error> { ... }
    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, Error> { ... }
    fn pnl_value(
        &self,
        prices: &Prices<Self::Num>,
        size_delta_usd: &Self::Num,
    ) -> Result<(Self::Signed, Self::Signed, Self::Num), Error> { ... }
    fn validate(
        &self,
        prices: &Prices<Self::Num>,
        should_validate_min_position_size: bool,
        should_validate_min_collateral_usd: bool,
    ) -> Result<(), Error> { ... }
    fn check_liquidatable(
        &self,
        prices: &Prices<Self::Num>,
        should_validate_min_collateral_usd: bool,
        for_liquidation: bool,
    ) -> Result<Option<LiquidatableReason>, Error> { ... }
    fn position_price_impact(
        &self,
        size_delta_usd: &Self::Signed,
        include_virtual_inventory_impact: bool,
    ) -> Result<PriceImpact<Self::Signed>, Error> { ... }
    fn capped_positive_position_price_impact(
        &self,
        index_token_price: &Price<Self::Num>,
        size_delta_usd: &Self::Signed,
        include_virtual_inventory_impact: bool,
    ) -> Result<PriceImpact<Self::Signed>, Error> { ... }
    fn capped_position_price_impact(
        &self,
        index_token_price: &Price<Self::Num>,
        size_delta_usd: &Self::Signed,
        include_virtual_inventory_impact: bool,
    ) -> Result<(PriceImpact<Self::Signed>, Self::Num), Error> { ... }
    fn pending_borrowing_fee_value(&self) -> Result<Self::Num, Error> { ... }
    fn pending_funding_fees(&self) -> Result<FundingFees<Self::Num>, Error> { ... }
    fn position_fees(
        &self,
        collateral_token_price: &Price<Self::Num>,
        size_delta_usd: &Self::Num,
        balance_change: BalanceChange,
        is_liquidation: bool,
    ) -> Result<PositionFees<Self::Num>, Error> { ... }
}
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>, Error>

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, Error>

Get collateral value.

Source

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

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<(), Error>

Validate the position.

Source

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

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, include_virtual_inventory_impact: bool, ) -> Result<PriceImpact<Self::Signed>, Error>

Get position price impact.

Source

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

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, include_virtual_inventory_impact: bool, ) -> Result<(PriceImpact<Self::Signed>, Self::Num), Error>

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, Error>

Get pending borrowing fee value of this position.

Source

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

Get pending funding fees.

Source

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

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

Implementors§

Source§

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