OpenBB-finance/OpenBB · error · ValueError

Invalid exchange: '{value}'. Accepts ISO 10383 MIC codes (e.

Error message

Invalid exchange: '{value}'. Accepts ISO 10383 MIC codes (e.g., 'XNAS', 'XNYS'), acronyms (e.g., 'NASDAQ', 'NYSE'), or exchange names (e.g., 'New York Stock Exchange').

What it means

Raised by Exchange.__new__._lookup_exchange (exchange_utils.py) when the value cannot be resolved in the ISO 10383 lookup table. It tries lowercase, uppercase, and original-case forms of MIC codes ('XNAS'), acronyms ('NASDAQ'), and exchange names; failure raises this ValueError. Exchange is a Pydantic annotated type, so it fires during validation wherever an 'exchange' parameter is normalized.

Source

Thrown at openbb_platform/core/openbb_core/provider/utils/exchange_utils.py:173

        # Convert lower_snake_case to lookup key
        if "_" in val:
            val = val.replace("_", " ")

        # Try direct lookup
        lookup_key = val.lower()
        if lookup_key in _EXCHANGE_LOOKUP:
            return _EXCHANGE_LOOKUP[lookup_key]

        # Try uppercase (common for MICs)
        if val.upper() in _EXCHANGE_LOOKUP:
            return _EXCHANGE_LOOKUP[val.upper()]

        # Try original case
        if val in _EXCHANGE_LOOKUP:
            return _EXCHANGE_LOOKUP[val]

        raise ValueError(
            f"Invalid exchange: '{value}'. "
            "Accepts ISO 10383 MIC codes (e.g., 'XNAS', 'XNYS'), "
            "acronyms (e.g., 'NASDAQ', 'NYSE'), "
            "or exchange names (e.g., 'New York Stock Exchange')."
        )

    @property
    def mic(self) -> str:
        """ISO 10383 Market Identifier Code (e.g., 'XNAS')."""
        return self._exchange_data["mic"]

    @property
    def acronym(self) -> str:
        """Exchange acronym/short name (e.g., 'NASDAQ')."""
        return self._exchange_data["acronym"]

    @property
    def name(self) -> str:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use the official ISO 10383 MIC (operating MIC): 'XNAS' for NASDAQ, 'XNYS' for NYSE, 'XLON' for London
  2. Or a well-known acronym/name: 'NASDAQ', 'New York Stock Exchange'
  3. Search the packaged table to confirm what is accepted: from openbb_core.provider.utils.exchange_utils import _EXCHANGE_LOOKUP; [k for k in _EXCHANGE_LOOKUP if 'nasdaq' in k]
  4. If the MIC is legitimately missing, regenerate the exchange data via openbb_core.provider.utils.update_exchange_data or file an issue

Example fix

# before
res = await obb.equity.price.quote(symbol="AAPL")  # with exchange="NMS" -> ValueError (Yahoo-style code)

# after
res = await obb.equity.price.quote(symbol="AAPL")  # with exchange="XNAS" (ISO 10383 MIC)
Defensive patterns

Strategy: validation

Validate before calling

from openbb_core.provider.utils.exchange_utils import _EXCHANGE_LOOKUP

def is_known_exchange(v: str) -> bool:
    return v.lower() in _EXCHANGE_LOOKUP or v.upper() in _EXCHANGE_LOOKUP or v in _EXCHANGE_LOOKUP

if not is_known_exchange(exchange):
    exchange = "XNAS"  # or strip 'SYM:EXCH' composites first

Type guard

def is_mic_like(v: str) -> bool:
    return len(v) == 4 and v.isalpha() and v.isupper()

Try / catch

from pydantic import ValidationError

try:
    res = await obb.equity.price.quote(symbol=sym, exchange=exchange)
except ValidationError as e:
    if any("Invalid exchange" in str(err["msg"]) for err in e.errors()):
        res = await obb.equity.price.quote(symbol=sym)  # retry without exchange
    else:
        raise

Prevention

When it happens

Trigger: Passing a non-MIC ticker-ish string ('NYSE:AAPL' instead of 'XNYS'), an unknown acronym ('TSX' may map, 'LSE' depends on table), a deprecated/operating-status-excluded MIC, or a non-string value that fails all three dict lookups.

Common situations: Copying exchange identifiers from other APIs (Yahoo/Reuters codes like 'NMS' or 'NYSE'), using composite 'symbol:exchange' strings, or MICs retired by ISO 10383 updates after the packaged table was generated.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/cffb72b4d61d2620. Report an issue: GitHub.