GTE’s margin system is designed to give traders maximum flexibility while maintaining system safety. Whether you’re trading a single position or managing a complex portfolio, the margin system adapts to your needs.

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 as address 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 as 1e18 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:
orderbookCollateralDelta = openOrderNotional / newLeverage - openOrderNotional / oldLeverage
Margin Delta:
marginDelta = <total intended margin for all positions given new leverage for a single position> - currentMargin
Where the intended margin for a given position is:
intendedMargin = position.amount × mark / leverage
The total delta is:
marginDelta + orderbookCollateralDelta
where:
  • 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:
opened notional / leverage
This represents the maximum cost since positive PnL can reduce it to zero. The opening process works like this:
  1. Margin Delta = opened notional / leverage
  2. rPnL includes funding payment, fees, and any PnL from closing (if it’s a reverse open)
  3. The system updates your margin balance with realized items, and recalculates equity; this margin may be subject to forfeit in liquidation
Because unrealized PnL and funding can be large and immediately settled, the margin balance (cash) can be negative while account equity (cash + unrealized PnL) still satisfies the solvency rule. This is allowed by design but may tighten this via policy for more conservative risk management.

Closing Positions

When you close a position, the standard maximum payout is:
closed notional / leverage
This is the maximum margin returned since negative PnL can reduce it to zero. The closing process:
  1. Margin Delta = -(closed notional / leverage) (negative sign because margin is returned)
  2. rPnL includes funding, PnL from the close, and fees
  3. The system calculates your final margin balance
Realized PnL, funding, and fees adjust the margin balance, and margin returned is what remains after any forfeits in liquidation scenarios. In cross-margin, there is no per-position “margin pot” to return. The system updates the margin balance and requirements, and enforces the account-level health condition.

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:
rebalance = MIN(marginDelta, MAX(intendedMargin - equity, 0))
For Closes:
rebalance = MAX(marginDelta, MIN(intendedMargin - equity, 0))
Where:
  • margin += rPnL
  • equity = margin + uPnL
This ensures your account always maintains the proper margin ratios for your chosen leverage levels.

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:
margin_balance_after_deposit = margin_balance_before_deposit + deposit_amount
account_equity_after_deposit = margin_balance_after_deposit + Σ uPnL_after_deposit
Deposits always pass health checks (account becomes more solvent). After withdrawal state:
margin_balance_after_withdrawal = margin_balance_before_withdrawal - withdrawal_amount
account_equity_after_withdrawal = margin_balance_after_withdrawal + Σ uPnL_after_withdrawal
Withdrawal checks:
  1. Invariant: account_equity_after_withdrawal ≥ total_maintenance_margin_after_withdrawal
  2. Collateral floor: margin_balance_after_withdrawal ≥ MAX(total_initial_margin_after_withdrawal, total_notional_after_withdrawal × 0.10)
This ensures sufficient collateral remains, even though in liquidation, position margin is forfeit subject to per-event caps. If any of these conditions fail, the withdrawal is blocked or capped at the maximum safe amount.