Margining
As part of default settings on the Rubin Chain open source software, each market has two risk parameters, Initial Margin Fraction (IMF) and Maintenance Margin Fraction (MMF):
-
Initial Margin Fraction: A percentage (fixed until certain level of Open Interest) that determines the minimum collateral required to open or increase positions.
-
Maintenance Margin Fraction: A percentage (fixed) that determines the minimum collateral required to maintain positions and avoid liquidation.
Open-Interest-Based IMF
The IMF of a perpetual market scales linearly according to the current open_notional in the market, starting at open_notional_lower_cap to open_notional_upper_cap (USDC denominated):
open_notional = open_interest * oracle_price
scaling_factor = (open_notional - open_notional_lower_cap) / (open_notional_upper_cap - open_notional_lower_cap)
IMF_increase = scaling_factor * (1 - base_IMF)
effective_IMF = Min(base_IMF + Max(IMF_increase, 0), 100%)I.e. the effective IMF is the base IMF while open_notinal < lower_cap, and increases linearly until open_notional = upper_cap, at which point the IMF stays at 100% (requiring 1:1 collateral for trading). Importantly, the MMF (Maintenance Margin Fraction) does not change.
The Open Notional Lower Cap and Open Notional Upper Cap are parameters defined as part of the market's Liquidity Tier.
Selected Leverage
By default a position can use the market's maximum leverage, 1 / effective_IMF. A trader can choose a lower leverage for a market. The choice is stored on-chain for each subaccount and market as a custom IMF in parts per million:
custom_imf_ppm = 1,000,000 / leverageIt is set with Update Leverage (MsgUpdateLeverage) and read with Get Leverage. A market without a selection uses its maximum leverage.
When a selection exists, the initial margin of the position uses the larger of the two fractions:
IMF_used = Max(custom_imf, effective_IMF)A selection therefore only lowers leverage: if open interest pushes the effective IMF above the chosen one, the market's IMF applies. The maintenance margin fraction does not change — the selection limits how large a position can be opened with the available collateral; it does not change the maintenance requirement of a position.
For example, BTC-USD with a base IMF of 2% allows 50×. With 10× selected (custom_imf_ppm = 100000), a position of 0.1 BTC at $80,000 ($8,000 notional) reserves $800 of initial margin instead of $160.
Rules the chain enforces:
- The selection cannot exceed the leverage of the market's liquidity tier:
custom_imf_ppmmust not be below the tier's base IMF. Open-interest scaling is not checked here; it only applies throughIMF_used. - Leverage applies to perpetual markets only. Spot pairs and the spot subaccounts (
number % 128 == 1) cannot use it. - The new value must keep the subaccount's open positions within the initial margin requirement; otherwise the update is rejected.
- Leverage is stored per subaccount. An isolated position lives on its own subaccount, so its leverage is set there. The web app writes the value to the position's subaccount and to the parent subaccount
0. - The update pays no fee, like other order-book messages. A trading key can sign it for its subaccount. Keys approved before protocol v30.3 received this permission in the upgrade without being approved again.
Margin Calculation
The margin requirement for a single position is calculated as follows:
Initial Margin Requirement = abs(S × P × I) Maintenance Margin Requirement = abs(S × P × M)
Where:
Sis the size of the position (positive if long, negative if short)Pis the oracle price for the marketIis the initial margin fraction for the market (IMF_usedwhen a leverage is selected)Mis the maintenance margin fraction for the market
The margin requirement for the account as a whole is the sum of the margin requirement over each market i in which the account holds a position:
Total Initial Margin Requirement = Σ abs(Si × Pi × Ii) Total Maintenance Margin Requirement = Σ abs(S i × Pi × Mi)
The total margin requirement is compared against the total value of the account, which incorporates the quote asset (USDC) balance of the account as well as the value of the positions held by the account:
Total Account Value = Q + Σ (Si × Pi)
The Total Account Value is also referred to as equity.
Where:
Qis the account's USDC balance (note thatQmay be negative). In the API, this is calledquoteBalance. Every time a transfer, deposit or withdrawal occurs for an account, the balance changes. Also, when a position is modified for an account, thequoteBalancechanges. Also funding payments and liquidations will change an account'squoteBalance.SandPare as defined above (note thatSmay be negative)
An account cannot open new positions or increase the size of existing positions if it would lead the total account value of the account to drop below the total initial margin requirement. If the total account value ever falls below the total maintenance margin requirement, the account may be liquidated.
Free collateral is calculated as:
Free collateral = Total Account Value - Total Initial Margin Requirement
Equity and free collateral can be tracked over time using the latest oracle price (obtained from the markets websocket).