Margining
GX Exchange supports both cross margin and isolated margin modes for perpetual trading. All margin calculations use integer arithmetic with basis-point precision to eliminate floating-point rounding errors.
Cross Margin
In cross margin mode, all positions in an account share a single collateral pool. Unrealized profits from one position can offset margin requirements of another.
Advantages:
- Lower liquidation risk for diversified portfolios
- More capital-efficient for correlated positions
- Simplified collateral management
Risks:
- A single losing position can deplete margin for all positions
- Liquidation affects the entire account
Isolated Margin
In isolated margin mode, each position has a dedicated collateral allocation. Losses are limited to the margin assigned to that specific position.
Advantages:
- Risk is contained to individual positions
- Losing positions cannot drain other positions
- Clear risk/reward boundaries per trade
Risks:
- Less capital-efficient (margin cannot be shared)
- Positions may be liquidated individually even when the overall account is healthy
Margin Formulas
Initial Margin
The initial margin is the minimum collateral required to open a new position:
initial_margin = abs(size) * price * initial_margin_bps / 10,000Where initial_margin_bps = 10,000 / max_leverage. For BTC at 40x leverage:
initial_margin_bps = 10,000 / 40 = 250 bps = 2.5%Maintenance Margin
The maintenance margin is the minimum collateral required to keep a position open. Falling below this level triggers liquidation:
maintenance_margin = abs(size) * mark_price * maintenance_margin_bps / 10,000Maintenance margin is approximately half of initial margin:
| Max Leverage | Initial Margin | Maintenance Margin |
|---|---|---|
| 40x | 2.50% (250 bps) | 1.25% (125 bps) |
| 25x | 4.00% (400 bps) | 2.00% (200 bps) |
| 20x | 5.00% (500 bps) | 2.50% (250 bps) |
| 15x | 6.67% (667 bps) | 3.33% (333 bps) |
| 10x | 10.00% (1000 bps) | 5.00% (500 bps) |
| 5x | 20.00% (2000 bps) | 10.00% (1000 bps) |
Equity
Account equity determines margin health:
equity = collateral + sum(unrealized_pnl for all positions)Where unrealized PnL for each position is:
unrealized_pnl = position_size * (mark_price - entry_price)Margin Check (New Order)
When a new order is submitted, the system checks:
total_required = sum(maintenance_margin for existing positions) + initial_margin(new order)The order is accepted if equity >= total_required. Otherwise, it is rejected with an InsufficientMargin error.
Maintenance Margin Check (Liquidation)
The liquidation engine continuously checks:
if equity < sum(maintenance_margin for all positions):
trigger liquidationSee Liquidations for the partial liquidation mechanics that follow.
Free Collateral
Free collateral represents the unused margin available for new orders:
free_collateral = equity - total_margin_requiredThis value is displayed in the trading interface and returned by the API.
Tiered Margin
For large positions, margin requirements increase as notional value crosses tier boundaries. The tiered system uses cumulative deductions to ensure a smooth, continuous margin function with no discontinuities at tier boundaries.
See Margin Tiers for the complete tier-based margin calculation.