C.W.K.
Stream
Lesson 03 of 05 · published

FX Never Crosses the Line

~10 min · fx, domain-boundaries, provider-policy, separation

Level 0Open Gate
0 XP0/36 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete
"Just because two things both come from 'the internet' doesn't mean they share a backup plan."

Currency is a different domain

Keep tracks two portfolios that mix US and Korean value, so the USD/KRW exchange rate is a first-class number, not an afterthought. And it has its own provider boundary, deliberately separate from equities. Massive's daily REST aggregate is primary for USD/KRW. Its only confirmed fallback is FRED's DEXKOUS series — the US Federal Reserve's official daily rate. And the rule that matters most: FX never crosses into Yahoo, even though Yahoo is a fallback for equities. The equity fallback list and the FX fallback list are separate universes.

Why not just one global fallback chain?

Because a fallback is only valid within a domain where the substitute is genuinely comparable. Yahoo's equity quotes are a reasonable stand-in for Massive's equity quotes — same kind of data, similar conventions. But an FX rate is a different kind of measurement, and letting the equity fallback logic reach over and grab a currency number from a source that wasn't vetted for FX would be mixing domains. FRED's DEXKOUS is vetted specifically as an FX source — an official, authoritative daily rate. The boundary says: an FX value may only ever come from an FX-approved source, full stop.

Fallbacks are scoped to a domain, not to a network. 'Both are available online' is not a reason two sources are interchangeable. A valid fallback is one that's been vetted as comparable for that specific kind of data. Cross-domain substitution — grabbing a currency rate from a stock source because the code path happened to reach it — is how quietly-wrong numbers get in.

The shape this creates

Instead of one tangled fallback tree where anything can substitute for anything under enough failures, Keep has a small set of clean, per-domain boundaries: equities have their primary and their confirmed equity fallbacks; FX has its primary and its one confirmed FX fallback; specific instruments have their policy sources. Each boundary is small enough to hold in your head and reason about. "Where could this USD/KRW number possibly have come from?" has a two-item answer, not a shrug.

Authoritative beats convenient for a base measurement. FRED DEXKOUS is chosen as the FX fallback partly because it's an official central-bank series — for something as foundational as the rate that converts one half of the family's wealth into the other, you want the most authoritative available source, not merely the most convenient API that happens to also return currency numbers.

Code

Per-domain fallback tables, never one global chain·python
# Equities have their own vetted fallbacks.
EQUITY_SOURCES = {"primary": "massive", "fallbacks": ["yahoo", "stooq"]}

# FX has a SEPARATE table. Yahoo is deliberately absent here.
FX_SOURCES = {"primary": "massive_daily_rest", "fallbacks": ["fred_dexkous"]}

def resolve_fx(pair, *, confirmed_source=None):
    try:
        return fetch(FX_SOURCES["primary"], pair)
    except ProviderError:
        # An FX value may ONLY come from an FX-approved source.
        # There is no code path that lets an equity fallback serve FX.
        if confirmed_source in FX_SOURCES["fallbacks"]:
            return fetch(confirmed_source, pair)
        raise FallbackConfirmationRequired(candidate="fred_dexkous")

External links

Exercise

Imagine a system that fetches two genuinely different kinds of data (say, temperatures and stock prices) and has a generic 'try the next provider' fallback. Describe the bug where a failure in one domain causes a value to be served from a source that was only ever vetted for the other. Then redesign it with per-domain fallback tables and state the invariant that prevents the cross-domain leak.
Hint
A single global fallback list is seductive because it's DRY. But 'don't repeat yourself' is the wrong axis here — the whole point is that these domains must NOT share a fallback. Separate tables aren't duplication; they're the boundary that keeps a currency rate from ever being served by a stock API.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.