Dev.to WebDev 🛠 Dev 👁 0 📖 4 min read

One bad number almost shipped in our markets line. So we made two sources agree first.

Our news app publishes a markets line in every evening edition — S&P 500, Dow, Nasdaq, one line, right at the top of the Business section. It's a small line. It is also the line most likely to be wrong, because it comes

Our news app publishes a markets line in every evening edition — S&P 500, Dow, Nasdaq, one line, right at the top of the Business section. It's a small line. It is also the line most likely to be wrong, because it comes from a single API call to a single vendor, and nobody checks the answer before it ships.

Last week my bar for that line was three words: free, reliable, independent. Free, because the news is free and the budget for this is zero. Reliable, because a wrong number in a news product is worse than no number. Independent, because one vendor's word is not a fact — it's a claim.

No single free source passed all three. Yahoo's finance API is free and current, but on its own it fails "independent." Stooq, the other free option, was dead when we tested it. Alpha Vantage, Finnhub and Polygon all need keys on their free tiers and are still single vendors. FRED — the Federal Reserve's own data service — is free, official and independent, but it only carries daily closes and it needs a key.

So we stopped looking for one perfect source and built independence out of redundancy instead: Yahoo as the primary leg, FRED as the second, and a rule that the two have to agree before we publish anything.

The cross-check

Every close we publish goes through one endpoint. It asks Yahoo for the index, asks FRED for the same index's daily close, and compares the two on the same date. They have to match within 0.1%. If they agree, the close ships with both sources named. If they disagree, the index is omitted from the line entirely — never shown from either side — and the disagreement is logged loudly so we see it. If FRED simply hasn't published yet for that index, we fall back to Yahoo and say so: the number ships flagged as unchecked, not dressed up as verified.

That last case is not hypothetical. FRED's Nasdaq series lags a day by design. This morning's probe (Nov 24, 10:55 UTC) is a clean example of all three outcomes at once:

  • S&P 500: 6,910.39. Yahoo and FRED agree to the cent. Cross-checked.
  • Dow: 48,147.30 vs FRED's 48,147.33. Agree within 0.0001%. Cross-checked.
  • Nasdaq: 22,617.70, Yahoo only. FRED hasn't published it yet. Ships flagged unchecked.

The evening line that comes out of it reads like this, from the Nov 23 evening edition: "S&P 500 7,237 +4.7% · Dow 49,595 +3.0% · Nasdaq 24,090 +6.5%," labelled "today's close" — the first two cross-checked, the third Yahoo-only and labelled as such. A reader never has to guess which numbers were verified.

The bug that proved the system works

The cross-check earned its keep before it ever shipped a number. The first version of the endpoint pulled Yahoo's previous close from a five-day range call. That sounds harmless. It isn't: in a range call, the "previous close" is relative to the range, not to yesterday. The probe caught it in about two minutes — the S&P's previous close came back as 7,416.59 against the true 6,910.39, which would have flipped the sign on the watchlist's daily change.

The fix was small (take the value from the one-day call, take the date from the five-day bars) and it came with a regression guard, but the lesson was the point: the check has to run before the number ships, not after. Now the cross-check runs inside the endpoint on every call, and the endpoint itself refuses to publish a disputed close.

That is also why the dispute rule is "omit," not "pick the one that looks right." Picking a side in a disagreement is a guess with a byline on it. Omitting is honest: the line is shorter that day, and the reader gets numbers we can stand behind.

What it feeds

The cross-checked close now feeds the evening edition's markets line and the twice-daily business videos — a midday report at 11:30 AM CT and a close wrap-up at 3:00 PM CT — which read their numbers from the same endpoint, so the video and the edition can never disagree with each other. The individual stock quotes on the watchlist still come from Yahoo directly, unchanged.

The Business section itself got the same treatment earlier in the week. It used to carry a single story, and that story was often a lawsuit, not markets news. It now carries at least three, with markets stories preferred, drawn from CNBC and Fortune — the only two business feeds whose full text actually opens inside the app. Four other candidates failed the live extraction test outright (MarketWatch blocked, Yahoo Finance's own articles won't extract, Investing.com blocked, Barron's 403), so they are out until that changes. No exception for a blocked outlet, even when a story is missed.

What we still won't do

We don't call the intraday numbers real-time. They're delayed, and the copy says so. We don't publish a close from one source and call it verified. And when FRED is a day behind on the Nasdaq, we say the Nasdaq is unchecked rather than quietly treating Yahoo as the second source.

A free news product lives or dies on whether people trust the small numbers. The big stories get fact-checked by everyone. The markets line gets fact-checked by nobody — so we built the fact-check into the pipeline, and made it refuse to ship when it can't pass.

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.