pub struct TestPositionOps<'a, T: Unsigned, const DECIMALS: u8>{ /* private fields */ }Available on crate features
test only.Expand description
Test Position.
Trait Implementations§
Source§impl<T, const DECIMALS: u8> Position<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
impl<T, const DECIMALS: u8> Position<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
Source§type Market = TestMarket<T, DECIMALS>
type Market = TestMarket<T, DECIMALS>
Market type.
Source§fn is_collateral_token_long(&self) -> bool
fn is_collateral_token_long(&self) -> bool
Returns whether the collateral token is the long token of the market.
Source§fn are_pnl_and_collateral_tokens_the_same(&self) -> bool
fn are_pnl_and_collateral_tokens_the_same(&self) -> bool
Returns whether the pnl and collateral tokens are the same.
Source§fn on_validate(&self) -> Result<()>
fn on_validate(&self) -> Result<()>
Called from
validate_position to add supplementary checks.Source§impl<T, const DECIMALS: u8> PositionMut<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
impl<T, const DECIMALS: u8> PositionMut<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
Source§fn market_mut(&mut self) -> &mut Self::Market
fn market_mut(&mut self) -> &mut Self::Market
Get a mutable reference to the market.
Source§fn on_increased(&mut self) -> Result<()>
fn on_increased(&mut self) -> Result<()>
Increased callback.
Source§fn on_decreased(&mut self) -> Result<()>
fn on_decreased(&mut self) -> Result<()>
Decreased callback.
Source§fn on_swapped(
&mut self,
ty: DecreasePositionSwapType,
report: &SwapReport<Self::Num, <Self::Num as Unsigned>::Signed>,
) -> Result<()>
fn on_swapped( &mut self, ty: DecreasePositionSwapType, report: &SwapReport<Self::Num, <Self::Num as Unsigned>::Signed>, ) -> Result<()>
Swapped callback.
Source§fn on_swap_error(
&mut self,
ty: DecreasePositionSwapType,
error: Error,
) -> Result<()>
fn on_swap_error( &mut self, ty: DecreasePositionSwapType, error: Error, ) -> Result<()>
Handle swap error.
Source§impl<T, const DECIMALS: u8> PositionState<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
impl<T, const DECIMALS: u8> PositionState<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
Source§fn collateral_amount(&self) -> &Self::Num
fn collateral_amount(&self) -> &Self::Num
Get the collateral amount.
Source§fn size_in_usd(&self) -> &Self::Num
fn size_in_usd(&self) -> &Self::Num
Get a reference to the size (in USD) of the position.
Source§fn size_in_tokens(&self) -> &Self::Num
fn size_in_tokens(&self) -> &Self::Num
Get a reference to the size (in tokens) of the position.
Source§fn borrowing_factor(&self) -> &Self::Num
fn borrowing_factor(&self) -> &Self::Num
Get a reference to last borrowing factor applied by the position.
Source§fn funding_fee_amount_per_size(&self) -> &Self::Num
fn funding_fee_amount_per_size(&self) -> &Self::Num
Get a reference to the funding fee amount per size.
Source§fn claimable_funding_fee_amount_per_size(
&self,
is_long_collateral: bool,
) -> &Self::Num
fn claimable_funding_fee_amount_per_size( &self, is_long_collateral: bool, ) -> &Self::Num
Get a reference to claimable funding fee amount per size of the given collateral.
Source§impl<T, const DECIMALS: u8> PositionStateMut<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
impl<T, const DECIMALS: u8> PositionStateMut<DECIMALS> for TestPositionOps<'_, T, DECIMALS>
Source§fn collateral_amount_mut(&mut self) -> &mut Self::Num
fn collateral_amount_mut(&mut self) -> &mut Self::Num
Get a mutable reference to the collateral amount.
Source§fn size_in_usd_mut(&mut self) -> &mut Self::Num
fn size_in_usd_mut(&mut self) -> &mut Self::Num
Get a mutable reference to the size (in USD) of the position.
Source§fn size_in_tokens_mut(&mut self) -> &mut Self::Num
fn size_in_tokens_mut(&mut self) -> &mut Self::Num
Get a mutable reference to the size (in tokens) of the position.
Source§fn borrowing_factor_mut(&mut self) -> &mut Self::Num
fn borrowing_factor_mut(&mut self) -> &mut Self::Num
Get a mutable reference to last borrowing factor applied by the position.
Source§fn funding_fee_amount_per_size_mut(&mut self) -> &mut Self::Num
fn funding_fee_amount_per_size_mut(&mut self) -> &mut Self::Num
Get a mutable reference to the funding fee amount per size.
Source§fn claimable_funding_fee_amount_per_size_mut(
&mut self,
is_long_collateral: bool,
) -> &mut Self::Num
fn claimable_funding_fee_amount_per_size_mut( &mut self, is_long_collateral: bool, ) -> &mut Self::Num
Get a mutable reference to claimable funding fee amount per size of the given collateral.
Auto Trait Implementations§
impl<'a, T, const DECIMALS: u8> Freeze for TestPositionOps<'a, T, DECIMALS>
impl<'a, T, const DECIMALS: u8> RefUnwindSafe for TestPositionOps<'a, T, DECIMALS>
impl<'a, T, const DECIMALS: u8> Send for TestPositionOps<'a, T, DECIMALS>
impl<'a, T, const DECIMALS: u8> Sync for TestPositionOps<'a, T, DECIMALS>
impl<'a, T, const DECIMALS: u8> Unpin for TestPositionOps<'a, T, DECIMALS>
impl<'a, T, const DECIMALS: u8> !UnwindSafe for TestPositionOps<'a, T, DECIMALS>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<const DECIMALS: u8, P> PositionExt<DECIMALS> for Pwhere
P: Position<DECIMALS>,
impl<const DECIMALS: u8, P> PositionExt<DECIMALS> for Pwhere
P: Position<DECIMALS>,
Source§fn 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. Read moreSource§fn 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.
Source§fn collateral_value(&self, prices: &Prices<Self::Num>) -> Result<Self::Num>
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)>
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. Read more
Source§fn 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.
Source§fn check_liquidatable(
&self,
prices: &Prices<Self::Num>,
should_validate_min_collateral_usd: bool,
for_liquidation: bool,
) -> Result<Option<LiquidatableReason>>
fn check_liquidatable( &self, prices: &Prices<Self::Num>, should_validate_min_collateral_usd: bool, for_liquidation: bool, ) -> Result<Option<LiquidatableReason>>
Check if the position is liquidatable. Read more
Source§fn position_price_impact(
&self,
size_delta_usd: &Self::Signed,
include_virtual_inventory_impact: bool,
) -> Result<PriceImpact<Self::Signed>>
fn position_price_impact( &self, size_delta_usd: &Self::Signed, include_virtual_inventory_impact: bool, ) -> Result<PriceImpact<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,
include_virtual_inventory_impact: bool,
) -> Result<PriceImpact<Self::Signed>>
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>>
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)>
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)>
Get capped position price impact usd. Read more
Source§fn 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.
Source§fn pending_funding_fees(&self) -> Result<FundingFees<Self::Num>>
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,
balance_change: BalanceChange,
is_liquidation: bool,
) -> Result<PositionFees<Self::Num>>
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>>
Calculates the
PositionFees generated by changing the position size by the specified size_delta_usd.