Getting Started

Quick start guide for LX - installation, setup, and your first trade

Getting Started with LX

Specification: LP-9000 DEX Core | LP-9002 DEX API | Discussions

Implementation: github.com/luxfi/dex

Get up and running with LX in minutes.

Prerequisites

  • Go 1.21+ (for building from source)
  • Git
  • Docker (optional, for containerized deployment)

Installation

From Source

# Clone the repository
git clone https://github.com/luxfi/dex.git
cd dex

# Build the project
make build

# Verify installation
./bin/luxd --version

From Release

# Download latest release
curl -L https://github.com/luxfi/dex/releases/latest/download/lx-dex-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m) -o lx-dex

# Make executable
chmod +x lx-dex

# Run
./lx-dex

With Docker

# Pull the image
docker pull luxfi/dex:latest

# Run the container
docker run -p 8080:8080 -p 8081:8081 -p 50051:50051 luxfi/dex:latest

Start the Node

Single Node (Development)

# Start with default configuration
./bin/luxd

# Or with custom config
./bin/luxd --config config.yaml

Multi-Node Cluster

# Start a 3-node cluster
make run-cluster

Docker Compose

# Start all services
docker-compose up -d

# View logs
docker-compose logs -f

Verify Installation

Check Node Health

curl http://localhost:8080/health

Expected response:

{"status": "healthy", "version": "1.0.0"}

Test JSON-RPC

curl -X POST http://localhost:8080/rpc \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "method": "lx_ping", "params": {}, "id": 1}'

Expected response:

{"jsonrpc": "2.0", "result": {"pong": true}, "id": 1}

Your First Trade

Using curl

# Place a buy order
curl -X POST http://localhost:8080/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "lx_placeOrder",
    "params": {
      "symbol": "BTC-USD",
      "type": 0,
      "side": 0,
      "price": 50000,
      "size": 1.0,
      "userID": "trader1"
    },
    "id": 1
  }'

Using TypeScript SDK

import { DEX } from '@luxfi/trading'

const dex = await DEX({ rpcUrl: 'http://localhost:8080/rpc' })

// Place a buy order
const order = await dex.limitBuy('BTC-USD', '1.0', '50000')

console.log('Order ID:', order.orderId)

Using Python SDK

from lux_dex import Client

client = Client(
    json_rpc_url='http://localhost:8080/rpc'
)

# Place a buy order
order = client.place_order(
    symbol='BTC-USD',
    order_type='limit',
    side='buy',
    price=50000,
    size=1.0
)

print(f'Order ID: {order.order_id}')

Using Go SDK

package main

import (
    "context"
    "fmt"
    
    "github.com/luxfi/dex/sdk/go/lxdex"
)

func main() {
    client := lxdex.NewClient(
        lxdex.WithJSONRPC("http://localhost:8080/rpc"),
    )

    order, _ := client.PlaceOrder(context.Background(), &lxdex.Order{
        Symbol: "BTC-USD",
        Type:   lxdex.OrderTypeLimit,
        Side:   lxdex.Buy,
        Price:  50000,
        Size:   1.0,
    })

    fmt.Printf("Order ID: %s\n", order.OrderID)
}

View Order Book

Using curl

curl -X POST http://localhost:8080/rpc \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "method": "lx_getOrderBook",
    "params": {"depth": 10},
    "id": 1
  }'

Using WebSocket

const ws = new WebSocket('ws://localhost:8081');

ws.onopen = () => {
    ws.send(JSON.stringify({
        type: 'subscribe',
        channel: 'orderbook',
        symbol: 'BTC-USD',
        depth: 10
    }));
};

ws.onmessage = (event) => {
    const data = JSON.parse(event.data);
    console.log('Order book:', data);
};

Configuration

Environment Variables

VariableDescriptionDefault
LX_RPC_PORTJSON-RPC port8080
LX_WS_PORTWebSocket port8081
LX_GRPC_PORTgRPC port50051
LX_P2P_PORTP2P networking port5000
LX_LOG_LEVELLog level (debug, info, warn, error)info
LX_DATA_DIRData directory./data

Configuration File

# config.yaml
server:
  rpc_port: 8080
  ws_port: 8081
  grpc_port: 50051

consensus:
  validators: 3
  block_time: 1ms

storage:
  path: ./data
  engine: badger

logging:
  level: info
  format: json

Default Ports

ServicePortProtocol
JSON-RPC8080HTTP
WebSocket8081WS
gRPC50051HTTP/2
P2P5000TCP
Metrics9090HTTP

Next Steps

Troubleshooting

Port Already in Use

# Find process using port
lsof -i :8080

# Kill process
kill -9 <PID>

Connection Refused

Check if the node is running:

ps aux | grep luxd

Check firewall rules:

# macOS
sudo pfctl -s rules

# Linux
sudo iptables -L

Permission Denied

# Fix binary permissions
chmod +x ./bin/luxd

# Fix data directory permissions
chmod 755 ./data

Support