Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustment to security types in bbg_figi_mapper #184

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,21 @@ def preload_tickers_mapping(self, tickers: Union[Sequence[BloombergTicker], Bloo
-----------
tickers: Union[Sequence[BloombergTicker], BloombergTicker]
ticker(s) for which the mapping should be fetched and saved

Returns
--------
results: List[Dict]
returns a list of dictionaries, containing all data extracted from openfigi for additional reference
"""
tickers, _ = convert_to_list(tickers, BloombergTicker)

requests = [self._ticker_into_openfigi_requests(ticker) for ticker in tickers]
results = asyncio.run(self._distribute_mapping_requests(requests))
results = list(asyncio.run(self._distribute_mapping_requests(requests)))
figi_values = map(lambda r: r.get('figi', None), itertools.chain(*results))

self.ticker_to_contract_data.update(dict(zip(tickers, figi_values)))
self.contract_data_to_ticker.update(dict(zip(figi_values, tickers)))
return results

def preload_figi_mapping(self, figis: Union[Sequence[str], str]):
"""
Expand All @@ -90,15 +96,21 @@ def preload_figi_mapping(self, figis: Union[Sequence[str], str]):
-----------
figis: Union[Sequence[str], str]
FIGI(s) for which the mapping should be fetched and saved

Returns
--------
results: List[Dict]
returns a list of dictionaries, containing all data extracted from openfigi for additional reference
"""
figis, _ = convert_to_list(figis, str)

requests = [{"idType": "ID_BB_GLOBAL", "idValue": f} for f in figis]
results = itertools.chain(*asyncio.run(self._distribute_mapping_requests(requests)))
results = list(itertools.chain(*asyncio.run(self._distribute_mapping_requests(requests))))
mapping = dict(self._ticker_from_openfigi_response(r, f) for (r, f) in zip(results, figis))

self.ticker_to_contract_data.update(mapping)
self.contract_data_to_ticker.update({val: key for key, val in mapping.items()})
return results

def contract_to_ticker(self, figi: str) -> BloombergTicker:
""" Maps Broker specific contract objects onto corresponding Tickers.
Expand Down Expand Up @@ -175,14 +187,15 @@ def _ticker_from_openfigi_response(self, contract_data: Dict[str, str], figi: st
security_type_map = {
'Index': (SecurityType.INDEX, ['ticker']),
'Equity': (SecurityType.STOCK, ['ticker', 'exchCode', 'marketSector']),
'Mutual Fund': (SecurityType.STOCK, ['ticker', 'exchCode', 'marketSector']),
'Future': (SecurityType.FUTURE, ['ticker', 'marketSector']),
'CROSS': (SecurityType.FX, ['securityDescription']),
'SPOT': (SecurityType.FX, ['securityDescription']),
'Comdty': (SecurityType.FUTURE, ['ticker', 'marketSector']),
'Curncy': (SecurityType.FX, ['securityDescription']),
'Corp': (SecurityType.STOCK, ['securityDescription', 'marketSector']),
'Govt': (SecurityType.STOCK, ['securityDescription']),
'Pfd': (SecurityType.STOCK, ['securityDescription']),
}

try:
security_type, fields = security_type_map[contract_data.get('securityType2', '')]
security_type, fields = security_type_map[contract_data.get('marketSector', '')]
fields_data = [contract_data.get(f) for f in fields if contract_data.get(f)]
ticker_str = " ".join(fields_data)

Expand Down
Loading