Trading

Perpetual Trading

Trade perpetual futures contracts with up to 1001x leverage on LX DEX

Perpetual Trading

Specification: LP-9004 Perpetuals & Derivatives Protocol

Perpetual futures (perps) are derivative contracts that track an underlying asset's price without expiration. Unlike traditional futures, perpetuals never settle—positions can be held indefinitely.

Overview

FeatureValue
Max Leverage1001x (tiered by position size)
Contract TypeInverse & Linear
SettlementUSDT, USDC
Funding Interval8 hours
LiquidationAutomatic
Insurance FundProtocol-backed
TP/SL Orders+300% targets supported
Referral SystemUp to 30% rebates

Tiered Leverage System

LX DEX supports up to 1001x leverage for micro-positions, with automatic leverage reduction as position size increases. This tiered system balances opportunity with risk management.

Leverage Tiers

TierPosition SizeMax LeverageMaintenance MarginInitial Margin
1$0 - $2001001x0.10%0.10%
2$200 - $2,000500x0.20%0.20%
3$2,000 - $10,000250x0.25%0.40%
4$10,000 - $50,000200x0.50%0.50%
5$50,000 - $500,000100x1.00%1.00%
6$500,000 - $1,000,00075x1.50%1.33%
7$1,000,000 - $2,500,00050x2.00%2.00%
8$2,500,000 - $5,000,00025x2.50%4.00%
9$5,000,000 - $12,500,00020x3.00%5.00%
10$12,500,000 - $25,000,00010x5.00%10.00%
11$25,000,000 - $75,000,0005x10.00%20.00%
12$75,000,000 - $125,000,0004x12.50%25.00%
13$125,000,000 - $200,000,0003x15.00%33.33%
14$200,000,000 - $250,000,0002x25.00%50.00%
15$250,000,000+1x50.00%100.00%

How Tiered Leverage Works

Position Size → Leverage Tier → Max Leverage

Example 1: $100 position
  Tier: 1 (micro)
  Max Leverage: 1001x
  Required Margin: $0.10 (0.1%)

Example 2: $100,000 position
  Tier: 5 (standard)
  Max Leverage: 100x
  Required Margin: $1,000 (1%)

Example 3: $10,000,000 position
  Tier: 9 (large)
  Max Leverage: 20x
  Required Margin: $500,000 (5%)

Get Max Leverage for Position

import { DEX } from '@luxfi/trading'

const dex = await DEX({ rpcUrl: 'https://api.lux.network/rpc' })

// Check max leverage for position size
const maxLeverage = await dex.perpetual.getMaxLeverage({
  symbol: 'BTC-USD-PERP',
  notionalSize: '50000'  // $50K position
})

console.log(`Max Leverage: ${maxLeverage}x`)  // 200x
console.log(`Required Margin: ${50000 / maxLeverage}`)  // $250

How Perpetuals Work

Perpetual Price ≈ Spot Price (via Funding Rate)

When perp price > spot:
  - Funding rate positive
  - Longs pay shorts
  - Encourages selling, brings price down

When perp price < spot:
  - Funding rate negative
  - Shorts pay longs
  - Encourages buying, brings price up

Key Concepts

TermDefinition
Mark PriceFair price used for liquidation (oracle-based)
Index PriceSpot price from major exchanges
Funding RatePayment between longs/shorts every 8h
Open InterestTotal value of outstanding positions
Unrealized PnLProfit/loss if position closed now
Realized PnLActual profit/loss from closed trades

Available Markets

Major Perpetuals

MarketMax LeverageMin SizeTick SizeMaintenance
BTC-USD-PERP1001x*$1$0.500.1% - 50%
ETH-USD-PERP1001x*$1$0.100.1% - 50%
LUX-USD-PERP500x*$1$0.00010.2% - 50%

*Max leverage depends on position size (see tiered leverage table)

Alt Perpetuals

MarketMax LeverageMin SizeTick SizeMaintenance
SOL-USD-PERP250x*$1$0.010.25% - 50%
AVAX-USD-PERP250x*$1$0.010.25% - 50%
ARB-USD-PERP100x*$1$0.00011% - 50%
OP-USD-PERP100x*$1$0.00011% - 50%

Quick Start

Open a Long Position

import { DEX } from '@luxfi/trading'

const dex = await DEX({ rpcUrl: 'https://api.lux.network/rpc' })

// Long BTC perpetual with 100x leverage
const position = await dex.perpetual.openPosition({
  symbol: 'BTC-USD-PERP',
  side: 'long',
  size: '10000',        // $10,000 notional
  leverage: 100,        // 100x leverage (tier 5)
  type: 'market'
})

console.log(`Position ID: ${position.id}`)
console.log(`Entry Price: $${position.entryPrice}`)
console.log(`Collateral: $${position.collateral}`)
console.log(`Liquidation: $${position.liquidationPrice}`)

Open a Short Position

// Short ETH with limit order
const position = await dex.perpetual.openPosition({
  symbol: 'ETH-USD-PERP',
  side: 'short',
  size: '5000',
  leverage: 50,
  type: 'limit',
  price: '2500.00'      // Enter short at $2,500
})

With Take Profit and Stop Loss

const position = await dex.perpetual.openPosition({
  symbol: 'BTC-USD-PERP',
  side: 'long',
  size: '10000',
  leverage: 100,
  type: 'market',
  takeProfit: {
    percent: 300,        // +300% profit target
    type: 'limit'
  },
  stopLoss: {
    percent: 50,         // -50% max loss
    type: 'market'
  }
})

Take Profit / Stop Loss (TP/SL)

LX DEX supports advanced TP/SL orders with percentage-based targets, making it easy to set profit targets like "+300%" directly.

TP/SL Order Types

Order TypeDescriptionUse Case
Take ProfitClose at profit targetLock in gains at +X%
Stop LossClose at loss limitLimit downside to -X%
Trailing StopDynamic stop that follows priceProtect gains while allowing upside

Trigger Types

TriggerDescription
Mark PriceTrigger on oracle mark price (default)
Last PriceTrigger on last traded price
Index PriceTrigger on underlying index price

Create TP/SL Orders

// Take Profit at +300% from entry
const tp = await dex.perpetual.createTPSL({
  positionId: 'pos_123',
  type: 'takeProfit',
  percent: 300,           // +300% from entry
  triggerType: 'mark',    // Trigger on mark price
  orderType: 'limit',     // Execute as limit order
  closePercent: 100       // Close 100% of position
})

// Stop Loss at -50% from entry
const sl = await dex.perpetual.createTPSL({
  positionId: 'pos_123',
  type: 'stopLoss',
  percent: 50,            // -50% from entry
  triggerType: 'mark',
  orderType: 'market',
  closePercent: 100
})

console.log(`TP Price: $${tp.triggerPrice}`)  // Entry × 4 for +300%
console.log(`SL Price: $${sl.triggerPrice}`)  // Entry × 0.5 for -50%

TP/SL with Price Targets

// Take Profit at specific price
const tp = await dex.perpetual.createTPSL({
  positionId: 'pos_123',
  type: 'takeProfit',
  price: '200000',        // $200,000 BTC target
  triggerType: 'mark',
  orderType: 'limit'
})

// Stop Loss at specific price
const sl = await dex.perpetual.createTPSL({
  positionId: 'pos_123',
  type: 'stopLoss',
  price: '45000',
  triggerType: 'mark',
  orderType: 'market'
})

Trailing Stop Orders

// Trailing stop with fixed delta
const trailing = await dex.perpetual.createTPSL({
  positionId: 'pos_123',
  type: 'trailingStop',
  trailingDelta: '1000',  // $1,000 trail distance
  triggerType: 'last'
})

// Trailing stop with percentage
const trailingPercent = await dex.perpetual.createTPSL({
  positionId: 'pos_123',
  type: 'trailingStop',
  trailingPercent: 2,     // 2% trail
  activationPrice: '55000', // Activate when price hits $55K
  triggerType: 'mark'
})

Manage TP/SL Orders

// Get all TP/SL orders for position
const orders = await dex.perpetual.getTPSLOrders('pos_123')

orders.forEach(order => {
  console.log(`${order.type}: $${order.triggerPrice}`)
  console.log(`  Status: ${order.status}`)
  console.log(`  Trigger: ${order.triggerType}`)
})

// Cancel specific order
await dex.perpetual.cancelTPSL(orders[0].id)

// Cancel all TP/SL for position
await dex.perpetual.cancelAllTPSL('pos_123')

Funding Rate

Understanding Funding

Funding payments occur every 8 hours (00:00, 08:00, 16:00 UTC):

Funding Payment = Position Size × Funding Rate

Example:
- Long Position: $100,000
- Funding Rate: 0.01% (positive = longs pay)
- Payment: $100,000 × 0.01% = $10 (paid to shorts)

Track Funding Rates

// Get current funding rate
const funding = await dex.perpetual.getFunding('BTC-USD-PERP')

console.log(`Symbol: ${funding.symbol}`)
console.log(`Current Rate: ${funding.rate}% per 8h`)
console.log(`Annualized: ${funding.rate * 3 * 365}%`)
console.log(`Next Settlement: ${funding.nextTime}`)
console.log(`Predicted Next: ${funding.predictedRate}%`)

Funding History

// Get position funding history
const history = await dex.perpetual.getFundingHistory({
  positionId: 'pos_123',
  limit: 100
})

let totalFunding = 0
history.forEach(f => {
  totalFunding += parseFloat(f.amount)
  console.log(`${f.timestamp}: ${f.amount} USDT`)
})
console.log(`Total Funding Paid/Received: ${totalFunding} USDT`)

Position Management

View Open Positions

const positions = await dex.perpetual.getPositions()

positions.forEach(pos => {
  console.log(`${pos.symbol}:`)
  console.log(`  Side: ${pos.side}`)
  console.log(`  Size: $${pos.size}`)
  console.log(`  Entry: $${pos.entryPrice}`)
  console.log(`  Mark: $${pos.markPrice}`)
  console.log(`  Leverage: ${pos.leverage}x (Tier ${pos.tier})`)
  console.log(`  Unrealized PnL: $${pos.unrealizedPnl}`)
  console.log(`  ROE: ${pos.roe}%`)
})

Increase Position

// Add to existing position
const result = await dex.perpetual.increasePosition({
  positionId: 'pos_123',
  additionalSize: '5000',   // Add $5k to position
  type: 'market'
})

console.log(`New Size: $${result.newSize}`)
console.log(`New Avg Price: $${result.newAvgPrice}`)
console.log(`New Tier: ${result.newTier}`)
console.log(`Max Leverage: ${result.maxLeverage}x`)

Decrease Position (Partial Close)

// Reduce position by 50%
const result = await dex.perpetual.decreasePosition({
  positionId: 'pos_123',
  reduceSize: '5000',
  type: 'market'
})

console.log(`Closed Size: $${result.closedSize}`)
console.log(`Realized PnL: $${result.realizedPnl}`)
console.log(`Remaining: $${result.remainingSize}`)

Close Position

// Close entire position at market
const result = await dex.perpetual.closePosition({
  positionId: 'pos_123',
  type: 'market'
})

console.log(`Final PnL: $${result.realizedPnl}`)
console.log(`Collateral Returned: $${result.collateralReturned}`)

Leverage and Margin

Adjust Leverage

// Check max leverage for current position size
const position = await dex.perpetual.getPosition('pos_123')
const maxLev = await dex.perpetual.getMaxLeverage({
  symbol: position.symbol,
  notionalSize: position.size
})

console.log(`Current Leverage: ${position.leverage}x`)
console.log(`Max Allowed: ${maxLev}x`)

// Increase leverage (if within tier limit)
await dex.perpetual.setLeverage({
  positionId: 'pos_123',
  leverage: Math.min(50, maxLev)
})

Add/Remove Margin

// Add margin to reduce liquidation risk
await dex.perpetual.addMargin({
  positionId: 'pos_123',
  amount: '500'
})

// Remove excess margin
await dex.perpetual.removeMargin({
  positionId: 'pos_123',
  amount: '200'
})

Liquidation

How Liquidation Works

Position is liquidated when:
  Margin Ratio < Maintenance Margin (tiered)

Margin Ratio = (Collateral + Unrealized PnL) / Position Size

Liquidation Process:
1. Position force-closed at mark price
2. Remaining collateral covers losses
3. Liquidation fee (5%) to liquidator
4. Shortfall covered by insurance fund

Tiered Liquidation Price

Long Liquidation:
Liq = Entry × (1 - InitialMarginRate + MaintenanceMarginRate)

Short Liquidation:
Liq = Entry × (1 + InitialMarginRate - MaintenanceMarginRate)

Example (100x Long BTC at $50,000, $100K position):
Tier: 5 (1% maintenance margin)
Initial Margin = 1%
Maintenance = 1%
Liq = $50,000 × (1 - 0.01 + 0.01) = $50,000 × 1.0 = immediate risk

With 20x leverage (5% margin):
Liq = $50,000 × (1 - 0.05 + 0.01) = $50,000 × 0.96 = $48,000

Monitor Liquidation Risk

const position = await dex.perpetual.getPosition('pos_123')

const liquidationRisk = {
  marginRatio: position.marginRatio,
  healthFactor: position.healthFactor,
  liquidationPrice: position.liquidationPrice,
  distanceToLiq: position.distanceToLiq,
  tier: position.tier,
  maintenanceMargin: position.maintenanceMargin
}

if (liquidationRisk.marginRatio < 5) {
  console.log('WARNING: Position near liquidation!')
  console.log(`Add margin or reduce position`)
}

Order Types

Market Order

await dex.perpetual.placeOrder({
  symbol: 'BTC-USD-PERP',
  side: 'buy',
  type: 'market',
  size: '1000'
})

Limit Order

await dex.perpetual.placeOrder({
  symbol: 'BTC-USD-PERP',
  side: 'buy',
  type: 'limit',
  price: '48000',
  size: '1000',
  postOnly: true      // Ensure maker fee
})

Stop Order

await dex.perpetual.placeOrder({
  symbol: 'BTC-USD-PERP',
  side: 'sell',
  type: 'stop',
  stopPrice: '45000', // Trigger price
  size: '1000',
  reduceOnly: true    // Only close existing position
})

Take Profit Order

await dex.perpetual.placeOrder({
  symbol: 'BTC-USD-PERP',
  side: 'sell',
  type: 'takeProfit',
  stopPrice: '55000',
  size: '1000',
  reduceOnly: true
})

Fees

See Fee Schedule for complete fee information including VIP tiers.

Base Fees

Fee TypeRate
Maker0.10%
Taker0.50%
Liquidation0.50%
FundingVariable

VIP Fee Tiers

VIP Tier30-Day VolumeMaker FeeTaker Fee
VIP 0$00.10%0.50%
VIP 1$1M0.08%0.45%
VIP 2$5M0.06%0.42%
VIP 3$10M0.04%0.39%
VIP 4$25M0.02%0.36%
VIP 5$50M0.00%0.27%
VIP 6$100M0.00%0.24%
VIP 7$250M0.00%0.21%
VIP 8$500M0.00%0.18%
VIP 9$1B0.00%0.15%

Risk Management

Perpetual trading carries significant risk. Leverage amplifies both gains and losses. With 1001x leverage, a 0.1% adverse move results in liquidation.

Best Practices

  1. Use appropriate leverage - Start with 2-10x, not 1001x
  2. Set stop losses - Always define max loss with TP/SL orders
  3. Monitor funding - Can erode profits on long holds
  4. Keep margin buffer - Don't use 100% available margin
  5. Track open interest - High OI can mean crowded trades
  6. Understand mark vs last - Liquidation uses mark price
  7. Know your tier - Larger positions have lower max leverage

Position Sizing Formula

Position Size = Account × Risk% / (Entry - Stop) × Entry

Example:
- Account: $10,000
- Risk: 1% ($100)
- Entry: $50,000
- Stop: $49,000 (2% away)

Size = $10,000 × 1% / 2% = $5,000 position
Leverage = $5,000 / $10,000 = 0.5x (conservative)

Market Data

Real-time Prices

// Subscribe to perpetual ticker
dex.perpetual.subscribeTicker('BTC-USD-PERP', (ticker) => {
  console.log(`Last: $${ticker.lastPrice}`)
  console.log(`Mark: $${ticker.markPrice}`)
  console.log(`Index: $${ticker.indexPrice}`)
  console.log(`Funding: ${ticker.fundingRate}%`)
  console.log(`Open Interest: $${ticker.openInterest}`)
})

Order Book

// Get perpetual order book
const book = await dex.perpetual.getOrderBook('BTC-USD-PERP', {
  depth: 20
})

console.log('Best Bid:', book.bids[0])
console.log('Best Ask:', book.asks[0])
console.log('Spread:', book.spread)

Insurance Fund

The insurance fund covers liquidation shortfalls:

// Check insurance fund status
const fund = await dex.perpetual.getInsuranceFund()

console.log(`Total: $${fund.total}`)
console.log(`BTC Coverage: $${fund.btc}`)
console.log(`ETH Coverage: $${fund.eth}`)

Fund Mechanics

When liquidation has shortfall:
1. Insurance fund covers the gap
2. If fund depleted, ADL triggered
3. Profitable traders auto-deleveraged