Examples

Complete, production-ready trading examples for LX

Trading Examples

Complete, copy-paste ready examples for building trading systems on LX.

Quick Start

All examples connect to LX and demonstrate real trading patterns. Before running:

# Start local LX node
cd /path/to/lx/dex
make build
./bin/lxd --config config/local.yaml

# Or connect to testnet
export LX_ENDPOINT="https://testnet.lx.exchange"

Examples by Language

LanguageDescriptionComplexity
Go TraderHigh-performance Go trading botIntermediate
Python TraderPython trading bot with pandasBeginner
TypeScript TraderTypeScript/Node.js trading botBeginner
Rust TraderZero-copy Rust trading botAdvanced
C++ TraderUltra-low latency C++ botAdvanced

Strategy Examples

StrategyDescriptionRisk Level
Market MakerProvide liquidity, earn spreadMedium
ArbitrageCross-exchange price differencesLow
Grid TradingRange-bound automated tradingMedium
Data CollectorMarket data storage and analysisN/A

Environment Setup

Go

# Initialize module
mkdir my-trader && cd my-trader
go mod init my-trader

# Add LX SDK
go get github.com/lx-exchange/lx-sdk-go@latest

Python

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install SDK
pip install lx-sdk websockets pandas numpy

TypeScript

# Initialize project
mkdir my-trader && cd my-trader
npm init -y

# Install SDK
npm install @lx-exchange/sdk axios ws
npm install -D typescript @types/node @types/ws

Rust

# Create project
cargo new my-trader
cd my-trader

# Add to Cargo.toml
# [dependencies]
# lx-sdk = "0.1"
# tokio = { version = "1", features = ["full"] }
# serde = { version = "1", features = ["derive"] }

C++

# Requirements
# - CMake 3.16+
# - C++20 compiler
# - vcpkg or conan for dependencies

# Install dependencies
vcpkg install nlohmann-json websocketpp openssl

Configuration

All examples use environment variables for configuration:

# Required
export LX_API_KEY="your-api-key"
export LX_API_SECRET="your-api-secret"

# Optional
export LX_ENDPOINT="http://localhost:8080"      # JSON-RPC endpoint
export LX_WS_ENDPOINT="ws://localhost:8081"     # WebSocket endpoint
export LX_GRPC_ENDPOINT="localhost:50051"       # gRPC endpoint

# Trading parameters
export TRADING_SYMBOL="BTC-USD"
export MAX_POSITION_SIZE="1.0"
export MAX_ORDER_SIZE="0.1"

Safety Guidelines

  1. Always use testnet first - Never test with real funds
  2. Set position limits - Define maximum exposure before trading
  3. Implement kill switches - Emergency stop functionality is required
  4. Monitor continuously - Never run unattended without alerting
  5. Log everything - Detailed logs for audit and debugging

Performance Benchmarks

LanguageOrders/secLatency p99Memory
C++500,000+12us50MB
Rust450,000+15us45MB
Go300,000+25us80MB
TypeScript50,000+500us150MB
Python10,000+2ms200MB

Source Code

All examples are available on GitHub:

Support