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§
Sourcefn will_collateral_be_sufficient(
&self,
prices: &Prices<Self::Num>,
delta: &CollateralDelta<Self::Num>,
) -> Result<WillCollateralBeSufficient<Self::Signed>>
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.
Sourcefn collateral_price<'a>(
&self,
prices: &'a Prices<Self::Num>,
) -> &'a Price<Self::Num>
fn collateral_price<'a>( &self, prices: &'a Prices<Self::Num>, ) -> &'a Price<Self::Num>
Get collateral price.
Sourcefn collateral_value(&self, prices: &Prices<Self::Num>) -> Result<Self::Num>
fn collateral_value(&self, prices: &Prices<Self::Num>) -> Result<Self::Num>
Get collateral value.
Sourcefn pnl_value(
&self,
prices: &Prices<Self::Num>,
size_delta_usd: &Self::Num,
) -> Result<(Self::Signed, Self::Signed, Self::Num)>
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)
Sourcefn validate(
&self,
prices: &Prices<Self::Num>,
should_validate_min_position_size: bool,
should_validate_min_collateral_usd: bool,
) -> Result<()>
fn validate( &self, prices: &Prices<Self::Num>, should_validate_min_position_size: bool, should_validate_min_collateral_usd: bool, ) -> Result<()>
Validate the position.
Sourcefn check_liquidatable(
&self,
prices: &Prices<Self::Num>,
should_validate_min_collateral_usd: bool,
) -> Result<Option<LiquidatableReason>>
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.
Sourcefn position_price_impact(
&self,
size_delta_usd: &Self::Signed,
) -> Result<Self::Signed>
fn position_price_impact( &self, size_delta_usd: &Self::Signed, ) -> Result<Self::Signed>
Get position price impact.
Sourcefn capped_positive_position_price_impact(
&self,
index_token_price: &Price<Self::Num>,
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>
Get position price impact usd and cap the value if it is positive.
Sourcefn capped_position_price_impact(
&self,
index_token_price: &Price<Self::Num>,
size_delta_usd: &Self::Signed,
) -> Result<(Self::Signed, Self::Num)>
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.
Sourcefn pending_borrowing_fee_value(&self) -> Result<Self::Num>
fn pending_borrowing_fee_value(&self) -> Result<Self::Num>
Get pending borrowing fee value of this position.
Sourcefn pending_funding_fees(&self) -> Result<FundingFees<Self::Num>>
fn pending_funding_fees(&self) -> Result<FundingFees<Self::Num>>
Get pending funding fees.
Sourcefn 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>>
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
.