Available collateral/balance to trade (accounts for any pending orders, includes unsettled PnL) = collateral + upnl - total_initial_margin_with_orders - pending_short_USDC
Collateral available to withdraw (excludes unsettled PnL) = total_balance - total_initial_margin_with_orders - positive_upnl
Ex. 1 user’s total_balance = 100 USDC, unsettled PnL = -40 USDC, => total_collateral is then 60 USDC. User has a position which takes up 20 USDC maintenance margin, then free_collateral or withdrawable_balance = 60 - 20 = 40 USDC
Ex. 2 user’s total_balance = 100 USDC, unsettled PnL = 40 USDC, => total_collateral is then 100 USDC. User has a position which takes up 20 USDC maintenance margin, then free_collateral = 100 - 20 = 80 USDC and withdrawable_balance = 80 - 40 = 40 USDC
Initial Margin Ratio
IMR i = Max(1 / Max Account Leverage, Base IMR i, IMR Factor i * Abs(Position Notional i)^(4/5))
initial_margin_i = abs (position_notional_i * IMR_i)
weighted_initial_margin_ratio_i = abs (position_notional_i / total_notional ) * IMR_i
initial_margin_ratio = sum (weighted_initial_margin_ratio_i)
Maintenance Margin Ratio
MMR i = Max(Base MMR i, (Base MMR i / Base IMR i) * IMR Factor i * Abs(Position Notional i)^(4/5))
maintenance_margin_i= abs (position_notional_i * MMR_i)
weighted_maintenance_margin_ratio_i = abs (position_notional_i / total_notional ) * MMR_i
maintenance_margin_ratio = sum (weighted_maintenance_margin_ratio_i)