Key Concepts
Margin balance (the cash balance in the account) = collateral deposited + realized PnL − settled funding − settled fees. Account equity = margin balance + sum of unrealized PnL across all open positions. This is the core solvency measure. Maintenance margin (MM) = sum over positions of (maintenance rate × abs(position size) × mark price). Available margin = account equity − maintenance margin (if negative, account is liquidatable). Realized PnL (rPnL) = PnL, funding, and fees that have been settled into the margin balance. Unrealized PnL (uPnL) = mark-to-market profit or loss on open positions. Intended margin = margin implied by the user’s leverage choice (for display/UX only; not part of the solvency rule). Account health condition (or invariant):account_equity ≥ account_maintenance_margin_total
Position margin (display) — For cross-margin accounts, the UI shows a per-position margin allocation for clarity. It’s a display figure derived from the account’s balance; solvency is still enforced at the account level.
Account Structure
Margin accounts on GTE are stored asaddress account ⇒ uint256 subaccount
mappings. You can choose between two margin modes:
Isolated Margin = each open position has its own dedicated margin (collateral), and losses are confined to that position only.
Cross Margin = all positions share the same margin pool and your entire account balance can be used to support any open position; solvency check is account_equity ≥ Σ maintenance
. No per-leg “margin_alloc” exists beyond display purposes.
When adding a new position to an existing cross margin account, all assets must have cross margin enabled. If you have a position in an asset with cross margin disabled, you can still trade that asset normally, but you won’t be able to add new assets until that position is closed.
In liquidation, the margin allocated to a position may be forfeited, capped by per-event limits and account equity (see sections below).
Leverage
Leverage is a user-set parameter. It reflects the ratio between your position notional and the margin required to support it. The system enforces this setting by adjusting your intended margin requirements whenever you open or change a position. You can set leverage on any position between 1x and the maximum allowed for that asset. The default is 1x (represented as1e18
in the contracts). You can adjust leverage at any time.
In cross-margin, the system enforces account-level solvency, not exact leverage per position. The leverage slider affects intended margin targets for UX, but not the invariant since in liquidation, margin is forfeit, not pro-rated by notional.
Leverage Adjustment Calculations
When you change leverage on a position in a cross margin account, the system calculates two deltas: Orderbook Collateral Delta:- Positive delta = you owe margin to the protocol
- Negative delta = the protocol owes margin to you
Opening Positions
When you open a new position, the standard maximum cost is:- Margin Delta =
opened notional / leverage
- rPnL includes funding payment, fees, and any PnL from closing (if it’s a reverse open)
- The system updates your margin balance with realized items, and recalculates equity; this margin may be subject to forfeit in liquidation
Closing Positions
When you close a position, the standard maximum payout is:- Margin Delta =
-(closed notional / leverage)
(negative sign because margin is returned) - rPnL includes funding, PnL from the close, and fees
- The system calculates your final margin balance
Margin Rebalancing
For user convenience, the system shows per-position margin allocations that match the user’s chosen leverage, but actual risk checks are enforced at the account level. This ensures that each position lines up with the chosen leverage settings. When you open a position: the system may allocate more margin to cover the new exposure. When you close a position: the system may release some margin if it’s no longer required. PnL, funding, and fees: any realized profit or loss, plus funding payments and trading fees, are posted straight into your margin balance. While these adjustments keep your leverage in line with your settings, account safety is always enforced at the account level. That means your account equity (collateral plus PnL) must always be greater than or equal to the total maintenance margin required for all of your open positions. If this condition is not met, your account becomes eligible for liquidation. For Opens:margin += rPnL
equity = margin + uPnL
Deposits and Withdrawals
Deposits and withdrawals are the simplest way to manage the cash balance in your account.Deposits
When you deposit collateral, your margin balance increases immediately. This also raises your account equity, giving you more room to trade or support existing positions.Withdrawals
You can withdraw funds as long as your account stays healthy after the withdrawal. The system checks that your account equity will still be greater than or equal to the total maintenance margin required for your open positions. If a withdrawal would make your account unsafe, it will be reduced or rejected.Safety Checks
Withdrawals also respect policy floors, such as minimum cash balance rules or venue-specific limits. This ensures you always have enough collateral left to cover open risk. After deposit state:- Invariant:
account_equity_after_withdrawal ≥ total_maintenance_margin_after_withdrawal
- Collateral floor:
margin_balance_after_withdrawal ≥ MAX(total_initial_margin_after_withdrawal, total_notional_after_withdrawal × 0.10)