Margin Trading on Stellar
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)
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)
Liquidation-price calculator
XLM/USDT at an illustrative $0.30 entry — see how leverage squeezes your room for error.
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#
| Parameter | Value | What it does |
|---|---|---|
| Minimum open health | 1.10 | Positions can't be opened already near liquidation |
| Maintenance margin | 5% | The buffer that defines the liquidation threshold |
| Liquidation incentive | 1% | 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 |
| Leverage | 2×–5× | Integer steps |
| Open/close fees | 0 (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 — 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#
- Set independent TP and SL trigger prices on any open position, with live PnL preview.
- While the app is open, a client-side monitor watches the mark price and executes your triggers.
- 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.