Margin Trading on Stellar

Testnet

Testnet product

Margin trading currently runs on the Stellar testnet with test funds, isolated from mainnet lending. The mechanics documented here are live on-chain; parameters may still change before a mainnet release. A built-in paper-trading mode lets you practice with zero risk.

Margin trading lets you open a leveraged long or short on XLM against USDT margin: the protocol lends you the difference between your margin and the position size, using the same lending pools documented elsewhere in these docs, with a dedicated risk engine on top.

Position sizing#

positionSize = margin × leverage          (leverage: 2×–5×)
borrowed     = margin × (leverage − 1)
A Long borrows USDT and swaps it into XLM; a Short borrows XLM and swaps it into USDT.

Nothing is ever paid into your wallet: the borrow and the swap happen inside the protocol, and the resulting position is held by the margin controller as collateral for the debt.

Opening and closing#

An open is a three-step on-chain sequence behind a single button: reserve the position, swap through the on-chain liquidity pool, activate. Closes run the sequence in reverse. The swap back happens on-chain too, so you never need the debt asset in your wallet to close. If a sequence is interrupted, the app offers resume or cancel; unfinished opens expire after 30 minutes and release their funds.

Liquidation math#

Margin positions use maintenance-margin logic (not the lending collateral factors): a position is liquidatable when its value, discounted by the 5% maintenance margin, no longer covers the debt.

liquidatable when: positionValue × (1 − 0.05) < debtValue

Long:  liqPrice = entry × (lev − 1) / (lev × 0.95)
Short: liqPrice = entry × 0.95 × lev / (lev − 1)
At-entry closed forms; accrued borrow interest shifts the real threshold over time. On-chain health is authoritative.

Liquidation-price calculator

XLM/USDT at an illustrative $0.30 entry: see how leverage squeezes your room for error.

Your margin (USDT)$100
Leverage

Position = margin × leverage; the protocol lends the rest ($200). Interest on that debt accrues while the position is open and is folded into your PnL.

Position size

$300

Borrowed

$200

Health factor at entry

1.43

must open ≥ 1.10

Liquidation price

$0.2105

Price move to liquidation

-29.8%

a fall this size liquidates

Maintenance margin

5%

+1% liquidation incentive

Estimate at entry, ignoring accrued interest and fees. The on-chain health factor decides, never the UI.

Protections & parameters#

ParameterValueWhat it does
Minimum open health1.10Positions can't be opened already near liquidation
Maintenance margin5%The buffer that defines the liquidation threshold
Liquidation incentive1%Bonus paid to liquidators for closing unhealthy positions
Max slippage (oracle band)5%Opens are rejected if the pool price strays >5% from the oracle price
Leverage2×–5×Integer steps
Open/close fees0 (testnet)Borrow interest still accrues and is folded into PnL

The oracle band deserves emphasis: if the on-chain liquidity pool's price drifts more than 5% from the independent oracle price, opens are blocked entirely, and no slippage setting can override it. This protects you from opening into a manipulated or thin market, at the cost of occasionally having to wait out a drift.

Take-profit & stop-loss#

  1. Set independent TP and SL trigger prices on any open position, with live PnL preview.
  2. While the app is open, a client-side monitor watches the mark price and executes your triggers.
  3. An always-on server keeper can arm triggers that fire even with the app closed.

PnL is net of interest

The PnL you see already subtracts accrued borrow interest: the number on screen is what you'd actually realize on close, not a gross figure with costs hidden elsewhere.

Common questions

What leverage can I use?

Between 2x and 5x, in integer steps. Position size is your margin multiplied by the leverage, and the protocol borrows the difference.

How is the liquidation price calculated?

A position is liquidatable when its value discounted by the 5% maintenance margin no longer covers the debt. At entry that gives liqPrice = entry × (lev − 1) / (lev × 0.95) for a long, and entry × 0.95 × lev / (lev − 1) for a short. Accrued borrow interest shifts the real threshold over time, and the on-chain health figure is authoritative.

Why was my position blocked from opening?

Most often the oracle band: if the on-chain liquidity pool's price strays more than 5% from the independent oracle price, opens are refused and no slippage setting can override it. That protects you from opening into a thin or manipulated market.

Do take-profit and stop-loss orders work with the app closed?

An always-on server keeper can arm triggers that fire with the app closed. The client-side monitor only runs while the page is open.

Is margin trading live on mainnet?

Not yet. It runs on the Stellar testnet with test funds, isolated from mainnet lending, and a paper-trading mode lets you practise at zero risk.

Last reviewed on .