Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Margin & Leverage

Margin is the collateral that backs your perpetual positions. This page covers how TxFlow margins a position, how leverage and position size interact, and how to compute your numbers before you open.

Margin modes

  • Cross — all the USDC in your perp account backs all of your cross positions together. Profit on one position can cover loss on another, and your liquidation depends on your whole account.
  • Isolated — each position locks its own margin. Your loss on that position is capped at the margin you assigned to it; it can't pull down your other positions.

Margin mode is per market, set with updateMarginMode, and defaults to cross for a market you have never configured.

Position modes

  • One-Way — a single net position per market within one margin mode (long or short).
  • Hedge — hold a long and a short in the same market at once.

Position mode is account-wide for perpetuals, set with updatePositionMode.

Choosing the margin mode of an order

The margin mode an order lands on is part of the position it opens into or reduces:

  • Send m (marginMode) on the order body to state it explicitly.
  • Omit m and the node routes the order to your current margin mode for that market — the saved per-market setting, or cross if you never set one. The same body can therefore land in a different mode after an updateMarginMode, and an order can open a position you did not intend to touch.

API clients should always send m explicitly; read the effective mode back from activeAssetData.

Tiered margin

The maintenance margin rate (MMR) and the maximum leverage depend on your position size. Larger positions sit in a higher tier: higher MMR, lower max leverage. Each market publishes its own tier table — check it before sizing up, because increasing size can bump you into a stricter tier.

The formulas

notional            = size × mark price
initial margin      = notional / leverage
maintenance margin  = notional × MMR              (MMR from your size tier)
liquidation fee     = notional × market taker fee rate   (reserved to close the position)
 
margin ratio        =    margin + unrealized PnL
                      ─────────────────────────────────
                       maintenance margin + liquidation fee

You are liquidated when margin ratio < 1.0. Two reference prices matter — both include the fee charged to close the position:

liquidation price (long)  =  size × entry − margin
                            ───────────────────────────
                             size × (1 − MMR − feeRate)
 
bankruptcy price  (long)  =  size × entry − margin
                            ───────────────────────
                             size × (1 − feeRate)

For shorts, both denominators become size × (1 + MMR + feeRate) and size × (1 + feeRate), with size × entry + margin in the numerator. The liquidation price is always reached before the bankruptcy price — that buffer is what the liquidation engine works with.

Worked example

You open a long 0.1 BTC perpetual at an entry/mark price of $64,000, isolated, at 10× leverage. Assume this size sits in a tier with MMR = 0.5% and that the market's taker fee rate is 0.045%.

CalculationResult
Notional0.1 × 64,000$6,400
Initial margin (locked)6,400 / 10$640
Maintenance margin6,400 × 0.005$32
Liquidation fee reserve6,400 × 0.00045$2.88
Liquidation price(6,400 − 640) / (0.1 × 0.99455)≈ $57,915.64
Bankruptcy price(6,400 − 640) / (0.1 × 0.99955)≈ $57,625.93

So with $640 of collateral you control $6,400 of BTC. If BTC falls ~9.5% to about $57,916, your equity no longer covers the maintenance margin plus the closing fee, and liquidation begins; by roughly $57,626 the position is fully underwater (bankruptcy). Raising leverage shrinks the initial margin and pushes the liquidation price closer to entry; lowering it does the opposite.

Where the live numbers come from

  • Mark price drives valuation and liquidation (see Mark vs. oracle price).
  • MMR and max leverage come from the market's tier table — query perpMetaDetail via the Info API.
  • The protocol exposes calculators such as getMaxPositions and getLiquidationPrices so you can pre-check a proposed order without computing by hand.