A production-quality perpetual futures trading platform built on the Unicity Sphere SDK. Trade BTC, ETH, SOL, and more with up to 100x leverage, powered by off-chain matching with on-chain UCT settlement.
- Sphere Wallet Auth — Connect via Sphere Connect protocol with cryptographic sign-in
- Perpetual Trading — Market & limit orders, long/short, cross & isolated margin
- Risk Engine — Liquidation price, maintenance margin, funding payments, auto-liquidation
- Live Market Data — Binance Futures WebSocket price feeds with candlestick charts
- AI Features — Trade journal, market summaries, risk scoring, trading coach
- Social — Leaderboards, referrals, achievements, competitions
- Admin Dashboard — Market management, trading freeze, system health
| Layer | Technology |
|---|---|
| Frontend | React, Vite, TypeScript, TailwindCSS, shadcn/ui, React Query, Zustand |
| Charts | TradingView Lightweight Charts |
| Backend | Node.js, Express, TypeScript |
| Database | PostgreSQL, Prisma ORM |
| Realtime | WebSockets |
| Wallet | Unicity Sphere SDK (Connect) |
| Prices | Binance Futures API |
sphere-perps/
├── backend/
│ ├── prisma/ # Database schema & seed
│ └── src/
│ ├── routes/ # REST API endpoints
│ ├── services/ # Trading engine, risk engine, AI, Sphere
│ └── websocket/ # Real-time price & notification hub
├── frontend/
│ └── src/
│ ├── components/ # Trading UI, wallet, layout
│ ├── pages/ # Trade, Dashboard, Leaderboard, Admin
│ ├── lib/ # API client, Sphere wallet, WebSocket
│ └── stores/ # Zustand state
└── docker-compose.yml
- Node.js 20+
- Sphere Wallet (browser extension or web)
- PostgreSQL — optional for local dev (SQLite is the default)
cd sphere-perps
npm installPostgreSQL is required. Pick one option:
Option A — Docker (local):
- Start Docker Desktop and wait until it shows "Running"
- Run:
# Windows
.\scripts\setup-db.ps1 -UseDocker# Mac/Linux
docker compose up postgres -d
cd backend && npm run db:setupOption B — Neon (free cloud, no Docker):
- Create a free database at neon.tech
- Copy the connection string into
backend/.env:DATABASE_URL=postgresql://user:pass@ep-xxx.region.aws.neon.tech/neondb?sslmode=require - Run:
cd backend && npm run db:setup
Troubleshooting: If you see
Can't reach database server at localhost:5432, Docker Desktop is not running. Either start Docker Desktop, or use Neon (Option B).
# From project root — starts both frontend & backend
npm run dev- Frontend: http://localhost:5173
- Backend API: http://localhost:4000
- WebSocket: ws://localhost:4000/ws
- Open http://localhost:5173
- Click Connect Wallet
- Approve connection in Sphere Wallet
- Sign the authentication message
- Deposit UCT to start trading
| Route | Description |
|---|---|
POST /auth/nonce |
Get auth challenge |
POST /auth/verify |
Verify signature & get JWT |
GET /markets |
List trading markets |
GET /prices/:symbol/candles |
OHLCV candle data |
POST /orders |
Place order |
GET /positions |
Open positions with live PnL |
POST /deposits |
Credit trading balance |
POST /withdrawals |
Withdraw UCT via Sphere |
GET /ai/risk-score |
AI trade risk assessment |
GET /leaderboard/:period |
Trading leaderboard |
GET /admin/dashboard |
Admin analytics |
DATABASE_URL=postgresql://sphere:sphere_dev_password@localhost:5432/sphere_perps
JWT_SECRET=your-secret-key
CORS_ORIGIN=http://localhost:5173
SPHERE_ORACLE_API_KEY=sk_ddc3cfcc001e4a28ac3fad7407f99590
SPHERE_TREASURY_NAMETAG=sphere-perps-treasury
SPHERE_TREASURY_MNEMONIC= # Optional: for live withdrawals
AI_PROVIDER=mock # mock | openai | spacexai
ADMIN_WALLET_PUBKEYS= # Comma-separated admin pubkeysVITE_API_URL=/api
VITE_WS_URL=ws://localhost:4000/ws
VITE_SPHERE_WALLET_URL=https://sphere.unicity.networkdocker compose up --buildServices:
- postgres — PostgreSQL on port 5432
- backend — API on port 4000
- frontend — Nginx on port 5173
cd frontend
vercel --prodSet environment variables in Vercel dashboard.
- Connect repository
- Set
DATABASE_URLto Supabase/Neon PostgreSQL - Set all backend environment variables
- Deploy with
npm run build && npm start
Create a PostgreSQL instance and use the connection string as DATABASE_URL.
The platform uses an off-chain matching engine with on-chain settlement:
- Deposits/Withdrawals — Settled via Sphere SDK UCT transfers
- Trading — Matched internally against Binance mark prices
- Liquidation — Automatic when maintenance margin is breached
- Funding — Periodic funding rate payments every 8 hours
Margin Used = Notional / LeverageLiquidation Price (Long) = Entry × (1 - 1/Leverage + MMR)Unrealized PnL = (Mark - Entry) × Size(long)ROE = Unrealized PnL / Margin Used × 100
Markets are defined in backend/prisma/seed.ts. To add a new asset:
{ symbol: 'XRP/USD', baseAsset: 'XRP', binanceSymbol: 'XRPUSDT', sortOrder: 7 }Or via Admin API:
POST /admin/markets
{
"symbol": "XRP/USD",
"baseAsset": "XRP",
"binanceSymbol": "XRPUSDT",
"tickSize": 0.0001,
"lotSize": 1,
"minOrderSize": 1
}The codebase is structured for:
- Prediction markets
- Options trading
- Copy trading & vaults
- Social trading & AI agents
- Yield products & NFT achievements
- Mobile app (React Native)
MIT