Exchange Input
Exchange is a str subclass that resolves an exchange identifier to its ISO 10383 Market Identifier Code (MIC) and carries the acronym and full name as properties. Use it for exchange parameters so providers accept the same inputs and receive a MIC.
from openbb_core.provider.utils.exchange_utils import Exchange
Accepted inputs
The constructor accepts a MIC ("XNAS"), an acronym ("NASDAQ"), the registered name, or the registered name in snake_case, all without regard to case. Registered names are the ones in the ISO list, such as "LONDON STOCK EXCHANGE" or "NEW YORK STOCK EXCHANGE, INC.", so the MIC or acronym is usually the more reliable input. Anything unknown raises ValueError.
>>> e = Exchange("nasdaq")
>>> e
'XNAS'
>>> e.acronym
'NASDAQ'
>>> e.name
'NASDAQ - ALL MARKETS'
>>> Exchange("london_stock_exchange")
'XLON'
>>> Exchange("XNYS").name
'NEW YORK STOCK EXCHANGE, INC.'
The value compares and serializes as the MIC. mic, acronym, and name return the three identifiers. When several segment MICs share an acronym, the acronym resolves to the operating MIC.
Use it in a model
Exchange works as a Pydantic field type:
from openbb_core.provider.abstract.query_params import QueryParams
from openbb_core.provider.utils.exchange_utils import Exchange
from pydantic import Field
class DemoListingsQueryParams(QueryParams):
"""Query with an exchange parameter."""
exchange: Exchange = Field(description="Exchange MIC, acronym, or name.")
DemoListingsQueryParams(exchange="NYSE") stores 'XNYS', and query.exchange.acronym returns the short form for sources that expect it.
Refresh the data
The definitions ship with openbb-core in exchange_data.json. The module openbb_core.provider.utils.update_exchange_data downloads the current MIC registry from iso20022.org and rewrites that file in the installed package. --operating-only leaves out segment MICs.
python -m openbb_core.provider.utils.update_exchange_data