A gamified trading simulator controlled by a physical Adafruit device. Trade simulated tokens using buy/sell buttons and LED color signals. The system includes levels, PnL tracking, trading rules, and a fast price-simulation engine.
/apps
/backend - Node.js REST API + WebSocket server
/frontend - Next.js frontend with real-time charts
/device-simulator - Simulated Adafruit hardware controller
/packages
/price-simulator - Fast token price simulation engine
/trading-engine - CEX-like trading engine
/types - Shared TypeScript types
/utils - Shared utility functions
- Monorepo: pnpm + Turborepo
- Backend: Node.js + Express + WebSocket
- Frontend: Next.js 14 + React + Tailwind CSS + Recharts
- Language: TypeScript (strict mode)
- Validation: Zod
- Testing: Jest
- Node.js >= 18.0.0
- pnpm >= 8.0.0
# Install dependencies
pnpm install
# Build all packages
pnpm build# Start all services in development mode
pnpm dev
# Or start individually:
cd apps/backend && pnpm dev
cd apps/frontend && pnpm dev
cd apps/device-simulator && pnpm dev# Run all tests
pnpm test
# Run tests for a specific package
cd packages/price-simulator && pnpm test
cd packages/trading-engine && pnpm test- Noob Mode: Fixed position sizes ($50), safety limits (max 80% position)
- DeGen Mode: Percentage-based position sizing (10% of balance)
- Pro Mode: Dynamic position sizing with profit targets and stop losses
- Patterns: Pump, dump, rug pull, chop, whale spike, parabolic, slow grind
- Trend Signals: Up (green), Down (red), Sideways (yellow), Whale (purple), Rug (orange)
- Difficulty-based volatility: Higher volatility in Pro mode
- XP System: Gain XP based on realized PnL
- Level Progression: Level = floor(sqrt(XP / 100)) + 1
- Realized & Unrealized PnL: Track both realized gains and paper gains
- Session Management: Start/reset trading sessions
- WebSocket Communication: Real-time LED color signals
- Button Controls: BUY, SELL, PANIC EXIT
- Notifications: Level-up alerts, price alerts
POST /trade/buy- Execute buy tradePOST /trade/sell- Execute sell tradeGET /state?userId=<id>- Get current game statePOST /session/start- Start a new trading sessionPOST /session/reset- Reset user session
Connect to ws://localhost:3001 and subscribe:
{ "type": "subscribe", "userId": "default" }Messages received:
{ "type": "price", "data": { price, timestamp, trend } }{ "type": "device", "data": { type, color, message } }
-
Start Backend:
cd apps/backend && pnpm dev -
Start Frontend:
cd apps/frontend && pnpm dev(runs on http://localhost:3000) -
Start Device Simulator (optional):
cd apps/device-simulator && pnpm dev -
Open http://localhost:3000 in your browser
-
Select difficulty mode (Noob/DeGen/Pro)
-
Start trading using the BUY/SELL buttons
-
Watch the real-time price chart and LED signals
Environment variables:
PORT- Backend port (default: 3001)NEXT_PUBLIC_API_URL- Frontend API URL (default: http://localhost:3001)WS_URL- Device simulator WebSocket URL (default: ws://localhost:3001)
Each package includes Jest tests:
# Price Simulator Tests
cd packages/price-simulator
pnpm test
# Trading Engine Tests
cd packages/trading-engine
pnpm testThe device-simulator app simulates the Adafruit hardware. To integrate real hardware:
-
Replace WebSocket client with GPIO handlers
-
Use libraries like:
rpi-gpiofor Raspberry Pijohnny-fivefor Arduino/Adafruit boardsadafruit-circuitpythonfor CircuitPython
-
Map physical buttons to trade actions:
- Button 1 → BUY
- Button 2 → SELL
- Button 3 → PANIC EXIT
-
Map LED signals to colors:
- Green → Up trend
- Red → Down trend
- Yellow → Sideways
- Purple → Whale activity
- Orange → Rug pull
MIT
This is a hackathon project. Feel free to fork and extend!