NexTrade is an open-source reference implementation of a digital asset exchange. It combines a professional trading terminal with modular TypeScript engines for spot matching, derivatives, margin, wallets, risk, compliance, client operations, and platform administration.
The project runs with seeded in-memory data by default, so contributors can explore the complete exchange workflow without provisioning infrastructure. Cloudflare D1 provides an optional persistence path, while Supabase integration is available for production-style authentication.
Warning
NexTrade is an educational and prototyping system. It has not been audited for custody, financial, security, or regulatory use. Do not use it to hold real assets or execute production trades.
- Price-time-priority spot matching with limit and market orders
- Double-entry ledger, balances, deposits, and multisignature withdrawal workflow
- USDT-margined perpetual futures, cross margin, borrowing, interest, and liquidation rules
- Pre-trade risk controls, KYC/AML workflows, alerts, and audit events
- Earn products, grid and DCA bots, smart order routing, and local rule-based signals
- CRM, tickets, affiliates, account tiers, API keys, and operator dashboards
- Responsive TanStack Start terminal backed by lightweight-charts and Remult repositories
src/ TanStack Start routes, terminal UI, server functions
packages/contracts Shared domain contracts and error codes
packages/engine-* Pure TypeScript matching, ledger, risk, margin, and strategy engines
packages/core-* Exchange workflows that compose engines and repositories
packages/data* Remult repositories plus memory and Cloudflare D1 adapters
packages/kernel Clock, event bus, fees, limits, and notifications
Business rules live in framework-independent packages. UI routes call server functions, server functions compose core-* modules, and only the data adapter knows about persistence. This keeps the matching and risk engines replaceable without duplicating domain logic.
Prerequisites: Bun 1.2+.
git clone https://github.com/uu-z/nextrade-engine.git
cd nextrade-engine
bun install
bun run devOpen the local URL printed by Vite (normally http://localhost:5173), enter any username, and the in-memory demo account will be created with seeded assets.
Memory mode requires no database. Set NEXTRADE_DATA_MODE=memory explicitly when needed.
For Supabase authentication, configure:
VITE_SUPABASE_URL=
VITE_SUPABASE_PUBLISHABLE_KEY=
SUPABASE_URL=
SUPABASE_PUBLISHABLE_KEY=
SUPABASE_SERVICE_ROLE_KEY=For Cloudflare D1 persistence, create a D1 database, update the database binding in wrangler.toml, apply d1/migrations, and set NEXTRADE_DATA_MODE=db.
bun run lint
bun run build
bun run previewSee CONTRIBUTING.md before submitting changes.
