You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A real-time stock exchange simulator with a custom order matching engine, Redis-backed order book, BullMQ background jobs, and an ML prediction microservice — built to simulate how real exchanges like NSE and NASDAQ operate under the hood.
TradeSphere is a full-stack, three-service microservice system that simulates a real stock exchange. It is not a CRUD application — it implements actual financial system concepts:
A custom order matching engine that pairs buy and sell orders when price conditions are met
A Redis-backed order book using sorted sets for O(log n) order insertion and retrieval
BullMQ background workers so heavy tasks never block the Express API
A separate Flask ML microservice that trains on real OHLCV data and predicts next-day stock prices
Socket.IO rooms per stock symbol so clients only receive updates for stocks they are watching
User Places Order → Node API → Redis Order Book → Matching Engine
→ Trade Recorded (MongoDB) → Portfolios Updated → Socket.IO Broadcast
→ All watching clients receive live update
Request Flow — ML Prediction
Premium User clicks Predict → Node API → BullMQ Queue
→ Worker calls Flask /predict → Model trains on real OHLCV data
→ Result stored in MongoDB → Socket.IO emits to user
→ PredictionChart.jsx renders Actual vs Predicted graph
✨ Features
🔐 Authentication System
Register / Login with JWT
Three roles: User, Premium, Admin
Role-based route protection on both backend and frontend
Password hashing with bcryptjs
JWT blacklist on logout via Redis
📊 Virtual Stock Market
Admin creates stocks with symbol, initial price, and volatility factor
Each stock tracks current price, volume, market cap, and full price history
Live price ticker scrolling across the top of the UI
⚡ Trading System
Market Orders — execute instantly at the best available price
Limit Orders — sit in the order book until a matching order arrives
Partial fills supported — if quantities don't match exactly, the remainder stays in the book
git clone https://github.com/yourusername/tradesphere.git
cd tradesphere
2. Start the ML Service
cd tradesphere-ml
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env # add your Alpha Vantage key
python app.py
# Running on http://localhost:5001
3. Start the Backend
cd tradesphere-backend
npm install
cp .env.example .env # fill in MongoDB URI, Redis URL, JWT secret
npm run dev
# Running on http://localhost:3000
4. Start the Frontend
cd tradesphere-frontend
npm install
cp .env.example .env # set VITE_API_URL and VITE_SOCKET_URL
npm run dev
# Running on http://localhost:5173
5. Seed stock data (optional but recommended)
# Train ML models with real Alpha Vantage data
curl -X POST http://localhost:5001/train/AAPL
curl -X POST http://localhost:5001/train/TSLA
curl -X POST http://localhost:5001/train/MSFT
⭐ If you found this project useful, please give it a star!
Built with ❤️ to simulate real financial systems
About
TradeSphere — Real-time stock exchange simulator with order matching engine, Redis order book, BullMQ background jobs, Socket.IO live updates, and ML-powered price predictions via a Flask microservice.