Trait BaseMarketExt

Source
pub trait BaseMarketExt<const DECIMALS: u8>: BaseMarket<DECIMALS> {
Show 14 methods // Provided methods fn pool_value_without_pnl_for_one_side( &self, prices: &Prices<Self::Num>, is_long: bool, maximize: bool, ) -> Result<Self::Num> { ... } fn open_interest(&self) -> Result<Merged<&Self::Pool, &Self::Pool>> { ... } fn open_interest_in_tokens( &self, ) -> Result<Merged<&Self::Pool, &Self::Pool>> { ... } fn pnl( &self, index_token_price: &Price<Self::Num>, is_long: bool, maximize: bool, ) -> Result<Self::Signed> { ... } fn pnl_factor_with_pool_value( &self, prices: &Prices<Self::Num>, is_long: bool, maximize: bool, ) -> Result<(Self::Signed, Self::Num)> { ... } fn pnl_factor( &self, prices: &Prices<Self::Num>, is_long: bool, maximize: bool, ) -> Result<Self::Signed> { ... } fn validate_pool_amount(&self, is_long_token: bool) -> Result<()> { ... } fn pnl_factor_exceeded( &self, prices: &Prices<Self::Num>, kind: PnlFactorKind, is_long: bool, ) -> Result<Option<PnlFactorExceeded<Self::Num>>> { ... } fn validate_pnl_factor( &self, prices: &Prices<Self::Num>, kind: PnlFactorKind, is_long: bool, ) -> Result<()> { ... } fn validate_max_pnl( &self, prices: &Prices<Self::Num>, long_kind: PnlFactorKind, short_kind: PnlFactorKind, ) -> Result<()> { ... } fn reserved_value( &self, index_token_price: &Price<Self::Num>, is_long: bool, ) -> Result<Self::Num> { ... } fn validate_reserve( &self, prices: &Prices<Self::Num>, is_long: bool, ) -> Result<()> { ... } fn expected_min_token_balance_excluding_collateral_amount_for_one_token_side( &self, is_long_side: bool, ) -> Result<Self::Num> { ... } fn total_collateral_amount_for_one_token_side( &self, is_long_side: bool, ) -> Result<Self::Num> { ... }
}
Expand description

Extension trait for BaseMarket.

Provided Methods§

Source

fn pool_value_without_pnl_for_one_side( &self, prices: &Prices<Self::Num>, is_long: bool, maximize: bool, ) -> Result<Self::Num>

Get the usd value of primary pool without pnl for one side.

Source

fn open_interest(&self) -> Result<Merged<&Self::Pool, &Self::Pool>>

Get total open interest as a Balance.

Source

fn open_interest_in_tokens(&self) -> Result<Merged<&Self::Pool, &Self::Pool>>

Get total open interest in tokens as a merged Balance.

The long amount is the total long open interest in tokens, while the short amount is the total short open interest in tokens.

Source

fn pnl( &self, index_token_price: &Price<Self::Num>, is_long: bool, maximize: bool, ) -> Result<Self::Signed>

Get total pnl of the market for one side.

Source

fn pnl_factor_with_pool_value( &self, prices: &Prices<Self::Num>, is_long: bool, maximize: bool, ) -> Result<(Self::Signed, Self::Num)>

Get pnl factor with pool value.

Source

fn pnl_factor( &self, prices: &Prices<Self::Num>, is_long: bool, maximize: bool, ) -> Result<Self::Signed>

Get pnl factor.

Source

fn validate_pool_amount(&self, is_long_token: bool) -> Result<()>

Validate (primary) pool amount.

Source

fn pnl_factor_exceeded( &self, prices: &Prices<Self::Num>, kind: PnlFactorKind, is_long: bool, ) -> Result<Option<PnlFactorExceeded<Self::Num>>>

Get the excess of pending pnl.

Return Some if the pnl factor is exceeded the given kind of pnl factor.

Source

fn validate_pnl_factor( &self, prices: &Prices<Self::Num>, kind: PnlFactorKind, is_long: bool, ) -> Result<()>

Validate pnl factor.

Source

fn validate_max_pnl( &self, prices: &Prices<Self::Num>, long_kind: PnlFactorKind, short_kind: PnlFactorKind, ) -> Result<()>

Validate max pnl.

Source

fn reserved_value( &self, index_token_price: &Price<Self::Num>, is_long: bool, ) -> Result<Self::Num>

Get reserved value.

Source

fn validate_reserve( &self, prices: &Prices<Self::Num>, is_long: bool, ) -> Result<()>

Validate reserve.

Source

fn expected_min_token_balance_excluding_collateral_amount_for_one_token_side( &self, is_long_side: bool, ) -> Result<Self::Num>

Expected min token balance excluding collateral amount.

§Notes

Note that “one token side” here means calculating based on half of the side. For markets where the long token and short token are different, there is no ambiguity. However, if the long token and short token are the same, choosing the long token side will result in a value that is not actually the total amount of the long token, but rather the total amount belonging to the long token side (often only half of it).

For example, if both the long token and the short token are WSOL, and the liquidity pool has a total of 1000 WSOL. Then, in a typical pool implementation, the long token side of the liquidity pool has only 500 WSOL, while the short token side also has 500 WSOL. In this case, this function will only consider one side, taking into account only 500 WSOL in the calculation.

Source

fn total_collateral_amount_for_one_token_side( &self, is_long_side: bool, ) -> Result<Self::Num>

Get total collateral amount for one token side.

§Notes

Note that “one token side” here means calculating based on half of the side. (See also expected_min_token_balance_excluding_collateral_amount_for_one_token_side).

Implementors§

Source§

impl<M: BaseMarket<DECIMALS> + ?Sized, const DECIMALS: u8> BaseMarketExt<DECIMALS> for M