JSON-RPC API

LP-9002 DEX JSON-RPC API Reference

JSON-RPC API Reference

The LX exposes a JSON-RPC 2.0 API for programmatic trading operations. This API provides low-latency access to order management, market data, and account functions.

Specification

This API implements LP-9002: DEX JSON-RPC Protocol, the Lux Proposal for standardized decentralized exchange interfaces.

PropertyValue
ProtocolJSON-RPC 2.0
TransportHTTP, WebSocket
EncodingUTF-8 JSON
OpenRPC Schemahttps://api.lux.network/openrpc.json

Endpoints

Mainnet

HTTP:  https://api.lux.network/rpc
WS:    wss://api.lux.network/rpc/ws

Testnet

HTTP:  https://testnet-api.lux.network/rpc
WS:    wss://testnet-api.lux.network/rpc/ws

Local Development

HTTP:  http://localhost:8080/rpc
WS:    ws://localhost:8080/rpc/ws

Request Format

All JSON-RPC requests follow the standard format:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_methodName",
  "params": {}
}

Fields

FieldTypeRequiredDescription
jsonrpcstringYesMust be "2.0"
idnumber | stringYesRequest identifier, echoed in response
methodstringYesMethod name with lx_ prefix
paramsobjectNoMethod parameters as named object

Example Request

curl -X POST https://api.lux.network/rpc \
  -H "Content-Type: application/json" \
  -H "X-API-Key: your_api_key" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "lx_getOrderBook",
    "params": {
      "market": "BTC-USDT",
      "depth": 20
    }
  }'

Response Format

Success Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    // Method-specific result
  }
}

Error Response

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32000,
    "message": "Order not found",
    "data": {
      "orderId": "550e8400-e29b-41d4-a716-446655440000"
    }
  }
}

Authentication

API Key Authentication

For HTTP requests, include API credentials in headers:

X-API-Key: your_api_key
X-API-Secret: your_api_secret
X-API-Timestamp: 1702300000000
X-API-Signature: hmac_sha256_signature

Signature Generation

import hmac
import hashlib
import time

def generate_signature(secret: str, timestamp: int, method: str, body: str) -> str:
    message = f"{timestamp}{method}{body}"
    return hmac.new(
        secret.encode(),
        message.encode(),
        hashlib.sha256
    ).hexdigest()

WebSocket Authentication

Authenticate on connection with the lx_authenticate method:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_authenticate",
  "params": {
    "apiKey": "your_api_key",
    "timestamp": 1702300000000,
    "signature": "hmac_sha256_signature"
  }
}

Rate Limits

HTTP Endpoints

Endpoint TypeLimitWindow
Public (market data)100 req1 second
Private (orders)50 req1 second
Account20 req1 second
Admin10 req1 second

WebSocket

Limit TypeValue
Connections per IP5
Messages per second100
Subscriptions per connection50

Rate Limit Headers

X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1702300060
X-RateLimit-Window: 1s

Rate Limit Error

{
  "jsonrpc": "2.0",
  "id": 1,
  "error": {
    "code": -32029,
    "message": "Rate limit exceeded",
    "data": {
      "limit": 100,
      "window": "1s",
      "retryAfter": 500
    }
  }
}

Error Codes

Standard JSON-RPC Errors

CodeMessageDescription
-32700Parse errorInvalid JSON
-32600Invalid RequestNot a valid JSON-RPC request
-32601Method not foundUnknown method
-32602Invalid paramsInvalid method parameters
-32603Internal errorInternal server error

LP-9002 DEX Errors

CodeMessageDescription
-32000Order not foundOrder ID does not exist
-32001Market not foundTrading pair not supported
-32002Insufficient balanceNot enough funds
-32003Invalid orderOrder validation failed
-32004Order already cancelledCannot modify cancelled order
-32005Order already filledCannot modify filled order
-32010Invalid pricePrice outside valid range
-32011Invalid quantityQuantity below minimum
-32012Invalid sideMust be "buy" or "sell"
-32013Invalid order typeUnsupported order type
-32014Invalid time in forceUnsupported TIF value
-32020Authentication requiredMissing credentials
-32021Invalid signatureSignature verification failed
-32022Expired timestampRequest timestamp too old
-32023Permission deniedInsufficient permissions
-32029Rate limit exceededToo many requests
-32030Market suspendedTrading halted
-32031Maintenance modeSystem under maintenance

Method Categories

Order Management

MethodDescriptionAuth
lx_placeOrderSubmit new orderYes
lx_cancelOrderCancel existing orderYes
lx_getOrderGet order detailsYes
lx_getOrdersList user ordersYes

Order Book

MethodDescriptionAuth
lx_getOrderBookGet order book snapshotNo
lx_getOrderBookDepthGet aggregated depthNo
lx_getSpreadGet bid-ask spreadNo

Trades

MethodDescriptionAuth
lx_getTradesGet recent tradesNo
lx_getUserTradesGet user trade historyYes
lx_getTradeHistoryGet historical tradesNo

Account

MethodDescriptionAuth
lx_getBalanceGet single asset balanceYes
lx_getBalancesGet all balancesYes
lx_getPositionsGet open positionsYes

Market Data

MethodDescriptionAuth
lx_getMarketsList available marketsNo
lx_getTickerGet ticker dataNo
lx_get24hStatsGet 24h statisticsNo

Admin

MethodDescriptionAuth
lx_pingHealth checkNo
lx_healthDetailed health statusNo
lx_versionAPI version infoNo
lx_metricsPerformance metricsYes

Batch Requests

Multiple requests can be sent in a single HTTP call:

[
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "lx_getTicker",
    "params": {"market": "BTC-USDT"}
  },
  {
    "jsonrpc": "2.0",
    "id": 2,
    "method": "lx_getTicker",
    "params": {"market": "ETH-USDT"}
  }
]

Response:

[
  {
    "jsonrpc": "2.0",
    "id": 1,
    "result": {"market": "BTC-USDT", "lastPrice": "42150.00", ...}
  },
  {
    "jsonrpc": "2.0",
    "id": 2,
    "result": {"market": "ETH-USDT", "lastPrice": "2250.00", ...}
  }
]

Batch Limits

LimitValue
Max requests per batch100
Max batch payload size1 MB

OpenRPC Schema

The full OpenRPC schema is available at:

https://api.lux.network/openrpc.json

This schema can be used with OpenRPC tooling for:

  • Client code generation
  • Documentation generation
  • Request validation
  • Type checking

Schema Example

{
  "openrpc": "1.2.6",
  "info": {
    "title": "LX JSON-RPC API",
    "version": "1.0.0",
    "description": "LP-9002 compliant DEX API"
  },
  "servers": [
    {"url": "https://api.lux.network/rpc"}
  ],
  "methods": [
    {
      "name": "lx_placeOrder",
      "params": [...],
      "result": {...}
    }
  ]
}

WebSocket Subscriptions

Beyond RPC methods, the WebSocket endpoint supports real-time subscriptions:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "lx_subscribe",
  "params": {
    "channel": "orderbook",
    "market": "BTC-USDT"
  }
}

See WebSocket API for subscription details.

SDK Integration

Go

import "github.com/luxfi/dex/sdk/go/rpc"

client := rpc.NewClient("https://api.lux.network/rpc", apiKey, apiSecret)
order, err := client.PlaceOrder(ctx, &rpc.PlaceOrderParams{
    Market:   "BTC-USDT",
    Side:     "buy",
    Type:     "limit",
    Price:    "42000.00",
    Quantity: "0.1",
})

TypeScript

import { LXRPCClient } from '@luxfi/trading';

const client = new LXRPCClient({
  endpoint: 'https://api.lux.network/rpc',
  apiKey: 'your_api_key',
  apiSecret: 'your_api_secret',
});

const order = await client.placeOrder({
  market: 'BTC-USDT',
  side: 'buy',
  type: 'limit',
  price: '42000.00',
  quantity: '0.1',
});

Python

from lux_dex import RPCClient

client = RPCClient(
    endpoint="https://api.lux.network/rpc",
    api_key="your_api_key",
    api_secret="your_api_secret"
)

order = client.place_order(
    market="BTC-USDT",
    side="buy",
    order_type="limit",
    price="42000.00",
    quantity="0.1"
)