An alert that fits the free plan
By the end of this lesson you will have npm run alert:local: a command that reads your alert rules, says what its run costs before spending anything, fetches one end-of-day series per symbol and prints which rules fired. In mock mode it costs nothing.
What you will see: a terminal showing the run's price, in your agent's own words (for example 2 symbols: 2 calls live, 0 in mock mode for the starter's AAPL.US and the one symbol you add a fixture for), one FIRED line with rule, symbol, close, bar date and threshold, and a quiet line for each other rule.
Where this course starts
Why your alert did not fire listed what an alert needs: a schedule, data fresh enough to matter, somewhere to keep state, and a way to reach you. This course builds all four.
If you came through Build a Dashboard, you already have a rules module for the cockpit. This one is separate on purpose: it lives in src/lib/alerts/ and reads alerts/rules.json, because it runs from a script on a schedule with no browser and no server store. Reuse is a later decision, not this lesson's.
Straight from Start From Zero is fine: you need your fork of the starter, a free EODHD APIs key and a coding agent — Claude Code or Codex CLI, both shown wherever they differ. Neither is free: Claude Code needs a paid Claude plan (Pro is $20 a month billed monthly) or an Anthropic Console API key, and Codex CLI needs ChatGPT Plus or an OpenAI API key. An IDE's agent mode follows the same prompts too, since they all read AGENTS.md.
The idea: price it before you build it
The cockpit's alert loop needed 936 calls a day, because live quotes cost a call per symbol and it checked every five minutes. An end-of-day alert asks one question per symbol per trading day, and one request answers it. That one call returns several closes, and your alert reads the last two, so a crossing needs no stored history:
| Request | Cost |
|---|---|
| End-of-day series, one symbol | 1 call, any number of rows |
| Your account's usage | 0 |
| Live quotes | 1 call per symbol |
| News | 5 calls per ticker |
| Fundamentals | 10 calls |
Five symbols once a day cost 5 × 1 = 5 calls. The free plan allows 20, resetting at midnight GMT, which leaves room for a live test and a re-run. Three things never fit:
- Headlines. News costs 5 calls per ticker; four tickers are the whole day.
- Fundamentals per symbol. Ten calls each.
- A typo. A ticker that does not exist is still billed, on every run. Validate rules before the first fetch.
The EODHD MCP server from Connect EODHD to your agent is billed the same way, so point the agent at the fixtures while developing.
What the alert says: rule, symbol, close, threshold, and the date of the bar, not the time the job ran. It is a notice that a number crossed your line, not a recommendation; nothing in this course is investment advice.
The prompt
With EODHD_MOCK=1 in .env.local, start your agent in the repository and paste:
Read AGENTS.md. Plan an end-of-day price alert that runs as a script, and show me the plan before writing code.
- alerts/rules.json holds rules as data: id, symbol, op (crosses_above or crosses_below), value. src/lib/alerts/rules.ts validates them on read: an unknown op, a symbol without an exchange suffix or a duplicate id stops the run before any fetch, naming the rule.
- src/lib/alerts/evaluate.ts: a pure evaluate(rule, bars) comparing the last two daily closes with the threshold. No fetch, no clock, no printing.
- scripts/alert.ts: read the time once and pass it down; fetch eod/SYMBOL once per distinct symbol through eodhdFetch(), from ten days back; print FIRED or quiet per rule with symbol, close, bar date and threshold. First print the run's live cost from estimateCalls() in src/lib/cost.ts.
- package.json: "alert" runs tsx scripts/alert.ts, "alert:local" runs tsx --env-file=.env.local scripts/alert.ts; tsx as a dev dependency.
- A fixture under fixtures/eod/ for a second symbol whose last two closes cross a rule, so exactly one rule fires in mock mode.
- tests/alert-evaluate.test.ts: crossing up, crossing down, no crossing, a close exactly on the threshold, fewer than two bars.
Mock mode only; run nothing live. Run npm test and show me the diff.
What the agent should do. New: the rules, src/lib/alerts/, scripts/alert.ts, a test file, a fixture. Changed: package.json and the lockfile; tsx is there because plain Node does not resolve the starter's @/ import alias. In the plan, check where the previous close comes from: a plan that stores it in a file missed that the response carries it. Keep the rules to two symbols, AAPL.US and the new one: mock mode answers from fixtures/eod/, and a third symbol with no fixture there gets a 404.
Check it yourself
npm testpasses, with the new tests.npm run alert:localprints the price line, oneFIREDline and aquietline for the rest. That script reads.env.local, so create it withEODHD_MOCK=1first; without the file, setEODHD_MOCK=1in your shell and runnpm run alertinstead. In mock mode the fixtures ignore the date the script asks for, so the bars may start earlier than the "from" date it prints: that is the mock, not a bug.- Change the firing rule's
optocrosses_below: it goes quiet. Change it back. - Ask the agent what
evaluate()does when the close equals the threshold, and compare with your test. - Once, live: set
EODHD_MOCK=0, read the usage meter on the starter's page, runnpm run alert:local, wait a few seconds (the counter lags) and read it again. It rose by your number of distinct symbols. SetEODHD_MOCK=1again. This one needs your own key: thedemokey's meter is shared by everyone using it, so it never moves by exactly your count, anddemoanswers only a handful of symbols (AAPL.USandMSFT.USamong them).
Break it on purpose
Remove the exchange suffix from one rule's symbol: the run must stop before the price line, naming the rule. Then use a suffixed ticker that does not exist. Mock mode answers 404, as the live API would, and live that 404 is billed. Make the output name the rule.
Compare with ours
Add the starter as a remote once, git remote add upstream https://github.com/EodHistoricalData/academy-dashboard-starter.git, then git fetch upstream and git diff upstream/ref/runs-without-you/1.
Our version, on branch ref/runs-without-you/1
| File | What it holds |
|---|---|
src/lib/alerts/rules.ts |
parseRules(), which throws naming the rule |
src/lib/alerts/evaluate.ts |
evaluate(), nine lines |
scripts/alert.ts |
time once, rules, distinct symbols, price, fetch, print |
const [prev, last] = bars.slice(-2);
const fires = rule.op === "crosses_above"
? prev.close <= rule.value && last.close > rule.value
: prev.close >= rule.value && last.close < rule.value;
A close exactly on the line does not fire; the next close above it does, because the one before was not above. Whichever you choose, the printed sentence and the test must agree.
Try it now
Checkpoint: commit what works before the next lesson changes it.
- Commit:
npm test
git status # the files you expect, and no .env file
git add -A
git commit -m "feat(alert): end-of-day rules, a pure evaluator, a runner that prices itself"
- Write the day's budget at the top of
PLAN.md: symbols, calls per run, the runs you allow yourself, the reserve. - Take the lesson check. It asks you to price an alert you have not seen, and what a close exactly on the line does.