Formulas and Definitions
Margin and Balance Formulas
Futures Margin Ratio
Current margin ratio = total_collateral_value / sum(abs(position_notional_i))
Total Collateral
Total collateral of the user (doesn’t account for any pending orders, includes unsettled PnL) = total_balance + upnl + pending_short_USDC
Free Collateral
Available collateral/balance to trade (accounts for any pending orders, includes unsettled PnL) = collateral + upnl - total_initial_margin_with_orders - pending_short_USDC
Portfolio Value
Total potfolio value including position notionals = USDC Balance + (non USDC assets) * mid_price + unsettled pnl
Withdrawable Balance
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
Withdrawable balance/collateral does not equal to total or free collateral.
Initial Margin Ratio
Maintenance Margin Ratio
Positions PnL
Unrealized PnL = position_qty * (mark_price - avg_open)
Liquidation Price
Notional = position_notional_i = abs(mark_price_i * position_qty_i)
Fut Notional or Total Notional = sum (abs (position_notional_i))
Unsettled PnL is retrieved from the API and cannot be calculated