A watchlist dashboard is a good first project with a market data API. You list some symbols, fetch their prices, and refresh a table. The one design decision that matters is where the API key lives. If the browser calls the API directly, the key ships in your page source. This tutorial builds a small Node server that holds the key and a plain JavaScript page that reads from it. Mboum's quotes endpoint takes many symbols in one request, so the whole table costs a single call.
Prerequisites
- Node.js 18 or later. It has
fetchbuilt in, so there is nothing to install. - A Mboum API key. Get one at mboum.com/pages/api.
The quotes endpoint
GET https://api.mboum.com/v1/markets/stock/quotes has weight 2 per call, whatever the number of symbols. Pass ticker with one symbol or up to 200 separated by commas. Symbols can mix asset types, so AAPL,^VIX,BTC-USD,ES=F,EURUSD=X works in one request. The body is a list of quote records in the order you asked for them. These fields are enough for a dashboard:
symbol,shortName,marketStateregularMarketPrice,regularMarketChange,regularMarketChangePercentregularMarketDayLowandregularMarketDayHighpreMarketPrice,preMarketChangePercent,postMarketPrice,postMarketChangePercentand theirTimefields. These are always present and arenullwhen there is no extended-hours price.
Two behaviors to handle. If some symbols are invalid, they are dropped and the rest come back. If every symbol is invalid, you get HTTP 200 with "success": false and the message "Invalid tickers". A missing ticker returns HTTP 422.
Step 1: the server
The server has one job: forward /api/quotes to Mboum with the key from an environment variable. It validates the symbol list and caches each result for 30 seconds, so ten open browser tabs cost one upstream call, not ten. Save it as server.js:
const http = require("http");
const fs = require("fs");
const path = require("path");
const API_KEY = process.env.MBOUM_API_KEY;
const PORT = process.env.PORT || 3000;
const CACHE_MS = 30_000;
const cache = new Map(); // symbols -> { time, body }
async function getQuotes(symbols) {
const hit = cache.get(symbols);
if (hit && Date.now() - hit.time < CACHE_MS) return hit.body;
const url = "https://api.mboum.com/v1/markets/stock/quotes?ticker=" + encodeURIComponent(symbols);
const res = await fetch(url, { headers: { Authorization: `Bearer ${API_KEY}` } });
const data = await res.json();
if (!res.ok || data.success === false || !Array.isArray(data.body)) {
throw new Error(data.message || `Request failed with status ${res.status}`);
}
cache.set(symbols, { time: Date.now(), body: data.body });
return data.body;
}
function send(res, status, type, text) {
res.writeHead(status, { "Content-Type": type });
res.end(text);
}
http
.createServer(async (req, res) => {
const url = new URL(req.url, "http://localhost");
if (url.pathname === "/api/quotes") {
const symbols = url.searchParams.get("symbols") || "";
if (!/^[A-Za-z0-9.,^=-]{1,400}$/.test(symbols)) {
return send(res, 400, "application/json", JSON.stringify({ error: "Bad symbols" }));
}
try {
const body = await getQuotes(symbols);
return send(res, 200, "application/json", JSON.stringify(body));
} catch (err) {
return send(res, 502, "application/json", JSON.stringify({ error: String(err.message) }));
}
}
fs.readFile(path.join(__dirname, "index.html"), (err, html) => {
if (err) return send(res, 500, "text/plain", "Missing index.html");
send(res, 200, "text/html", html);
});
})
.listen(PORT, () => console.log(`Watchlist on http://localhost:${PORT}`));
Step 2: the page
The page asks the server for quotes every minute and redraws the table. It builds cells with textContent, not innerHTML, so data from the API can never be treated as markup. The extended-hours column shows the newer of the pre-market and post-market prices, or a dash when both are null. Save it as index.html in the same folder:
<!doctype html>
<meta charset="utf-8">
<title>Watchlist</title>
<style>
body { font-family: system-ui, sans-serif; margin: 2rem; }
table { border-collapse: collapse; }
th, td { padding: 6px 14px; text-align: right; border-bottom: 1px solid #ddd; }
th:first-child, td:first-child { text-align: left; }
.up { color: #0a7d33; } .down { color: #c0262d; }
</style>
<table>
<thead><tr><th>Symbol</th><th>Price</th><th>Change</th><th>Day range</th><th>Extended hours</th></tr></thead>
<tbody id="rows"></tbody>
</table>
<p id="status"></p>
<script>
const SYMBOLS = ["AAPL", "MSFT", "NVDA", "TSLA", "SPY"];
const REFRESH_MS = 60_000;
const fmt = (n) => (n == null ? "-" : Number(n).toFixed(2));
const pct = (n) => (n == null ? "-" : (n >= 0 ? "+" : "") + Number(n).toFixed(2) + "%");
function extended(q) {
const prints = [];
for (const [label, key] of [["PRE", "preMarket"], ["POST", "postMarket"]]) {
if (q[key + "Price"] != null) prints.push([q[key + "Time"] || 0, label, q[key + "Price"], q[key + "ChangePercent"]]);
}
if (!prints.length) return { text: "-", cls: "" };
const [, label, price, change] = prints.sort((a, b) => b[0] - a[0])[0];
return { text: `${label} ${fmt(price)} ${pct(change)}`, cls: change >= 0 ? "up" : "down" };
}
function cell(text, cls) {
const td = document.createElement("td");
td.textContent = text;
if (cls) td.className = cls;
return td;
}
function render(quotes) {
const rows = document.getElementById("rows");
rows.replaceChildren();
for (const q of quotes) {
const tr = document.createElement("tr");
const cls = q.regularMarketChange >= 0 ? "up" : "down";
const ext = extended(q);
tr.append(
cell(q.symbol),
cell(fmt(q.regularMarketPrice)),
cell(`${fmt(q.regularMarketChange)} (${pct(q.regularMarketChangePercent)})`, cls),
cell(`${fmt(q.regularMarketDayLow)} - ${fmt(q.regularMarketDayHigh)}`),
cell(ext.text, ext.cls)
);
rows.append(tr);
}
}
async function refresh() {
const status = document.getElementById("status");
try {
const res = await fetch("/api/quotes?symbols=" + SYMBOLS.join(","));
const data = await res.json();
if (!res.ok) throw new Error(data.error || "Request failed");
render(data);
const state = data[0] ? data[0].marketState : "";
status.textContent = `Updated ${new Date().toLocaleTimeString()} - market ${state}`;
} catch (err) {
status.textContent = "Could not refresh: " + err.message;
}
}
refresh();
setInterval(refresh, REFRESH_MS);
</script>
Run it
MBOUM_API_KEY=YOUR_MBOUM_API_KEY node server.js
Open http://localhost:3000. A row looks like this. These are real values for AAPL from the last session, with the after-hours price in the last column:
AAPL 342.56 -6.65 (-1.90%) 340.56 - 354.30 POST 344.87 +0.67%
The line under the table shows the time of the last refresh and the marketState of the first symbol. Equities showed CLOSED outside trading hours in our check, and crypto and futures showed REGULAR.
Best practices
- Keep the key on the server. The browser only ever talks to your own
/api/quotesroute. - Batch, then cache. One call covers the whole list. The cache caps upstream calls at one every 30 seconds for each symbol list, however many people have the page open. Raise
CACHE_MSto spend less. - Do not trust the response shape. The server checks that
bodyis a list and treats"success": falseas an error, even on HTTP 200. - Skip refreshes when the market is closed. Equity quotes only change during trading and extended hours. If
marketStateisCLOSEDfor every row, there is nothing new to fetch.
Next steps
Change the SYMBOLS list, add a column such as fiftyTwoWeekHigh, or color rows by marketState. For every field the quotes endpoint returns, see the API documentation, and get a free key at mboum.com/pages/api.
The data is for information only. It is not investment advice.