feat(platform): standardize exchange inputs with ISO 10383 MIC codes#7351
feat(platform): standardize exchange inputs with ISO 10383 MIC codes#7351sandole wants to merge 9 commits intoOpenBB-finance:developfrom
Conversation
6f7b0d6 to
94d228e
Compare
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
94d228e to
309eca0
Compare
- 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.
|
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. |
5e317d6 to
8693dd3
Compare
|
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:
I've got a script ready to pull from the official source for whichever way. |
8693dd3 to
1c4f7ab
Compare
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. |
|
updated to pull the full ISO 10383 registry. used the official ISO 20022 source (https://www.iso20022.org/market-identifier-codes). The update script ( |
5aeab2e to
36247ec
Compare
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
36247ec to
a404eb9
Compare
|
We should probably include city, country, and website in the JSON, eh? |
e1845e6 to
0e0ba15
Compare
Pull Request for OpenBB Platform
Description
Exchangetype that standardizes exchange inputs across providers using ISO 10383 Market Identifier Codes (MIC).obb.equity.screener: Make Input Of Country & Exchange Uniform Across Providers #6969Countrytype approach from PR feat(platform): standardize country inputs with ISO 3166 Country type #7333, this provides uniform exchange input handling across all providers.Features
Following the same pattern as
Country, theExchangetype:str(storing the MIC code) for type checker compatibilityXNAS,XNYS)NASDAQ,NYSE)New York Stock Exchange)new_york_stock_exchange)mic,acronym,name,city,country,websiteExchangeDataTypedDict for proper type inferenceExample Usage
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 fieldsopenbb_core/provider/utils/exchange_utils.py— Exchange type implementation withExchangeDataTypedDicttests/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
TypedDictfor proper type inference (consistent withCountryDatapattern from #7352):How has this been tested?
Checklist