Contents Lesson 7 of 7

8 min read · practitioner

The wall: intraday alerts are a plan question

By the end of this lesson you will have npm run alert:cost, which prices your own rules three ways (end of day, live quotes every 15 minutes, intraday bars every 15 minutes) with estimateCalls() and no calls at all, and a decision in PLAN.md: stay, change the question, or upgrade.

What you will see: a three-row table in your terminal, such as end of day: 5 calls a day, live quotes every 15 minutes: 130, intraday bars every 15 minutes: 650, with your allowance underneath and the rows that fit marked.

The idea: your alert answers one kind of question

An end-of-day alert tells you, ninety minutes after the close, that the close crossed your line. For a level you would act on tomorrow morning that is the right product, and it is free. Tell me while it happens changes three things, and only one is code.

The arithmetic, for five symbols

The US session is 09:30 to 16:00 in New York, six and a half hours, so a check every 15 minutes is 26 checks.

Version One check Per day
End of day, once 5 symbols at 1 call 5
Live quotes, every 15 minutes 5 symbols at 1 call 26 × 5 = 130
Intraday bars, every 15 minutes 5 requests at 5 calls 26 × 25 = 650
Live quotes, every 5 minutes 5 symbols at 1 call 78 × 5 = 390

Against 20 a day, the live version spends 130 ÷ 20 = 6.5 free days every day, and intraday 650 ÷ 20 = 32.5. A snapshot of the whole US market is 100 calls in one request, and it is yesterday's close from the bulk endpoint, which the free plan does not include, not a live price. None of that is a defect in your code; as The real-time wall said, the price list is the wall.

The scheduler is a wall too

Even with calls to spare, a cron job is the wrong shape for while it happens. GitHub's shortest interval is five minutes and scheduled runs can be delayed or dropped; a 15-minute alert that starts 20 minutes late has missed its move. Live alerts want a process that stays connected and is told when a price moves, such as the EODHD APIs WebSockets feed in this lesson's sources, on a machine that stays on. That is a different product.

When upgrading is the honest answer

Three questions, in order:

  • Would you act during the session? If you act tomorrow morning anyway, end-of-day is right, and free.
  • Has the alert changed a decision yet? Run the end-of-day version for a month; if it changed nothing, a faster one will not.
  • Is the limit speed or breadth? Fifteen symbols once a day fit; forty do not. Breadth is a plan question too, and a cheaper one.

Yes, yes and speed is what a paid plan is for, and you can now state the need (symbols, interval, calls a day) against the pricing page. Prices are not quoted here on purpose: a price in a lesson goes stale. A 403 says your plan does not cover some data; the plan says what does.

What survives an upgrade: rules, evaluator, delivery, state, retries, heartbeat and every test. What changes: the fetcher, the schedule, the key (bar date to bar time), the staleness threshold and the heartbeat period. That list is short because of lessons 1 to 6.

The prompt

Add npm run alert:cost (scripts/alert-cost.ts). It takes an optional path to a rules file, default alerts/rules.json; read that file and print, for its distinct symbols, the calls per day of: end of day once after the close; live quotes every 15 minutes through a 6.5-hour session; intraday bars every 15 minutes, one request per symbol.
Price every request with estimateCalls() from src/lib/cost.ts; never hard-code a cost. Under the table, print the free plan's 20 calls a day and mark what fits. No network, no key.
Add a test that three symbols give 3, 78 and 390.

What the agent should do. One script, one package.json line, one test. The intraday row must come from estimateCalls() on an intraday path, not from a 5 typed into the script; if you see a price written as a number, ask where it came from.

Check it yourself

  1. npm run alert:cost prints three rows, and the end-of-day row equals your number of distinct symbols.
  2. Work one row out by hand from the table above and compare.
  3. Copy alerts/rules.json to alerts/rules-more.json, add three rules on three more symbols, and run npm run alert:cost -- alerts/rules-more.json. Every row grows in proportion, and only the end-of-day row is likely to stay under 20. Delete the copy.
  4. npm test passes, including the new test.
  5. Write your three answers from When upgrading is the honest answer in PLAN.md, and the decision under them.

Break it on purpose

Replace the intraday row's estimateCalls() with a hard-coded 1. The row now claims intraday is as cheap as live, and your test fails. A price you copy is a price that drifts, which is why the costs live in one table.

Compare with ours

git fetch upstream, then git diff upstream/ref/runs-without-you/7 -- scripts tests.

Our version, on branch ref/runs-without-you/7
const checks = Math.floor(390 / 15);
const [first, ...rest] = symbols;
const live = checks * (estimateCalls(`real-time/${first}`, { s: rest.join(",") }) ?? NaN);
const intraday = checks * symbols.length * (estimateCalls(`intraday/${first}`) ?? NaN);

A missing price prints as a gap, never as zero: an unknown cost means "look it up".

What the exam asks

Ten questions, seventy percent to pass, a twenty-four hour cooldown, from a pool, so a retake is a different paper. Every fixture is fixed. Expect to price an alert, read a cron line in New York time in both seasons, name the quiet failure behind a symptom, order a send and a record, pick retry, wait or stop for a status code, and judge whether a ping proves the job worked.

The finance behind it

What the word means on a quote: What does "delayed" actually mean on a live quote?

Try it now

Checkpoint: the course's last commit, and a decision.

  1. Commit:
npm test
git status          # the files you expect, and no .env file
git add -A
git commit -m "feat(alert): price the end-of-day, live and intraday versions of the alert"
  1. Put one sentence in your README's limitations section: what the alert checks, when it runs, and what it cannot do.
  2. Take the lesson check, then the course exam.