Contents Lesson 16 of 19

11 min read · professional

What "real-time" actually means

By the end of this lesson you will have an age on every quote panel computed from the response's own timestamp, a measured update interval for one liquid and one thin instrument written in PLAN.md, and a small script that took those samples after telling you what they would cost.

The word does more work in marketing than in engineering. Before you design a refresh strategy, you need to know what your data actually is.

Three different things wear the name

End of day. One bar per trading day, finalised after the close — finalised, not settled, which is the separate cash-for-shares step and lands a day later. Yesterday's truth, and the right data for a backtest — Backtest Strategies ran entirely on it.

Delayed. Real trades, shown after a lag. The number is right; it describes a moment that has passed.

Live. As close to now as a consumer feed gets, which still is not the exchange's own clock.

A dashboard mixing these without labels is the most confidently wrong artefact in this whole track, because all three render as a number with two decimal places.

Read the age, do not trust the name

You already have the technique from Build Your First Tool. The response carries a timestamp; use it:

{"code":"AAPL.US","timestamp":1787689680,"gmtoffset":0,"close":309.90,"change_p":-0.1418}

1787689680 is Unix seconds — 2026-08-25 20:28:00 UTC. Subtract from now and you have the true age of that number, whatever any plan description says.

Two things to know about that field. It is timezone-independent, so gmtoffset is for display only and never for arithmetic. And it is the timestamp of the last trade, not of your request — so a thinly traded instrument reports an age of hours during an open market and is not broken.

Different symbols, different ages, one response

From the same measured fixture:

[{"code":"AAPL.US","timestamp":1787689680},
 {"code":"MSFT.US","timestamp":1787689680},
 {"code":"TSLA.US","timestamp":1787689740}]

Sixty seconds apart, in one response, for three of the most liquid stocks in the world — and read the clock while you are there: 20:28 UTC is 16:28 in New York, so those are after-hours prints on a feed stamped to the minute. In the session three names this liquid sit within seconds of each other. On a thin instrument the spread is much larger.

So there is no single "as of" for a cockpit. Per-panel ages, and a header showing the oldest — which unit 3 already established and which this lesson explains the reason for.

Refresh rate cannot exceed the data rate

The mistake that wastes the most quota in this course: polling every five seconds a feed that moves about once a minute and is fifteen to twenty minutes behind anyway.

You now have the measurement to prevent it. Poll a symbol repeatedly for a few minutes, log the distinct timestamps, and compute the median gap between changes. That gap is the fastest useful refresh interval. Anything faster spends calls to fetch a number you already have.

Do it for one liquid and one thin instrument. The liquid one's gap is the feed's own step, a minute on a feed stamped to the minute; the thin one's is however long it goes between trades, and that is the number that decides how often its panel is worth refreshing.

What the market is doing matters too

A closed market produces no new trades. A cockpit refreshing through the night is spending its allowance to re-fetch the same closing price several hundred times.

Refresh only while the relevant market is open, and pause when the tab is hidden. Two conditions, and together they usually cut a day's usage by more than any other change in this course.

The finance behind it

What the word means on a quote, from the data side: What does "delayed" actually mean on a live quote?. And why a market that never closes still stops: Why does FX trade around the clock but stop for the weekend?

Try it now

Measure the update interval of one liquid and one thin instrument on your own plan, and write both in PLAN.md. Then compare them to the refresh rate you were about to choose — for most people the honest number is many times slower than the intended one.

The prompt

Mock mode on, plan mode on, and paste:

Plan, then build. In src/lib/age.ts add ageSeconds(timestamp, now) on
Unix seconds, ignoring gmtoffset, and medianGap(timestamps): the median
of the gaps between distinct consecutive values. Test both first in
tests/age.test.ts with literal timestamps. Show each quote panel's age
from its own rows, and the oldest of them in the header. The screen and
the backtest rows carry a date, not a timestamp: those panels say end
of day and name the date, and so does the header. Then write
scripts/sample-interval.mjs: run as node scripts/sample-interval.mjs
SYMBOL N --yes, it asks the running dev server's proxy for that
symbol's real-time quote N times, a minute apart, and prints each
timestamp and the median gap; without --yes it prints the price and
stops. It runs on plain Node with no warnings. Before any live run,
tell me with estimateCalls what N samples of one symbol cost against
my allowance, and wait for my yes. Mock mode for the tests. Mock mode for everything else. Run npm test,
typecheck, lint and check:leak, and show me the diff first.

A good answer adds src/lib/age.ts, its test and the script, and changes the panels' headers in the container. The samples themselves are the one step in this lesson that spends calls, and the agent asks before it. To take them: stop the dev server, comment out the EODHD_MOCK=1 line in .env.local, make sure the key line holds your key, start npm run dev again, run the two commands below, write the two medians and today's date into PLAN.md yourself, then put the mock line back and restart the server.

Instrument Command
A US stock, liquid in the session node scripts/sample-interval.mjs AAPL.US 3 --yes
Bitcoin, which trades around the clock node scripts/sample-interval.mjs BTC-USD.CC 3 --yes

Keep the exchange suffix: the demo key covers these two symbols only with it, and a bare BTC-USD answers 403. Both are liquid, so on demo the pair shows the feed's step twice; with your own key, swap the second for a thinly traded stock to see the gap widen.

Check it yourself

  1. tests/age.test.ts treats a repeated timestamp as the same trade seen again, not as a gap of zero.
  2. Before the live run the agent named its price: one call per sample per symbol.
  3. PLAN.md holds the two intervals you measured, the date you took them and whether the market was open. Measuring needs your key: in mock mode every sample is the same fixture and the script reports no change. If you have no key yet, or no calls to spare today, leave the two lines blank with that reason beside them rather than writing a guess.
  4. Each quote panel shows its own age, and the header shows the oldest of them; the screen and backtest panels say end of day with their date.
Compare with ours
// src/lib/age.ts: the response's clock, not the plan's name for it
export const ageSeconds = (timestamp: number, now: number) =>
  Math.max(0, Math.floor(now / 1000) - timestamp);   // Unix seconds; gmtoffset never enters

export function medianGap(timestamps: number[]): number | null {
  const distinct = [...new Set(timestamps)].sort((a, b) => a - b);
  const gaps = distinct.slice(1).map((t, i) => t - distinct[i]).sort((a, b) => a - b);
  if (gaps.length === 0) return null;
  const mid = Math.floor(gaps.length / 2);
  return gaps.length % 2 === 1 ? gaps[mid] : (gaps[mid - 1] + gaps[mid]) / 2;
}

Ours runs on fixtures with no key, so its two interval lines are blank with that reason beside them; yours are a measurement and belong there with the date and whether the market was open. The full state at the end of this unit is on the starter's branch ref/build-a-dashboard/u4.

Checkpoint

npm test && npm run typecheck
git status          # the files you expect, and no .env file
git add -A
git commit -m "Ages from the response's timestamp; update intervals measured, not assumed"

Then answer this lesson's questions.