1
Setup
Claude edited this page 2026-04-03 11:12:45 +01:00
Setup
Docker Deployment (Recommended)
The trade backend is published as the Docker image lthn/trade-api:testnet. It requires a running Lethean daemon, wallet RPC, and a PostgreSQL instance.
docker-compose.yml
services:
trade-api:
image: lthn/trade-api:testnet
ports:
- "3336:3336"
environment:
PORT: "3336"
PGUSER: "postgres"
PGPASSWORD: "strong-password-here"
PGHOST: "postgres"
PGDATABASE: "lethean_trade"
PGPORT: "5432"
JWT_SECRET: "change-me-to-a-real-secret"
OWNER_ALIAS: "admin"
DAEMON_RPC_URL: "http://daemon:46941/json_rpc"
WALLET_RPC_URL: "http://wallet:46944/json_rpc"
depends_on:
- postgres
- daemon
postgres:
image: postgres:16
environment:
POSTGRES_PASSWORD: "strong-password-here"
volumes:
- pgdata:/var/lib/postgresql/data
daemon:
image: lthn/chain:testnet
# Exposes RPC on port 46941 (testnet) / 36941 (mainnet)
volumes:
pgdata:
Required Services
| Service | Purpose | Default Port |
|---|---|---|
| PostgreSQL | Order book, users, transactions, chat storage | 5432 |
| Lethean Daemon | Asset discovery, chain queries | 46941 (testnet) / 36941 (mainnet) |
| Lethean Wallet RPC | Wallet signature verification, transfers | 46944 (testnet) / 36944 (mainnet) |
The backend will automatically create the database if it does not exist (it connects to the postgres database first and issues CREATE DATABASE).
Default Port
The trade API listens on port 3336 when using the recommended Docker configuration. The PORT environment variable controls this; the application default (when unset) is 3000.
Local Development
Prerequisites
- Node.js 20+
- PostgreSQL 14+
- Lethean daemon running with RPC enabled
- Lethean wallet RPC running
Steps
# Clone the repository
git clone ssh://git@forge.lthn.ai:2223/lthn/trade-backend.git
cd trade-backend
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env -- at minimum set PGPASSWORD and JWT_SECRET
# Start in development mode (with hot reload)
npm run dev
# Or start in production mode
npm start
Available Scripts
| Script | Command | Description |
|---|---|---|
dev |
nodemon --exec tsx ./src/server.ts |
Development with hot-reload |
start |
tsx ./src/server.ts |
Production start |
format |
prettier --write . |
Format all files |
format:check |
prettier --check . |
Check formatting |
Startup Sequence
On boot the backend:
- Creates the PostgreSQL database if it does not exist
- Authenticates and syncs the Sequelize schema
- Sets up model associations
- Ensures the LTHN base currency row exists
- Promotes the
OWNER_ALIASuser to admin (if set) - Starts background workers:
- Assets update checker -- polls
explorer.lethean.ioandapi.lethean.iohourly - Orders moderation service -- periodic order maintenance
- Auth messages clean service -- purges expired auth challenges
- Pair stats daemon -- updates 24h price/volume statistics
- Stats model -- initialises always-active pair tracking
- Assets update checker -- polls
- Starts the Socket.IO server
- Mounts Express middleware and routes
- Begins listening on the configured port