Trading

Trading Overview

Complete guide to trading on LX - spot, perpetuals, margin, and advanced order types

Trading Overview

Specification: LP-9001 DEX Trading Engine | LP-9003 High-Performance DEX

LX provides institutional-grade trading infrastructure with sub-microsecond latency and 434M+ orders per second throughput.

Trading Modes

ModeDescriptionLeverageSettlement
SpotDirect asset exchange1xInstant
MarginLeveraged spot tradingUp to 10xInstant
PerpetualsPerpetual futures contractsUp to 50xContinuous
OptionsOptions contracts (coming soon)VariableExpiration

Supported Markets

Crypto Pairs

  • Major pairs: BTC-USD, ETH-USD, LUX-USD
  • Cross pairs: BTC-ETH, ETH-LUX
  • Stablecoin pairs: BTC-USDT, ETH-USDC

Traditional Assets (via Oracle)

  • Forex: EUR-USD, GBP-USD, JPY-USD
  • Commodities: XAU-USD (Gold), XAG-USD (Silver)
  • Indices: SPX, NDX (reference only)

Total Markets

  • 784,000+ trading pairs across all global markets
  • Real-time oracle price feeds
  • 24/7 trading availability

Order Execution Flow

                    Order Submission
                          |
                          v
+----------------------------------------------------------+
|                   Pre-Trade Checks                        |
+----------------------------------------------------------+
|  1. Authentication    - API key / signature validation    |
|  2. Balance Check     - Sufficient funds / margin         |
|  3. Risk Validation   - Position limits, exposure caps    |
|  4. Order Validation  - Price bounds, size limits         |
+----------------------------------------------------------+
                          |
                          v
+----------------------------------------------------------+
|                   Matching Engine                         |
+----------------------------------------------------------+
|  Price-Time Priority (FIFO)                               |
|  - Best price matched first                               |
|  - Same price: earliest order matched first               |
|  - Partial fills supported                                |
+----------------------------------------------------------+
                          |
                          v
+----------------------------------------------------------+
|                   Post-Trade                              |
+----------------------------------------------------------+
|  1. Trade Execution   - Atomic balance updates            |
|  2. Settlement        - Asset transfer (spot) or PnL      |
|  3. Notification      - WebSocket push to clients         |
|  4. Recording         - Trade history, audit log          |
+----------------------------------------------------------+

Quick Start

1. Place a Limit Order

import { DEX } from '@luxfi/trading'

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

// Buy 1 BTC at $50,000
const order = await dex.limitBuy('BTC-USDC', '1', '50000')

console.log(`Order ID: ${order.orderId}`)
console.log(`Status: ${order.status}`)

2. Place a Market Order

// Market buy 0.5 BTC at best available price
const order = await dex.buy('BTC-USDC', '0.5')

3. Set Stop-Loss

// Stop-loss: Sell if price drops to $45,000
const stopOrder = await dex.limitSell('BTC-USDC', '1', '45000')

Trading Features

Order Types

TypeDescriptionUse Case
LimitExecute at specified price or betterPrecise entry/exit
MarketExecute immediately at best priceUrgent execution
StopTrigger when price reaches levelStop-loss protection
Stop-LimitStop that becomes limit orderControlled stop-loss
Trailing StopDynamic stop that follows priceLock in profits
IcebergHide total order sizeLarge order execution
TWAPTime-weighted average priceMinimize market impact
Post-OnlyOnly add liquidity (maker)Fee optimization

See Order Types for complete documentation.

Time-in-Force Options

TIFNameBehavior
GTCGood Till CancelledRemains until filled or cancelled
IOCImmediate or CancelFill immediately, cancel unfilled
FOKFill or KillFill entirely or cancel entirely
GTDGood Till DateExpires at specified time
DAYDay OrderExpires at end of trading day (00:00 UTC)

Advanced Features

  • Reduce-Only: Close positions only, never increase
  • Post-Only: Ensure order is maker, never taker
  • Hidden Orders: Not visible in order book
  • Bracket Orders: Entry with take-profit and stop-loss

Account Types

Standard Account

  • Spot trading with 1x leverage
  • Basic order types
  • Standard fee tier

Margin Account

  • Up to 10x leverage on spot
  • Cross-margin and isolated margin modes
  • Access to margin lending pools

Perpetual Account

  • Up to 50x leverage on perpetuals
  • Cross-collateral support
  • Funding rate payments/receipts

Portfolio Margin Account

  • Risk-based margin calculation
  • Cross-product margining
  • Lower margin requirements for hedged positions

Risk Warnings

Trading involves significant risk of loss.

  • Leveraged trading can result in losses exceeding your initial deposit
  • Perpetual futures have funding costs that compound over time
  • Liquidation can occur rapidly in volatile markets
  • Past performance does not guarantee future results

Risk Management Best Practices

  1. Use stop-loss orders - Always define your maximum loss
  2. Start with low leverage - Higher leverage = higher risk
  3. Diversify positions - Don't concentrate in single assets
  4. Monitor health factor - Keep margin buffer above requirements
  5. Understand funding - Track funding rate impact on positions

Performance Specifications

MetricValue
Order Latency (GPU)2 ns
Order Latency (CPU)487 ns
Throughput434M orders/sec
Order Book Depth100 levels standard
Matching AlgorithmPrice-Time Priority (FIFO)
SettlementInstant (on-chain finality ~1ms)

API Access

WebSocket (Real-time)

wss://api.lux.network/ws

REST API

https://api.lux.network/v1

gRPC (High-performance)

grpc://api.lux.network:9760

Next Steps