Skip to content

Comments

feat(platform): standardize exchange inputs with ISO 10383 MIC codes#7351

Open
sandole wants to merge 9 commits intoOpenBB-finance:developfrom
sandole:feature/standardize-exchange-inputs
Open

feat(platform): standardize exchange inputs with ISO 10383 MIC codes#7351
sandole wants to merge 9 commits intoOpenBB-finance:developfrom
sandole:feature/standardize-exchange-inputs

Conversation

@sandole
Copy link
Contributor

@sandole sandole commented Feb 11, 2026

Pull Request for OpenBB Platform

Description

Features

Following the same pattern as Country, the Exchange type:

  • Inherits from str (storing the MIC code) for type checker compatibility
  • Accepts multiple input formats:
    • ISO 10383 MIC codes (e.g., XNAS, XNYS)
    • Exchange acronyms (e.g., NASDAQ, NYSE)
    • Full exchange names (e.g., New York Stock Exchange)
    • lower_snake_case names (e.g., new_york_stock_exchange)
  • Provides properties: mic, acronym, name, city, country, website
  • Uses ExchangeData TypedDict for proper type inference
  • Includes enriched metadata from ISO 10383: city (title-cased), country (ISO alpha_2), and website (normalized with https://)
  • 2,272 active MICs with 100% city/country coverage and 98% website coverage

Example Usage

from openbb_core.provider.utils.exchange_utils import Exchange

e = Exchange("nasdaq")
str(e)      # "XNAS"
e.mic       # "XNAS"
e.acronym   # "NASDAQ"
e.name      # "NASDAQ - ALL MARKETS"

e = Exchange("XNYS")
e.mic       # "XNYS"
e.acronym   # "NYSE"
e.name      # "NEW YORK STOCK EXCHANGE, INC."

Sample JSON Entry

{
  "mic": "XNYS",
  "acronym": "NYSE",
  "name": "NEW YORK STOCK EXCHANGE, INC.",
  "city": "New York",
  "country": "US",
  "website": "https://www.nyse.com"
}

Files Added/Modified

  • openbb_core/provider/utils/exchange_data.json — Full ISO 10383 dataset (2,272 active MICs) with city, country (ISO alpha_2), and website fields
  • openbb_core/provider/utils/exchange_utils.py — Exchange type implementation with ExchangeData TypedDict
  • tests/provider/utils/test_exchange_utils.py — Unit tests (13 test cases)
  • scripts/update_exchange_data.py — Script to regenerate exchange data from official ISO 20022 source (stdlib only, no external dependencies)

Type Safety

Uses TypedDict for proper type inference (consistent with CountryData pattern from #7352):

class ExchangeData(TypedDict, total=False):
    mic: str
    acronym: str
    name: str
    city: str
    country: str
    website: str

How has this been tested?

  • Manually tested Exchange type creation and property access
  • Unit tests cover MIC codes, acronyms, full names, snake_case, case insensitivity, whitespace handling
  • Syntax and JSON validation passing

Checklist

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have adhered to the GitFlow naming convention.
  • I ensure that I am following the CONTRIBUTING guidelines.
  • I have added tests.

@sandole sandole force-pushed the feature/standardize-exchange-inputs branch from 6f7b0d6 to 94d228e Compare February 11, 2026 21:30
Add Exchange type in provider utils that standardizes exchange inputs across
providers using ISO 10383 Market Identifier Codes (MIC).

Similar to the Country type from PR OpenBB-finance#7333, this allows providers to accept:
- ISO 10383 MIC codes (e.g., 'XNAS', 'XNYS')
- Exchange acronyms (e.g., 'NASDAQ', 'NYSE')
- Full exchange names (e.g., 'New York Stock Exchange')
- lower_snake_case names (e.g., 'new_york_stock_exchange')

The Exchange class inherits from str (storing the MIC code) while providing
access to mic, acronym, name, country, and city properties.

Example usage in FMP equity screener demonstrates provider integration pattern:
- exchange: Exchange | None with validator for provider-specific validation
- Maps Exchange.acronym to FMP's expected lowercase exchange codes

Addresses part of OpenBB-finance#6969
@sandole sandole force-pushed the feature/standardize-exchange-inputs branch from 94d228e to 309eca0 Compare February 11, 2026 21:50
sandole and others added 2 commits February 13, 2026 13:04
- Add ExchangeData TypedDict with explicit field types (consistent with CountryData)
- Update function signatures and class attributes to use ExchangeData
- Add _last_updated metadata to exchange_data.json
- Add Wikipedia reference URL to docstring

Aligns Exchange implementation with Country pattern from PR OpenBB-finance#7352.
@sandole sandole marked this pull request as ready for review February 13, 2026 21:15
@deeleeramone
Copy link
Contributor

Thanks for picking this up. The implementation looks good, but the JSON data seems like it is missing a lot of entries. There are no Cboe markets in there, just to name one company. There should be closer to 2000 items in this ISO.

@sandole sandole force-pushed the feature/standardize-exchange-inputs branch from 5e317d6 to 8693dd3 Compare February 14, 2026 07:00
@sandole
Copy link
Contributor Author

sandole commented Feb 14, 2026

Good point on completeness - I updated the exchanges JSON to include CBOE and a few more. I did look into pulling the full ISO 10383 list (~1,300 operating MICs, ~2,200 with segments).

Question: what's the practical value of including exchanges beyond the major ~66? Most data providers (FMP, Polygon, Intrinio, etc.) only support major venues. Including 1,300+ MICs means we'd validate inputs that no provider can actually serve data for.

My proposals:

  1. Keep curated major exchanges (current) — practical but incomplete
  2. Full ISO list — complete but accepts unusable inputs
  3. Full list + tier field to distinguish major/regional/mtf — best of both?

I've got a script ready to pull from the official source for whichever way.

@sandole sandole force-pushed the feature/standardize-exchange-inputs branch from 8693dd3 to 1c4f7ab Compare February 14, 2026 07:14
@deeleeramone
Copy link
Contributor

Question: what's the practical value of including exchanges beyond the major ~66?

If you have a CTA feed or assets other than stocks, there will be all kinds of MICs that you will never encounter as an individual. Options, futures, commodities, indices, financial derivatives, bonds, etc. all have their own markets and codes.

Exchange code mapping, IMO, is useful for processing raw market data and converting codes into human-readable labels.

@sandole
Copy link
Contributor Author

sandole commented Feb 16, 2026

updated to pull the full ISO 10383 registry. used the official ISO 20022 source (https://www.iso20022.org/market-identifier-codes). The update script (scripts/update_exchange_data.py) can be re-run anytime the registry updates.

@sandole sandole force-pushed the feature/standardize-exchange-inputs branch 6 times, most recently from 5aeab2e to 36247ec Compare February 16, 2026 19:27
Address review feedback to include all active MICs, not just curated majors.

- Expand exchange_data.json from 66 to 2,272 active MICs (operating + segments)
- Remove country and city fields (out of scope for this PR)
- Add scripts/update_exchange_data.py to regenerate from official ISO 20022
  CSV source using stdlib only (no external dependencies)
- Use first-write-wins lookup with operating MICs ordered before segments
  to resolve acronym collisions (e.g. LSE -> XLON, not XPVT)
- Update tests to reflect simplified data model
@sandole sandole force-pushed the feature/standardize-exchange-inputs branch from 36247ec to a404eb9 Compare February 16, 2026 19:47
@deeleeramone
Copy link
Contributor

We should probably include city, country, and website in the JSON, eh?

@sandole sandole force-pushed the feature/standardize-exchange-inputs branch from e1845e6 to 0e0ba15 Compare February 17, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants