A cryptocurrency trading platform with real-time price updates, authentication, and trading capabilities. The platform supports trading of BTC, ETH, and SOL with leverage, margin, and slippage controls.
The platform is built as a microservices architecture with four main components:
api-backend- Express.js API server (Bun runtime) handling authentication, trading operations, and balance managementfrontend- Next.js 14 frontend application with TypeScript and Tailwind CSSengine- Trading engine service that processes orders and manages trading logicprice-poller- Real-time price polling service that connects to Backpack Exchange WebSocket and publishes prices to Redis
- Runtime: Bun
- Framework: Express.js
- Database/Cache: Redis
- Authentication: JWT (JSON Web Tokens)
- Email: SendGrid
- Framework: Next.js
- Language: TypeScript
- Styling: Tailwind CSS
- HTTP Client: Axios
- WebSocket: ws (for price polling)
- Redis: ioredis, redis (for pub/sub and data storage)
- Bun (latest version) or Node.js
- Redis server running locally or accessible
- SendGrid API Key (for email authentication)
-
Clone the repository
git clone <repository-url> cd exness-v1
-
Install dependencies for each service
# API Backend cd api-backend bun install # Frontend cd ../frontend npm install # Engine cd ../engine bun install # Price Poller cd ../price-poller bun install
-
Set up environment variables
Create
.envfiles in each service directory:api-backend/.env:JWT_SECRET=your-secret-key SENDGRID_API_KEY=your-sendgrid-api-key SENDGRID_FROM_EMAIL=your-email@example.com
frontend/.env.local(if needed):NEXT_PUBLIC_API_URL=http://localhost:4000
-
Start Redis
redis-server
Run each service in a separate terminal:
-
Start Price Poller (must run first for price data)
cd price-poller bun run dev -
Start Trading Engine
cd engine bun run src/index.ts -
Start API Backend
cd api-backend bun run devServer runs on
http://localhost:4000 -
Start Frontend
cd frontend npm run devApplication runs on
http://localhost:3000
POST /api/v1/signup- Register new user (sends magic link email)POST /api/v1/signin- Sign in user (sends magic link email)GET /api/v1/verify?token=<token>- Verify magic link token and set cookie
GET /api/v1/supportedAssets- Get list of supported trading assets (BTC, ETH, SOL)
POST /api/v1/trades/create- Create a new trade order{ "asset": "BTC" | "ETH" | "SOL", "type": "long" | "short", "margin": number, "leverage": number, "slippage": number }POST /api/v1/trades/close- Close an existing trade order{ "orderId": "uuid" }
GET /api/v1/balance- Get all asset balances for authenticated userGET /api/v1/balance/:asset- Get balance for specific asset (BTC, ETH, SOL)
The platform uses magic link authentication:
- User provides email address
- System sends a magic link via SendGrid email
- User clicks the link to verify and authenticate
- JWT token is stored in HTTP-only cookie
All protected routes require a valid JWT token in the cookie.
- BTC (Bitcoin)
- ETH (Ethereum)
- SOL (Solana)
Prices are fetched in real-time from Backpack Exchange WebSocket API and published to Redis Streams.
- Price Updates: Price poller connects to Backpack Exchange WebSocket and publishes price updates to Redis Stream (
latest-prices) - Order Processing: API receives trade orders → publishes to Redis queue → Engine processes orders
- Balance Management: Balance requests are processed through Redis pub/sub pattern
- Real-time Updates: Frontend can subscribe to price updates and order status changes
API Backend:
bun run dev- Start development server with hot reloadbun run start- Start production serverbun run build- Build TypeScript
Frontend:
npm run dev- Start Next.js development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLint
Price Poller:
bun run dev- Start with hot reloadbun run start- Start production
- API Port: 4000 (configurable in
api-backend/src/server.ts) - Frontend Port: 3000 (Next.js default)
- Redis: Default connection (localhost:6379)
- Price Update Interval: 100ms (configurable in
price-poller/src/index.ts)
Private project