A sector heatmap answers one question at a glance: where is the money moving today? Technology is up 3%, utilities are flat, one sector is red. You see it in a second, without reading a table.
You do not need sector data feeds to build one. The 11 Select Sector SPDR ETFs each track one sector of the S&P 500, and a single quotes call returns all of them. This guide builds the whole thing: a tiny Node.js server that calls SteadyAPI, and a plain HTML page that draws color-coded tiles. There are no frameworks and no npm packages.
Prerequisites
- A SteadyAPI API key from steadyapi.com. The Free plan works for a demo. Read the cost section first.
- Node.js 18 or newer. It has
fetchbuilt in. - A browser.
One call for every sector
Use GET https://api.steadyapi.com/v1/markets/stock/quotes (weight 2). It takes up to 200 comma-separated symbols in ticker, and it works for ETFs as well as stocks. The sector funds are:
- XLK: Technology
- XLF: Financials
- XLE: Energy
- XLV: Health Care
- XLY: Consumer Discretionary
- XLP: Consumer Staples
- XLI: Industrials
- XLB: Materials
- XLU: Utilities
- XLRE: Real Estate
- XLC: Communication
For each fund we need three fields from the response body:
symbolregularMarketPriceregularMarketChangePercent: the change from the previous close, as a percentage number.1.86means +1.86%.
Quote values are numbers, so there is nothing to parse. The marketState field (REGULAR, PRE, POST) tells the page whether the market is open.
Why there is a server
Do not call the API from the browser. Anyone who opens developer tools could read your API key and spend your quota. The page talks to your own server, and the server holds the key.
The server also protects your request count. It keeps the last response for 30 seconds. A hundred visitors in the same minute cost two API calls, not two hundred.
The server
Save as server.js:
const http = require("http");
const fs = require("fs");
const API_KEY = process.env.STEADYAPI_KEY;
const BASE = process.env.STEADYAPI_BASE || "https://api.steadyapi.com";
const SECTORS = {
XLK: "Technology", XLF: "Financials", XLE: "Energy", XLV: "Health Care",
XLY: "Consumer Discretionary", XLP: "Consumer Staples", XLI: "Industrials",
XLB: "Materials", XLU: "Utilities", XLRE: "Real Estate", XLC: "Communication",
};
let cache = { at: 0, data: null };
async function loadSectors() {
if (cache.data && Date.now() - cache.at < 30000) return cache.data; // one API call per 30 s
const url = `${BASE}/v1/markets/stock/quotes?ticker=${Object.keys(SECTORS).join(",")}`;
const res = await fetch(url, { headers: { Authorization: `Bearer ${API_KEY}` } });
if (!res.ok) throw new Error(`API returned ${res.status}`);
const json = await res.json();
if (json.success === false) throw new Error(json.message || "Request failed");
const sectors = json.body.map((q) => ({
symbol: q.symbol,
name: SECTORS[q.symbol] || q.symbol,
price: q.regularMarketPrice,
change: q.regularMarketChangePercent,
}));
cache = { at: Date.now(), data: { state: json.body[0]?.marketState, sectors } };
return cache.data;
}
http.createServer(async (req, res) => {
if (req.url === "/api/sectors") {
try {
res.writeHead(200, { "Content-Type": "application/json" });
res.end(JSON.stringify(await loadSectors()));
} catch (err) {
res.writeHead(502, { "Content-Type": "application/json" });
res.end(JSON.stringify({ error: err.message }));
}
} else {
res.writeHead(200, { "Content-Type": "text/html" });
res.end(fs.readFileSync(__dirname + "/index.html"));
}
}).listen(3000, () => console.log("http://localhost:3000"));
It exposes one route, /api/sectors, and serves index.html for everything else. If the API fails, it returns a 502 with the message, and the page shows a retry notice.
The page
Save as index.html in the same folder:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sector heatmap</title>
<style>
body { font-family: system-ui, sans-serif; background: #111; color: #eee; margin: 24px; }
#map { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.tile { padding: 16px; border-radius: 6px; min-height: 90px; }
.tile b { display: block; font-size: 1.1rem; }
.tile .pct { font-size: 1.6rem; font-weight: 700; }
#status { color: #999; margin-top: 12px; font-size: .9rem; }
</style>
</head>
<body>
<h1>US sector performance</h1>
<div id="map"></div>
<div id="status">Loading...</div>
<script>
// Maps a % change to a color. Anything beyond +/-3% gets the strongest shade.
function color(pct) {
const t = Math.max(-1, Math.min(1, pct / 3));
const hue = t >= 0 ? 145 : 0;
return `hsl(${hue}, ${20 + Math.abs(t) * 50}%, ${22 + Math.abs(t) * 14}%)`;
}
async function refresh() {
let next = 30000;
try {
const res = await fetch("/api/sectors");
if (!res.ok) throw new Error("Server error");
const { state, sectors } = await res.json();
sectors.sort((a, b) => b.change - a.change);
const map = document.getElementById("map");
map.replaceChildren(...sectors.map((s) => {
const tile = document.createElement("div");
tile.className = "tile";
tile.style.background = color(s.change);
tile.innerHTML = "<b></b><span></span><div class='pct'></div>";
tile.querySelector("b").textContent = s.name;
tile.querySelector("span").textContent = `${s.symbol} ${s.price.toFixed(2)}`;
tile.querySelector(".pct").textContent = `${s.change >= 0 ? "+" : ""}${s.change.toFixed(2)}%`;
return tile;
}));
document.getElementById("status").textContent =
`Market state: ${state}. Updated ${new Date().toLocaleTimeString()}.`;
if (state !== "REGULAR") next = 300000; // slow down outside the regular session
} catch (err) {
document.getElementById("status").textContent = "Could not load data. Retrying.";
}
setTimeout(refresh, next);
}
refresh();
</script>
</body>
</html>
Three details are worth a look.
- The color scale.
color()clamps the change to plus or minus 3% and scales the saturation and lightness. A 3% mover is bright. A 0.05% mover is nearly gray. Change the3to widen or narrow the range. - Safe text. Names and prices go in through
textContent, never as raw HTML. - Adaptive refresh. While the market is in its regular session, the page refreshes every 30 seconds. At any other time it slows to every 5 minutes. Prices do not move overnight.
Run it
STEADYAPI_KEY=YOUR_STEADYAPI_KEY node server.js
Open http://localhost:3000. You should see 11 tiles, sorted from strongest to weakest.
Count your requests
Each refresh that reaches the API costs 2 requests. Over a 6.5-hour regular session, one page refreshing every 30 seconds makes about 780 calls, which is 1,560 request units. The server cache means more visitors do not raise that number.
The Free plan's 500 requests a month is 250 refreshes. For a demo on Free, raise the 30-second cache to 5 minutes, or run the page only while you test. For a dashboard that stays open all day, use a paid plan.
Where to take it
- Size by weight. The quote also has
netAssets. Use it to make bigger funds bigger tiles with CSS grid spans. - Show extended hours. Outside the regular session,
postMarketChangePercentandpreMarketChangePercenthold the extended-hours change. The extended-hours movers guide covers those fields. - Add a benchmark. Put
SPYin the list and compare each sector with the index. - Drill down. Click a tile and draw a price chart from the history endpoint,
GET /v1/markets/stock/history. - Polling design. For choices between polling and push, see the polling comparison.
The quotes and history guide explains the quote fields in more detail.
Conclusion
One quotes call, a 30-second cache, and about 100 lines of code give you a live sector heatmap. The key stays on your server, and the request count stays flat however many people look.
Create a free account at steadyapi.com (no card required), run the server, and read the API documentation for every quote field and ready-made examples in cURL, JavaScript, PHP, and Python.