Margin Modes
Drift Protocol supports two margin modes:sdk/src/types.ts
Cross-Margin (Default)
Cross-margin mode pools all collateral across positions:- All deposits act as collateral for all positions
- Unrealized PnL contributes to margin (with haircuts)
- Most capital efficient for diversified portfolios
- Default mode for all users
Isolated Margin
Isolated margin uses dedicated collateral per position:- Only available for
ISOLATEDtier markets - Separate collateral pool per isolated position
- No cross-contamination of risk
- Introduced in v2.154.0
Margin Calculation
Margin health is determined by comparing total collateral to margin requirements.Total Collateral
Total collateral is the sum of:- Spot Deposits (weighted by asset weight)
- Unrealized Perp PnL (positive, with haircuts)
- Unsettled Perp PnL (positive, settled but not withdrawn)
Margin Requirement
Margin requirement is the sum of:- Perp Position Margin (based on position size and market tier)
- Spot Borrows (weighted by liability weight)
- Open Order Margins (reserved margin for open orders)
- Unrealized Perp PnL (negative, with liability weights)
Margin Ratio Types
Initial Margin: Required to open new positions- Initial: Higher requirement, used when opening/increasing positions
- Maintenance: Lower requirement, determines liquidation threshold
Health Check
Size-Based Margin Scaling
Both perp and spot positions have size-based margin scaling using the IMF (Initial Margin Fraction) factor:Perp Position Margin
sdk/src/math/margin.ts
Spot Liability Weight
Borrows also scale with size:Spot Asset Weight Discount
Large deposits receive a discounted asset weight:sdk/src/math/margin.ts
Perp Margin Components
Base Margin Requirements
Each perp market defines base margin ratios:Oracle Price for Margin
Perp positions are valued with a conservative oracle price:sdk/src/math/margin.ts
Worst-Case Position Size
Open orders are considered in margin calculations:sdk/src/math/margin.ts
- Current position
- All open bids (could increase position)
- All open asks (could decrease position)
Unrealized PnL Weights
Unrealized perp PnL contributes to margin with haircuts: Positive PnL (Asset):PnL Pool Limits
Positive unrealized PnL is capped by available PnL pool:Spot Margin Components
Asset Weights
Each spot market has asset weights for deposits:Liability Weights
Borrows have liability weights:Strict Oracle Prices
Spot margin uses strict oracle prices with confidence intervals:Isolated Position Margin
Isolated positions have separate margin calculations:Isolated Margin Calculation
- Use only their dedicated collateral
- Don’t affect cross-margin positions
- Are liquidated independently
- Cannot cross-collateralize
Isolated positions are ideal for high-risk trades where you want to limit downside to the allocated collateral.
Open Order Margin
Open orders reserve margin:Open Order Treatment
- Reduce-only orders: Don’t require additional margin
- Risk-increasing orders: Require margin for worst-case scenario
- Trigger orders: Require margin as if already filled
High Leverage Mode
Users can enable high leverage mode for lower margin requirements:sdk/src/types.ts
- Lower initial and maintenance margin ratios
- Limited to specific markets
- May have user caps
- Higher risk of liquidation
Margin Trading Toggle
Users can disable margin trading:- Cannot open leveraged positions
- Cannot borrow from spot markets
- Can only trade with existing deposits
- Useful for preventing accidental leverage
Custom Margin Ratios
Users can set custom max margin ratios:Margin Calculation Example
Let’s calculate margin for a user with:- 1000 USDC deposited (initial asset weight: 100%)
- Long 10 SOL-PERP at $100 (initial margin: 10%, maintenance: 5%)
- 500 USDC borrowed (initial liability weight: 105%)
Next Steps
Liquidations
Understand the liquidation process
Positions
Learn about position management
Markets
Review margin requirements per market
SDK Guide
Calculate margin in your application