AKJ
All projects

Case study

TRADEXCEL

A gamified stock market simulator with live NSE prices, weekly competitions and an in-house ML assistant.

Chapters

~258

live-priced NSE stocks

₹1L

virtual cash per player

~9 ms

per assistant reply

95%

advice-refusal recall

OVERVIEW

What & why!

Tradexcel lets anyone learn how the stock market works without risking a rupee. Every player starts with ₹1,00,000 in virtual cash and can trade about 258 NSE-listed stocks at real market prices, streamed live while the market is open.

Around the trading engine sit the things that make people come back: weekly seasons that reset everyone to the same starting line, leaderboards, private leagues, 1v1 duels, quests that teach the basics, and Tex, an assistant that answers questions without a hosted LLM.

HOW IT WORKS

From a price tick to your screen!

  1. 1

    Yahoo Finance

    Quotes cached 12s while the market is open, 30 min when it's closed.

  2. 2

    Price broadcast loop

    One central 5-second loop fetches only symbols someone is watching and emits real changes.

  3. 3

    Express + Prisma trading engine

    Market, limit and stop-loss orders; open orders reserve the cash or shares they need.

  4. 4

    PostgreSQL ledger

    Every trade runs in one transaction; check constraints reject negative balances.

  5. 5

    Socket.IO

    Prices and a marketStatus event, so the UI shows “Market closed” instead of a fake “Live”.

  6. 6

    Next.js dashboard

    Charts, portfolio analytics against NIFTY 50, leaderboards and contests.

INTERESTING PROBLEMS

The fun parts!

Money math that can't drift

All money uses Prisma.Decimal, never floats. Buys and sells lock the user's ledger, validate funds, write the holding and an immutable transaction row, and update the wallet in a single $transaction, with database check constraints as a last line of defence.

Live prices without hammering the API

Instead of one fetch per viewer, a single broadcast loop fetches quotes once for every symbol anyone is watching and only emits real changes, while market-hours-aware caching keeps Yahoo Finance traffic low.

An assistant with no hosted LLM

Tex runs guard rules first (it never gives investment advice), then a fine-tuned 22M-parameter MiniLM encoder with a 13-intent head and dense retrieval over 142 hand-written cards. Exported to ONNX and served inside Express, it fits on a 1 GB VM.

Fair, isolated competitions

Weekly seasons snapshot and reset every wallet each Monday. Contests use their own entry, holding and transaction tables, so league trading never touches a player's main wallet.

STACK

Built with!

Frontend
Next.js 16, React, TypeScript, Redux Toolkit, Tailwind CSS, Framer Motion, lightweight-charts
Backend
Node, Express, Prisma, PostgreSQL, Socket.IO, node-cron, Zod, Helmet
ML
PyTorch, sentence-transformers, scikit-learn, ONNX, transformers.js
Testing
Vitest, Testing Library, Playwright, pytest

Next case study

Argus