TestYourTrade
Paper trading on live Indian market prices.
DEMO limit order book
2,418.60120
2,418.20340
2,417.9075
2,417.40210
2,417.10460
2,416.8090
Limit buy filled at 2,417.40
Learning to trade shouldn't cost real money. TestYourTrade gives you a virtual ₹10,00,000, live NSE prices, market and limit orders, short selling, a portfolio and a leaderboard.
Measured
- upstream feed per symbol, shared by every user
- 1
- tables with row-level security
- 6
- symbols a client can watch at once
- 100
Problem
Live prices have to reach every viewer instantly, and every limit order has to fill the moment the price crosses it, without opening one market-data connection per user.
Architecture
- External
- Service
- Worker
- Interface
- Storage
One upstream subscription per symbol feeds a broadcast service that pushes ticks into a Socket.io room per symbol. On every tick, the matcher queries the Redis order book for limit orders the new price has crossed and fills them, including partial fills at a weighted average price.
Decisions
Redis sorted sets as the order book
Orders are scored by price in separate buy and sell sets per symbol, so finding every order a tick has crossed is one range query.
A shared, reference-counted feed
The first viewer of a symbol opens its upstream subscription and the last one to leave closes it, which keeps the app inside the market-data provider's limits.
Rooms per symbol
Fan-out cost grows with the viewers of one symbol, not with every connected user. A Redis adapter lets the socket layer scale across servers.
Postgres with row-level security
Orders, trades and balances live in Postgres with per-user policies on all six tables, plus Redis locks around balance changes.
Hard parts
Partial fills
A partly filled order is re-queued with its remaining quantity, and its average price is updated by weight.
Upstream drops
The market-data client reconnects automatically, and the socket layer falls back to in-memory mode when Redis isn't configured.
Quality
- Playwright specs for limit orders, short positions and live order updates, plus unit tests for balances, portfolio maths and the subscription registry.