Contents Lesson 8 of 18

11 min read · foundations

Your tickers, in one request

By the end of this lesson you will have your own instruments in src/lib/watchlist.ts, at least one of them listed outside the US, and the change on one row checked by hand against the raw response.

Time to replace the demo list with your own instruments and make the whole thing cost one request.

The list is a file you edit

In the starter, your watchlist lives in src/lib/watchlist.ts:

export const WATCHLIST: string[] = [
  "AAPL.US",
  "MSFT.US",
  "NVDA.US",
  "SPY.US",
  "BTC-USD.CC",
];

A file, not a database, and deliberately so. You are one person watching your own instruments; a database would be a second thing to run, back up and pay for, in exchange for a convenience you do not yet need. When editing a file stops being enough, because you want to add a symbol from your phone, that is a real reason to add storage, and it arrives in a later course.

Ticker format, and the part that surprises people

EODHD identifiers are SYMBOL.EXCHANGE:

Ticker What it is
AAPL.US Apple, US listing
VOD.LSE Vodafone, London
SAP.XETRA SAP, Frankfurt
BTC-USD.CC Bitcoin against the dollar
EURUSD.FOREX Euro against the dollar

The exchange suffix is part of the identity, not decoration: the same company listed in two places is two tickers with two prices, often in two currencies. Vodafone is pence in London and dollars in New York; SAP is euros on both Xetra and Frankfurt. Different price either way, and the currency is the trap you have to check rather than assume.

And the currency is not in the response. VOD.LSE quotes in pence, not pounds, a London convention that has produced more wrong dashboards than any other single fact in this course. If you mix AAPL.US and VOD.LSE in one column and sum them, you have added dollars to pence and produced a number that means nothing. Either keep one currency per view, or label the column per row. Do not silently total a mixed list.

One request, whatever the length

The endpoint takes the first ticker in the path and the rest in s:

const [first, ...rest] = tickers;
const params = rest.length ? `?s=${rest.join(",")}` : "";
const res = await fetch(`/api/proxy/real-time/${first}${params}`);

Five instruments, one request. Twenty instruments, still one request — but twenty calls, because /real-time is priced per symbol. The saving is in round trips, not in quota, and there is a second saving worth more than it looks: every row in one response was taken at the same moment, so your table shows one snapshot rather than twenty arriving at twenty different times.

Your watchlist therefore costs list length × page loads. Both numbers are yours to choose, and the wall in unit 4 is where they meet your allowance.

Handle both response shapes, because you now know about the bare object:

const body: unknown = await res.json();
const rows = Array.isArray(body) ? body : [body];

Trust the fields, verify the values

From a live response on 2026-08-25:

{"code":"AAPL.US","timestamp":1787603280,"close":310.34,
 "previousClose":309.35,"change":0.99,"change_p":0.32,"volume":32510925}

change is close - previousClose: 310.34 minus 309.35 is 0.99. Correct. change_p is that as a percentage of previousClose: 0.99 / 309.35 = 0.32%. Correct.

Do that arithmetic once, by hand, on a real response. It takes a minute and it tells you what the field means, which is the difference between using an API and hoping.

Note what change is not: it is not the move since the open, and it is not the move over 24 hours. It is measured from the previous session's close. Once Monday is trading, change spans the weekend gap — but before the open, which is when this tool was planned to run, the pair is still Friday's close against Thursday's, so the figure is Friday's session move and contains no weekend at all.

Render numbers so they can be read

Two rules, both cheap, both the difference between a tool and a toy:

Tabular figures. font-variant-numeric: tabular-nums makes every digit the same width, so a column of prices lines up. Without it, 1,234.56 and 987.65 are ragged and your eye cannot scan them.

The sign carries the direction, not just the colour. Print +0.99 and -6.24, then colour them. Colour alone fails for a colour-blind reader, a bad screen, and a printout, and you will read this tool on a phone in sunlight.

Try it now

The prompt

Mock mode on. Pick the instruments you actually check, including at least one that is not US-listed. (Why the fixture matters: in mock mode a ticker that has no row in fixtures/real-time.json is answered the way the API answers an unknown symbol, with every field "NA", and the starter's shape check drops that row, so the ticker silently never appears. "Done means the tests are green", two lessons on, makes such rows visible; until then a missing fixture row means a missing ticker.) Paste:

Replace WATCHLIST in src/lib/watchlist.ts with these tickers, in this
order: [your tickers]. Before you edit, tell me what one page load will
cost live with pageLoadCalls() in src/lib/quotes.ts, and which of my
tickers have no row in fixtures/real-time.json. For each of those, add a
row to the fixture in the same shape with invented numbers, so mock mode
shows it. Change no other file, run npm test, and show me the diff.

A good answer states the cost — one call per ticker, on every load — before touching anything, lists the tickers the fixture lacks, and changes two files: src/lib/watchlist.ts and fixtures/real-time.json.

Check it yourself

  1. The cost the agent stated equals the length of your list, and the line under the meter says the same in mock mode.
  2. Every ticker shows in mock mode, the invented rows included.
  3. Go live once to check the arithmetic; it costs one call per ticker, and it needs a key of your own (the demo token covers only a few symbols, and one ticker it does not cover makes the whole request fail with 403, so a list that mixes covered and uncovered names shows nothing). Without a key, stay in mock mode: the arithmetic below holds for the invented rows too, which you wrote to be consistent. Open one row's raw quote through your own proxy, at /api/proxy/real-time/ followed by the ticker on the address npm run dev prints (usually http://localhost:3000), and compare its shape with this one, captured live on 2026-08-25:
    {"code":"AAPL.US","close":310.34,"previousClose":309.35,"change":0.99,"change_p":0.32}
    
    change should be close minus previousClose, and change_p that as a percentage of previousClose, to rounding.
  4. If your list has both a US and a London name, look at the two prices side by side and say out loud what units each is in.

Compare with ours

Ours
File What changed
src/lib/watchlist.ts AAPL.US, MSFT.US, SPY.US, plus VOD.LSE, with a comment that it is quoted in pence
fixtures/real-time.json one invented VOD.LSE row in the same shape, so mock mode shows it

The full state at the end of this unit is on the starter's branch ref/build-your-first-tool/u2.

Checkpoint

git status   # only the files you expect, and no .env*
git add -A
git commit -m "My own tickers, one quoted in pence, so the units have to be read"

Then answer this lesson's questions.