JSON-RPC API LP-9002 DEX 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.
This API implements LP-9002: DEX JSON-RPC Protocol , the Lux Proposal for standardized decentralized exchange interfaces.
Property Value Protocol JSON-RPC 2.0 Transport HTTP, WebSocket Encoding UTF-8 JSON OpenRPC Schema https: //api.lux.network/openrpc.json
HTTP: https://api.lux.network/rpc
WS: wss://api.lux.network/rpc/ws
HTTP: https://testnet-api.lux.network/rpc
WS: wss://testnet-api.lux.network/rpc/ws
HTTP: http://localhost:8080/rpc
WS: ws://localhost:8080/rpc/ws
All JSON-RPC requests follow the standard format:
{
"jsonrpc" : "2.0" ,
"id" : 1 ,
"method" : "lx_methodName" ,
"params" : {}
}
Field Type Required Description jsonrpc string Yes Must be "2.0" id number | string Yes Request identifier, echoed in response method string Yes Method name with lx_ prefix params object No Method parameters as named object
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
}
}'
{
"jsonrpc" : "2.0" ,
"id" : 1 ,
"result" : {
// Method-specific result
}
}
{
"jsonrpc" : "2.0" ,
"id" : 1 ,
"error" : {
"code" : -32000 ,
"message" : "Order not found" ,
"data" : {
"orderId" : "550e8400-e29b-41d4-a716-446655440000"
}
}
}
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
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()
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"
}
}
Endpoint Type Limit Window Public (market data) 100 req 1 second Private (orders) 50 req 1 second Account 20 req 1 second Admin 10 req 1 second
Limit Type Value Connections per IP 5 Messages per second 100 Subscriptions per connection 50
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 95
X-RateLimit-Reset: 1702300060
X-RateLimit-Window: 1s
{
"jsonrpc" : "2.0" ,
"id" : 1 ,
"error" : {
"code" : -32029 ,
"message" : "Rate limit exceeded" ,
"data" : {
"limit" : 100 ,
"window" : "1s" ,
"retryAfter" : 500
}
}
}
Code Message Description -32700 Parse error Invalid JSON -32600 Invalid Request Not a valid JSON-RPC request -32601 Method not found Unknown method -32602 Invalid params Invalid method parameters -32603 Internal error Internal server error
Code Message Description -32000 Order not found Order ID does not exist -32001 Market not found Trading pair not supported -32002 Insufficient balance Not enough funds -32003 Invalid order Order validation failed -32004 Order already cancelled Cannot modify cancelled order -32005 Order already filled Cannot modify filled order -32010 Invalid price Price outside valid range -32011 Invalid quantity Quantity below minimum -32012 Invalid side Must be "buy" or "sell" -32013 Invalid order type Unsupported order type -32014 Invalid time in force Unsupported TIF value -32020 Authentication required Missing credentials -32021 Invalid signature Signature verification failed -32022 Expired timestamp Request timestamp too old -32023 Permission denied Insufficient permissions -32029 Rate limit exceeded Too many requests -32030 Market suspended Trading halted -32031 Maintenance mode System under maintenance
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" , ... }
}
]
Limit Value Max requests per batch 100 Max batch payload size 1 MB
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
{
"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" : { ... }
}
]
}
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.
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" ,
})
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' ,
});
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"
)