How to build a live billionaire net worth tracker
In this tutorial you'll build the classic “Elon Musk has made $X since you opened this page” counter. It takes one request to the free Billionaire Tracker API and about 30 lines of JavaScript.
1. Get the data
Each person in the API has a perSecondUsd field: for billionaires it is the average change in net worth per second since Forbes' last annual list. Free requests cover the top 25.
cURLcurl "https://billionairetracker.us/api/v1/people/elon-musk"2. Plain JavaScript
HTML<p>Since you opened this page, <strong id="name">…</strong> made
<strong id="made">$0.00</strong></p>
<small>Data: <a href="https://billionairetracker.us">Billionaire Tracker</a></small>
<script type="module">
const res = await fetch('https://billionairetracker.us/api/v1/people/elon-musk');
const { data: p } = await res.json();
document.getElementById('name').textContent = p.name;
const start = performance.now();
const fmt = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' });
(function tick() {
const seconds = (performance.now() - start) / 1000;
document.getElementById('made').textContent = fmt.format(p.perSecondUsd * seconds);
requestAnimationFrame(tick);
})();
</script>3. React version
Reactimport { useEffect, useState } from 'react';
export function LiveEarnings({ slug = 'elon-musk' }) {
const [person, setPerson] = useState(null);
const [elapsed, setElapsed] = useState(0);
useEffect(() => {
fetch(`https://billionairetracker.us/api/v1/people/${slug}`)
.then((r) => r.json())
.then(({ data }) => setPerson(data));
}, [slug]);
useEffect(() => {
const start = performance.now();
let raf;
const tick = (t) => { setElapsed((t - start) / 1000); raf = requestAnimationFrame(tick); };
raf = requestAnimationFrame(tick);
return () => cancelAnimationFrame(raf);
}, []);
if (!person) return null;
const made = (person.perSecondUsd * elapsed).toLocaleString('en-US', { style: 'currency', currency: 'USD' });
return (
<p>
Since you opened this page, {person.name} made <strong>{made}</strong>.{' '}
<small>Data: <a href="https://billionairetracker.us">Billionaire Tracker</a></small>
</p>
);
}4. Go further
- Show the live ranking with
/api/v1/rankings?limit=10. - Add daily winners and losers with
/api/v1/movers(Starter plan). - Chart a fortune over time using
historyfrom/api/v1/people/{slug}(Starter plan). - Cache responses for a minute or two — the data refreshes every 15 minutes, so there's no need to call it on every page view.
See the full API reference or the billionaire net worth API guide. Want to see the finished thing? It's what powers our Elon Musk live tracker.