Trait UserMargin

Source
pub trait UserMargin {
    // Required methods
    fn max_trade_size(
        &self,
        user: &Pubkey,
        market: MarketId,
        trade_side: PositionDirection,
    ) -> SdkResult<u64>;
    fn calculate_perp_buying_power(
        &self,
        user: &User,
        market: &PerpMarket,
        oracle_price: i64,
        collateral_buffer: u64,
    ) -> SdkResult<u128>;
    fn calculate_margin_info(&self, user: &User) -> SdkResult<MarginCalculation>;
}
Expand description

Provides margin calculation helpers for User accounts

sync, requires client is subscribed to necessary markets beforehand

Required Methods§

Source

fn max_trade_size( &self, user: &Pubkey, market: MarketId, trade_side: PositionDirection, ) -> SdkResult<u64>

Calculate user’s max. trade size in USDC for a given market and direction

  • user - the user account
  • market - the market to trade
  • trade_side - the direction of the trade

Returns max USDC trade size (PRICE_PRECISION)

Source

fn calculate_perp_buying_power( &self, user: &User, market: &PerpMarket, oracle_price: i64, collateral_buffer: u64, ) -> SdkResult<u128>

Source

fn calculate_margin_info(&self, user: &User) -> SdkResult<MarginCalculation>

Calculate the user’s live margin information

Implementors§