A professional-grade paper trading simulator for Indian stock markets (NSE), built with React + Vite frontend and Node.js + Express + MongoDB Atlas backend. Real stock prices fetched live from Yahoo Finance.
| Feature | Description |
|---|---|
| ๐ Dashboard | Live portfolio value, real P&L, equity curve from actual trades, top gainers/losers |
| ๐ Market | Live/simulated NSE stock prices, interactive price charts (1W/1M/3M/1Y) |
| ๐ Stock Detail | Full stock stats, candlestick chart, news, set price alerts โ all in one page |
| ๐ผ Portfolio | Open positions with live P&L, real equity curve, sector allocation |
| ๐ Orders | Complete trade history with filters |
| โญ Watchlist | Add/remove stocks, live price updates |
| ๐ Leaderboard | Real-time ranking of all traders by P&L |
| ๐ Price Alerts | Set target prices โ server checks every 60s and triggers alerts |
| โณ Backtesting | Test 6 strategies (SMA, EMA, RSI, MACD, Bollinger, S&R) on any stock |
| โ Settings | Edit profile, avatar color, set/top-up balance, reset portfolio, data mode toggle |
| Feature | Description |
|---|---|
| Admin Dashboard | Platform-wide stats, real trade volume chart, recent users & trades |
| User Management | View all users, activate/deactivate accounts |
| All Trades | Full platform trade history with search and filters |
| Analytics | Leaderboard, sector distribution, retention chart |
| Admin Settings | Admin-level platform configuration |
Switch between two modes anytime from the sidebar or Settings:
- ๐ฎ Simulation โ Simulated prices that update every 3 seconds. Works 24/7, perfect for after-hours testing
- ๐ Live โ Real NSE prices from Yahoo Finance. Works during market hours (9:15 AM โ 3:30 PM IST, weekdays)
alphametrics/
โโโ package.json โ root โ runs both frontend + backend together
โโโ vercel.json โ Vercel deploy config (auto SPA rewrite)
โโโ backend/
โ โโโ package.json
โ โโโ .env โ MongoDB Atlas URI + JWT secret (edit this)
โ โโโ src/
โ โโโ index.js โ Express server + price alert cron job
โ โโโ seed.js โ Creates demo users in MongoDB
โ โโโ models/ โ User, Trade, Position, Alert, PnlSnapshot
โ โโโ routes/ โ auth, stocks, trades, portfolio, watchlist,
โ โ alerts, leaderboard, backtest, admin
โ โโโ middleware/ โ JWT auth guard
โโโ frontend/
โโโ package.json
โโโ vite.config.js โ Vite 5 + proxy to backend :5000
โโโ index.html
โโโ src/
โโโ main.jsx
โโโ App.jsx โ All routes defined here
โโโ index.css โ Global design system & tokens
โโโ api/index.js โ All API calls in one place
โโโ context/
โ โโโ AuthContext.jsx โ Auth, balance, watchlist, data mode state
โโโ data/
โ โโโ mockStocks.js โ Simulation mode price generator
โ โโโ mockData.jsx โ Chart helpers + backtest utilities
โโโ components/ โ AppLayout, Sidebar, Topbar, BuySellModal
โโโ pages/
โโโ AuthPage.jsx
โโโ LandingPage.jsx
โโโ user/ โ Dashboard, Market, StockDetail, Portfolio,
โ Orders, Watchlist, Backtest, Leaderboard,
โ Alerts, UserSettings
โโโ admin/ โ AdminDashboard, AdminUsers, AdminTrades,
AdminAnalytics, AdminSettings
- Node.js v18 or higher โ check with
node -v - MongoDB Atlas free account โ no local database needed
- Go to cloud.mongodb.com โ sign in or register
- Click "Build a Database" โ choose Free (M0) โ any region โ Create
- Set a Username and Password (save these!)
- Go to Network Access โ Add IP Address โ "Allow Access from Anywhere" (
0.0.0.0/0) โ Confirm - Go to Database โ Connect โ Drivers โ copy the connection string:
mongodb+srv://youruser:[email protected]/?retryWrites=true&w=majority
Open backend/.env and paste your connection string:
PORT=5000
MONGO_URI=mongodb+srv://youruser:[email protected]/alphametrics?retryWrites=true&w=majority
JWT_SECRET=alphametrics_super_secret_key_change_in_productionReplace youruser, yourpassword, and cluster0.xxxxx with your real values.
The /alphametrics at the end is the database name โ Atlas creates it automatically.
# Run from the root alphametrics/ folder
npm install
npm install --prefix backend
npm install --prefix frontendOr use the shorthand script:
npm run install:allcd backend
node src/seed.js
cd ..Expected output:
โ
Connected to MongoDB
๐ Cleared existing users
โ Created: [email protected]
โ Created: [email protected]
โ Created: [email protected]
โ Created: [email protected]
โ Created: [email protected]
โ Created: [email protected]
โ Created: [email protected]
โ Created: [email protected]
๐ฑ Seed complete! Demo accounts ready.
# From the root alphametrics/ folder
npm run devThis starts both servers simultaneously:
- Backend โ http://localhost:5000
- Frontend โ http://localhost:5173
Open http://localhost:5173 in your browser.
| Role | Password | |
|---|---|---|
| ๐ค User | [email protected] | password123 |
| ๐ค User | [email protected] | password123 |
| ๐ค User | [email protected] | password123 |
| ๐ Admin | [email protected] | admin123 |
All user accounts use
password123. Admin usesadmin123.
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/auth/signup |
Public | Register new user |
| POST | /api/auth/login |
Public | Login, returns JWT token |
| GET | /api/auth/me |
User | Get current logged-in user |
| PATCH | /api/auth/profile |
User | Update name, email, password, balance, avatar |
| POST | /api/auth/reset-portfolio |
User | Wipe trades & positions, restore balance |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/stocks |
User | All NSE quotes (60s cache) |
| GET | /api/stocks/:symbol |
User | Single stock quote |
| GET | /api/stocks/:symbol/history?period=3M |
User | Historical OHLC candles |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/trades |
User | User's full order history |
| POST | /api/trades |
User | Execute BUY or SELL order |
| GET | /api/portfolio |
User | Open positions |
| GET | /api/portfolio/equity?days=30 |
User | Real equity curve from trade history |
| GET | /api/portfolio/stats |
User | Day P&L, trade counts |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/watchlist |
User | Get watchlist symbols |
| POST | /api/watchlist/:symbol |
User | Add symbol |
| DELETE | /api/watchlist/:symbol |
User | Remove symbol |
| GET | /api/alerts |
User | Get all alerts |
| POST | /api/alerts |
User | Create price alert |
| DELETE | /api/alerts/:id |
User | Delete alert |
| PATCH | /api/alerts/:id/reset |
User | Re-arm triggered alert |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| POST | /api/backtest |
User | Run strategy backtest โ returns totalReturn, winRate, maxDrawdown, sharpeRatio |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | /api/leaderboard |
User | Top 20 traders ranked by P&L |
| GET | /api/admin/stats |
Admin | Platform KPIs |
| GET | /api/admin/users |
Admin | All users |
| PATCH | /api/admin/users/:id/status |
Admin | Activate / deactivate user |
| GET | /api/admin/trades |
Admin | All platform trades |
| Layer | Technology |
|---|---|
| Frontend | React 18.3, Vite 5.3, React Router 6.23 |
| Charts | Recharts 2.12 |
| Backend | Node.js 18+, Express 4.19 |
| Database | MongoDB Atlas + Mongoose 8.4 |
| Auth | JWT (jsonwebtoken 9.0) + bcryptjs 2.4 |
| Rate Limiting | express-rate-limit 7.1 |
| Stock Data | yahoo-finance2 2.11 (real NSE prices via .NS suffix) |
| Monorepo | concurrently 8.2 (single npm run dev command) |
Stock prices โ Yahoo Finance is queried using NSE symbols with the .NS suffix (e.g. RELIANCE.NS). Results are cached in memory for 60 seconds to avoid rate limiting.
Trading โ When a user executes a BUY, the trade is saved to MongoDB, the position is created/updated with weighted average price, and the user's balance is deducted. SELL does the reverse and calculates realized P&L.
Equity curve โ The portfolio chart is built by replaying all of the user's actual trades day-by-day from MongoDB โ not random data.
Backtesting โ The /api/backtest endpoint fetches historical OHLC data from Yahoo Finance, runs the selected strategy to generate buy/sell signals, simulates trades, and returns metrics: total return, win rate, max drawdown, and annualized Sharpe ratio.
Price alerts โ A setInterval on the backend checks all active alerts every 60 seconds against live Yahoo Finance prices and marks them as triggered when the target is hit.
JWT auth โ Tokens are stored in localStorage under am_token and sent as Bearer headers on every API request.
# Install everything
npm run install:all
# Seed demo users (run from root)
cd backend && node src/seed.js && cd ..
# Start everything
npm run dev
# Start only backend
npm run backend
# Start only frontend
npm run frontendMongoDB connection fails โ Check your Atlas URI in backend/.env. Make sure Network Access has 0.0.0.0/0 and your username/password are correct.
"Cannot find module seed.js" โ You must cd backend first before running node src/seed.js.
Market shows no data โ Switch to Simulation mode in the sidebar toggle (market may be closed). Live data only works 9:15 AM โ 3:30 PM IST on weekdays.
Vite JSX error โ Make sure all files containing JSX use the .jsx extension, not .js.
Rate limit errors โ The backend uses express-rate-limit. If you're hitting limits during development, reduce your polling interval or restart the backend server.
- Frontend โ Vercel (auto-deploy from GitHub,
vercel.jsonincluded) - Backend โ Render.com free tier (always-on Node server)
- Database โ MongoDB Atlas (already configured)
- Go to render.com โ New โ Web Service
- Connect your GitHub repo
- Set these fields:
- Root Directory:
backend - Build Command:
npm install - Start Command:
node src/index.js - Environment:
Node
- Root Directory:
- Add Environment Variables (do NOT put these in .env on GitHub):
MONGO_URI = your MongoDB Atlas URI JWT_SECRET = a strong random secret (openssl rand -hex 32) FRONTEND_URL = https://your-app.vercel.app โ add after Vercel deploy PORT = 10000 - Deploy โ copy the Render URL e.g.
https://alphametrics-api.onrender.com
- Go to vercel.com โ New Project โ Import GitHub repo
- Vercel auto-detects settings from
vercel.jsonโ no changes needed - Add Environment Variable in Vercel dashboard:
VITE_API_URL = https://alphametrics-api.onrender.com - Deploy
- Copy your Vercel URL e.g.
https://alphametrics.vercel.app - Go back to Render โ your backend service โ Environment tab
- Set
FRONTEND_URL = https://alphametrics.vercel.app - Click Save โ Render redeploys automatically
In frontend/src/api/index.js, change:
const BASE = "/api";to:
const BASE = import.meta.env.VITE_API_URL
? `${import.meta.env.VITE_API_URL}/api`
: "/api";This makes it use localhost:5000 locally and your Render URL in production.
-
backend/.envis in.gitignoreโ - All secrets set as environment variables on Render, NOT in code
- JWT_SECRET changed from the default placeholder
- MongoDB Atlas Network Access includes
0.0.0.0/0(for Render's dynamic IPs)