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§
Sourcefn max_trade_size(
&self,
user: &Pubkey,
market: MarketId,
trade_side: PositionDirection,
) -> SdkResult<u64>
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 accountmarket
- the market to tradetrade_side
- the direction of the trade
Returns max USDC trade size (PRICE_PRECISION)
fn calculate_perp_buying_power( &self, user: &User, market: &PerpMarket, oracle_price: i64, collateral_buffer: u64, ) -> SdkResult<u128>
Sourcefn calculate_margin_info(&self, user: &User) -> SdkResult<MarginCalculation>
fn calculate_margin_info(&self, user: &User) -> SdkResult<MarginCalculation>
Calculate the user’s live margin information