A full‑stack virtual trading platform focused on the Indian equity markets (NSE/BSE). AlgoArena provides a risk‑free environment to practice manual trading and to build, backtest, and deploy custom algorithmic trading strategies.
- Part A: Foundational Trading Platform
- Part B: Pluggable Strategy API
- Stress Testing
- Technology Stack
- Project Structure
- Setup & Installation
- Testing the Backtester
- License
- Secure user authentication with cookie-based sessions and email verification.
- Initial virtual corpus: ₹1 Crore for every new user.
- Manual market BUY and SELL order execution for NSE/BSE stocks.
- Dynamic portfolio dashboard with live updates for holdings, P&L, and cash balance.
- Complete, filterable trade history.
- Integrates with Yahoo Finance (
yahoo-finance2) for real-time and historical data. - Interactive candlestick charts using TradingView Lightweight Charts™.
- Live market status indicator based on actual NSE/BSE market hours.
- Redis caching with dynamic TTLs for all market data endpoints to ensure data freshness and high performance.
- Dynamic polling during market hours (frontend polls backend every 10s for live price updates).
This is the core technical challenge of the platform, allowing users to connect their own algorithms.
- Strategy Registration: Users can register their external trading algorithms by providing a name and a webhook URL.
- Backtesting Engine: Users can run simulations for their registered strategies against historical stock data. The engine iterates through historical data points, sends each data slice to the user's webhook, and executes trades based on the algorithm's
BUY/SELLJSON response. - Performance Reports: After each backtest, a detailed performance report is generated and stored, including metrics like Net Profit, % Return, and Win Rate.
- Historical Results: Users can view a history of all past backtest results for each of their registered strategies.
A comprehensive stress test was performed on major API endpoints using k6. The final HTML report is available at:
server/test/stress-test-report.html
-
Frontend (client/)
- Next.js 14 (App Router)
- TypeScript
- Tailwind CSS
- Zustand (state management)
- Axios (API requests)
- TradingView Lightweight Charts™ (charting)
- Lucide React, Sonner (UI/icons/notifications)
-
Backend (server/)
- Node.js + Express
- MongoDB with Mongoose
- Redis for caching
- Cookie‑based sessions for authentication
yahoo‑finance2for market data
/
├── client/ (Next.js frontend)
│ ├── src/
│ │ ├── app/
│ │ │ ├── (auth)/ (Login, Register pages)
│ │ │ ├── (dashboard)/ (Authenticated pages)
│ │ │ └── page.tsx (Homepage)
│ │ ├── components/
│ │ ├── lib/ (API services)
│ │ └── store/ (Zustand stores)
│ └── tailwind.config.ts
└── server/ (Node backend)
├── src/
│ ├── config/
│ ├── controllers/
│ ├── middlewares/
│ ├── models/
│ └── routes/
│ ├── test/ (k6 stress test script & report)
└── index.js
- Node.js v18+
- npm or yarn
k6(for stress testing)- MongoDB connection URI
- Redis connection URL
- Navigate to the
serverdirectory and install dependencies:cd server npm install - Create a
.envfile in theserverroot (refer toserver/.env.example) and set:MONGO_URI=your_mongodb_uri REDIS_URL=your_redis_url JWT_SECRET=a_strong_secret_key FRONTEND_URL=http://localhost:3000
- Start the backend server:
npm run dev # Default port: 4000 (adjust in server code/env as needed)
- Navigate to the
clientdirectory and install dependencies:cd client npm install - Create
.env.localin the client root with:NEXT_PUBLIC_API_URL=http://localhost:4000
- Start the frontend:
npm run dev # Default port: 3000
To test the Part B Pluggable Strategy API you need a simple webhook server that can receive backtester POSTs and respond with trade instructions.
A minimal example server (provided in the repo under strategy-testing/strategy-server.js) can be started like this:
- Open a new terminal.
- Navigate to the strategy-testing directory:
cd strategy-testing node strategy-server.js - The example server listens on
http://localhost:5001by default. Use this URL as the "Webhook URL" when registering a strategy in the AlgoArena UI.
Notes:
- The backtester posts market snapshots (JSON) to the webhook. The webhook should respond with JSON like:
or
{ "action": "BUY", "symbol": "XYZ", "quantity": 100 }{ "action": "SELL", "symbol": "XYZ", "quantity": 100 } - The sample server in
strategy-testingdemonstrates the expected request/response shape and can be extended to implement more complex strategy logic.
- Fork the repo, create a feature branch, and submit pull requests with clear descriptions.
- Keep changes modular and follow the feature-based directory structure.