A high-performance order execution system with real-time WebSocket updates, built with Fastify, BullMQ, PostgreSQL, and Redis.
- π Real-time Order Execution - Submit orders and get live updates via WebSocket
- π DEX Routing - Automatically finds the best prices across multiple DEXes (Raydium, Meteor)
- π Slippage Protection - Configurable slippage limits with automatic rejection
- πΎ Persistent Storage - PostgreSQL for order history, Redis for active orders
- β‘ Queue Processing - BullMQ for reliable, scalable order processing
- π Live Updates - WebSocket connections for real-time order status updates
We currently only support market orders as we can route them very easily. However, it is very easy to extend this functionality into limit orders, as we can accept the orders, keep polling the blockchain, and if the quote matches the price, we can execute the order. Sniper orders are vague. If we have to execute the order when the token is launched, that would require a very different implementation in which we poll the chain for the various tokens being created. For orders involving a certain market cap or delta, the limit order logic can be used with some changes.
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Client App β β Fastify API β β BullMQ Queue β
β β β β β β
β β’ Submit Order βββββΆβ β’ REST EndpointsβββββΆβ β’ Order Worker β
β β’ WebSocket ββββββ β’ WebSocket β β β’ DEX Routing β
β β’ Status Poll β β β’ Validation β β β’ Execution β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ
β PostgreSQL β β Redis β
β β β β
β β’ Order History β β β’ Active Orders β
β β’ Audit Trail β β β’ WebSocket β
β β’ Analytics β β Connections β
βββββββββββββββββββ βββββββββββββββββββ
- Docker & Docker Compose - For PostgreSQL and Redis services
- Node.js 18+ - For the API server
- npm - Package manager
git clone <repository-url>
cd order-execution
npm install# Start PostgreSQL and Redis
npm run docker:up
# Build and start API server
npm run api:build
npm run api:dev# Run basic test client
npx ts-node src/api/test-client.ts
# Run comprehensive test suite
npm test| Document | Description |
|---|---|
| API_USAGE.md | π Comprehensive API guide with detailed endpoints, examples, and integration instructions |
| README-Tests.md | π§ͺ Test suite overview covering 23 tests across routing, queue, and WebSocket functionality |
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Health check |
POST |
/api/orders/quote |
Get best price quote (no order placed) |
POST |
/api/orders/execute |
Submit new order for execution |
GET |
/api/orders/:orderId |
Get order status |
GET |
/api/orders |
List all orders |
GET |
/api/queue/stats |
Queue performance statistics |
GET |
/api/metrics |
DEX network statistics |
| Endpoint | Description |
|---|---|
ws://localhost:3000/api/orders/:orderId/ws |
Real-time order updates |
π For detailed API documentation: See API_USAGE.md
- 100 orders/minute throughput capacity
- 10 concurrent orders maximum
- 3 retry attempts with exponential backoff
- 30 second timeout protection
pending β routing β building β submitted β confirmed
β
failed (if any step fails)
# Monitor queue in real-time
curl http://localhost:3000/api/queue/stats
# View system metrics
curl http://localhost:3000/api/metrics# 1. Submit order
curl -X POST http://localhost:3000/api/orders/execute \
-H "Content-Type: application/json" \
-d '{"tokenIn": "SOL", "tokenOut": "USDC", "amount": 100, "maxSlippage": 0.05}'
# 2. Track status
curl http://localhost:3000/api/orders/{orderId}
# 3. WebSocket monitoring
wscat -c ws://localhost:3000/api/orders/{orderId}/wsπ For complete examples and integration guides: See API_USAGE.md
# Development
npm run api:dev # Start API server with hot reload
npm run docker:up # Start Docker services
npm run docker:down # Stop Docker services
# Testing
npm test # Run comprehensive test suite
npm run test:watch # Run tests in watch mode
# Building
npm run api:build # Build for productionπ For detailed testing information: See README-Tests.md
src/
βββ api/ # API server and services
β βββ server.ts # Fastify server
β βββ services/ # Business logic (database, queue, websocket)
β βββ types.ts # TypeScript interfaces
βββ index.ts # DEX router logic
βββ tests/ # Comprehensive test suite
# Database
DB_HOST=localhost
DB_PORT=5433
DB_NAME=order_execution
DB_USER=postgres
DB_PASSWORD=password
# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
# Server
PORT=3000
HOST=0.0.0.0| Service | Port | Purpose |
|---|---|---|
| PostgreSQL | 5433 | Order history and analytics |
| Redis | 6379 | Active orders and WebSocket connections |
# Check services
docker ps
npm run docker:logs
# Test connectivity
curl http://localhost:3000/health
# Database connection
docker-compose exec postgres psql -U postgres -d order_execution -c "SELECT 1;"
# Redis connection
docker-compose exec redis redis-cli pingPort conflicts: Docker uses ports 5433 (PostgreSQL) and 6379 (Redis)
Connection errors: Ensure npm run docker:up completed successfully
BullMQ warnings: Deprecation warnings, functionality not affected
- New to the system? Start with the Quick Start guide above
- Building an integration? See API_USAGE.md for complete API reference
- Contributing code? Check README-Tests.md for test coverage
π― Ready to try it? Follow the Quick Start guide and run npm test to verify everything works