Implementing Futures Trading in a Mobile Exchange App
Futures trading on crypto exchanges means perpetual contracts with no expiration, leverage up to 125x, and an 8-hour funding mechanism. Unlike spot trading, there's no real asset — just a price difference contract. This demands fundamentally different UI requirements: Mark Price, Funding Rate, Liquidation Price, Unrealized/Realized PnL, and margin mode — all updating in real-time.
Perpetual Futures: Key Concepts for UI
Mark Price — index price calculated by the exchange from weighted-average price across multiple spot exchanges + funding premium. P&L and liquidation use Mark Price, not Last Price. The difference can reach 0.5–2% during high volatility. Always show both values.
Funding Rate — rate that longs pay shorts (or vice versa) every 8 hours. At high deviation: 0.1% every 8 hours = ~0.3% daily from position. Show Funding Rate and time until next accrual in the position card.
Leverage on futures dynamically changes via slider or field. Maximum depends on position size: on Binance, 125x is available only for positions under $50,000; above that, lower max.
Liquidation Price: Calculation for Futures
Formula for USDM perpetual (Binance Futures), LONG position:
LiquidationPrice = EntryPrice × (1 - InitialMarginRate + MaintenanceMarginRate)
where InitialMarginRate = 1 / Leverage.
// Android — liquidation price for perpetual futures LONG
fun calcLiqPriceLong(
entryPrice: BigDecimal,
leverage: Int,
mmRate: BigDecimal = BigDecimal("0.005") // Maintenance Margin Rate
): BigDecimal {
val imr = BigDecimal.ONE.divide(BigDecimal(leverage), 8, RoundingMode.HALF_UP)
return entryPrice.multiply(BigDecimal.ONE.subtract(imr).add(mmRate))
.setScale(2, RoundingMode.HALF_UP)
}
For positions with multiple averages (adding to position), recalculate Entry Price via weighted average and update Liquidation Price. For Cross Margin, the entire available balance factors into the calculation — more complex formula.
Trading Screen UI
Futures trading screen is data-heavy by nature. Recommended structure for mobile:
Top: Mark Price (large) | Last Price | Funding Rate + Countdown | 24h Change
Center: Candlestick chart (TradingView Lightweight Charts in WKWebView / WebView) with timeframe toggle
Bottom: Tabs "Position" / "Open Orders" / "History" + order form
Order form — Bottom Sheet with Long/Short tabs. Fields: Leverage (slider), Price (for limit), Size (in contracts or USDT), margin mode Cross/Isolated.
TP/SL Attached to Position
In futures, Take Profit and Stop Loss aren't separate orders — they're position attributes. Binance Futures API: POST /fapi/v1/order with reduceOnly=true, or create TP/SL via POST /fapi/v1/order with closePosition=true.
// iOS — creating TP/SL for futures position
struct FuturesTpSlRequest: Codable {
let symbol: String
let side: String // opposite of current position
let type: String // TAKE_PROFIT_MARKET or STOP_MARKET
let stopPrice: String
let closePosition: String // "true"
let workingType: String // MARK_PRICE or CONTRACT_PRICE
let timeInForce: String // GTE_GTC
}
workingType: MARK_PRICE — TP/SL triggers on Mark Price, protecting from false triggers on anomalous Last Price (wick hunting). Explain this to users in a tooltip.
Real-Time PnL and Liquidation
Binance Futures WebSocket: @markPrice stream for Mark Price, userData stream with ORDER_TRADE_UPDATE and ACCOUNT_UPDATE for balances and positions. All position UI relies on these two streams.
When approaching liquidation (Margin Ratio > 80%): visual pulse (position card border animation), high-priority push. On actual liquidation — separate screen with summary: what was, close price, loss amount.
Timeline
MVP futures module (perpetual, Long/Short, TP/SL):
| Component | Timeline |
|---|---|
| WebSocket Mark Price + Funding Rate | 3 days |
| Order form with leverage and margin mode | 1 week |
| Real-time positions: PnL, Liquidation Price | 1 week |
| TP/SL attached to position | 3 days |
| Trade history and funding payouts | 3 days |
| Risk push alerts | 3 days |
Total: 4–6 weeks. Full module with Multi-asset Mode, Portfolio Margin, hedge mode — 3 months.







