Trade
A real-time crypto trading dashboard: live markets, open positions and a portfolio, run on demo funds.

Live markets,demo money.
Trade is a crypto trading dashboard. You open long or short positions on markets like BTC, ETH and SOL, watch their profit and loss move with the price, and close them. The money is not real: in the engine code the balance starts at $10,000 of demo funds.
The live app has five views — Dashboard, Market, Positions, Portfolio and History. Market lists eight pairs with their last price and 24-hour change. History lists closed positions with entry, exit, margin, leverage and the realized result.
Two speeds of data.One set of numbers.
Two kinds of data move at very different speeds. Prices arrive from an exchange stream — across eight markets, several messages a second. The account — balance, open positions, unrealized P&L — belongs to the trading engine and only changes when the engine processes a trade or a price.
The numbers have to agree. If the screen and the engine compute P&L differently, the dashboard lies about money, even demo money. And the engine keeps its state in memory, so it has to stay small and its rules have to be simple enough to read.
Four decisionsbehind the numbers.
Decision 1: One socket for eight markets
The dashboard opens a single combined stream for all eight pairs instead of one connection each. Every ticker message carries its symbol, so the client maps it back to a market and replaces only that entry. One connection means one place to handle errors and one reconnect timer, and a dropped connection takes every price down together instead of leaving some cards silently stale.
NoteShipped bundle: one Binance combined stream subscribed to a ticker for each of 8 symbols. Each message updates one market in a keyed map; on close it reconnects after 3 s.

Dashboard price cards, captured from trade.pratikkk.me.
- Marker 1: 24-hour change %, from the ticker's change field
- Marker 2: Sparkline per market
- Marker 3: Last price, from the ticker's close field
Decision 2: Account numbers come from the engine, on their own clock
Prices are for looking at; the balance is the engine’s word. So the summary row never derives money from the price stream — it shows what the engine returned. For engine calls the browser only talks to its own origin and the proxy forwards them, so the client never needs the engine’s address.
NotePolls GET /api/v1/state every 5 s through a same-origin /api/proxy route, with up to 3 attempts and a growing back-off.

Summary row. The values match the engine's state response at the time of capture.
- Marker 1: Balance: balances.USD
- Marker 2: Open positions: count of positions
- Marker 3: Unrealized P&L: from each position's unrealizedPnL
Decision 3: Two status lights, because there are two sources
The two sources fail independently: prices can be live while the engine is unreachable, and the other way round. One combined “connected” light would hide which half is broken. With two, a stale balance next to moving prices explains itself.
NoteFooter: 'Trading Engine' tracks the API, 'Market Data' tracks the exchange stream. On first load I saw the engine read Disconnected while market data was already Live.

Footer status, right-hand side: the engine connection on the left, the exchange stream on the right.
Decision 4: The engine owns P&L and liquidation
All the money rules live in one small module on the server, and the UI only renders their results. Liquidation follows from the same rule: margin is the most a position can lose, so the engine closes it at that point. The losing rows in History stop at −$1,000.00 on $1,000 of margin.
Notestore.ts: long P&L = (price − entry) × quantity; short = (entry − price) × quantity. A position is closed when its unrealized P&L reaches −margin.

History totals, computed from closed positions.
- Marker 1: Closed positions, from /api/v1/positions/history
- Marker 2: Total realized P&L
- Marker 3: Win rate: 6 winning of 19 closed
An engine smallenough to read.
The backend repo is a Turborepo monorepo with three apps. market-data-service connects to the Backpack exchange WebSocket, subscribes to the SOL/USDC ticker and publishes each price to a Kafka topic. trading-engine consumes that topic, recomputes unrealized P&L for open positions, runs the liquidation check, and broadcasts the price to its own WebSocket clients. It also serves a small REST API under /api/v1: state, positions/open and positions/close.
State is plain in-memory objects: a balance map, open orders and open positions keyed by id. A position records margin, leverage, entry price and quantity, where quantity is margin × leverage ÷ entry price. The liquidation check is the whole risk system:
export const checkForLiquidations = () => {
const allOpenPositions = Object.values(openPositions);
for (const position of allOpenPositions) {
if (position.unrealizedPnL <= -position.margin) {
console.log(`[Engine] LIQUIDATING position ${position.positionId} due to excessive losses`);
const liquidationPrice = position.entryPrice + (position.unrealizedPnL / position.quantity);
closePosition(position.positionId, liquidationPrice);
}
}
}
The engine also has email magic-link sign-in (Nodemailer, a token that expires after 15 minutes). The live dashboard doesn’t show a sign-in step.
The deployed dashboard’s source isn’t in either public repo, so what I describe about it comes from the running app and its shipped JavaScript: the combined Binance stream, the 5-second state poll, the /api/proxy route with retries, and a positions/history endpoint that the public engine code doesn’t have yet. The second repo is a separate Vite + React landing page for the product, with a Framer Motion market ticker.
What I’dchange next.
Price open positions per market
Next: look up each position’s own market price wherever P&L is computed. Today open positions use one market’s price: on the live Positions table, BTC rows show SOL’s price as their current price, so their P&L % reads −998.78%, and History has ETH, BNB and BTC positions closed near $120.
Liquidation prices for shorts
The liquidation price in the excerpt above, entry + P&L ÷ quantity, is the formula for a long. Next: give shorts their own, entry − P&L ÷ quantity.
Accounts per user
The engine holds one balance and one set of positions, so everyone who opens the demo shares an account, and a restart wipes it. Next: key state by user.
Push account changes
The engine already runs a WebSocket server. Next: send state changes over it, which retires the 5-second poll and makes the summary row as live as the prices.
