For a deeper look into our Eikon Data API, look into:
Overview | Quickstart | Documentation | Downloads | Tutorials | Articles
Hi,
I would like to get a list of all the RICs in the 0#GRAINS/CASH chain.
I tried:
df, err = ek.get_data('0#GRAINS/CASH', 'TR.CommonName')
or
df, err = ek.get_data('0#.GRAINS/CASH', 'TR.CommonName')
but I got the error: 'Unable to resolve all requested identifiers.'
I noticed this is a chain containing chains so I also tried
df, err = ek.get_data('0#CMAIZE-FR', 'TR.CommonName')
which should yield rics but the same problem occurred.
Exchanges seem to work fine as:
df, err = ek.get_data('0#.ftse', 'TR.CommonName')
works fine.
How can I get a list of all RICs in the GRAINS/CASH chain?
To retrieve chain constituents for any kind of chain, use a real-time field like DSPLY_NAME in get_data method instead of a fundamental & reference data field (aka TR.* field) like TR.CommonName. Try
ek.get_data('0#GRAINS/CASH', 'DSPLY_NAME')
Thank you @Alex Putkov. I managed to get the chains of the chain :). I wrote your command into a recursive function that keeps digging down the RIC until it reaches the lowest level (code not starting with 0#). Then I calls some more data and append it to a pandas dataframe.
import eikon as ek import pandas as pd df_fin = pd.DataFrame(columns = ['Instrument', 'DSPLY_NAME', 'Instrument Description', 'Asset Category Description']) def get_all_children(parent_ric, dsply_name): logger.info(f"Call {parent_ric}") df, err = ek.get_data(parent_ric, 'DSPLY_NAME') for i, row in df.iterrows(): if str(row['Instrument']) == parent_ric: logger.info(f'Skip {parent_ric} because it returned itself.') return elif str(row['Instrument']).startswith('0#'): # the child is a chain logger.info(f"Getting children of {str(row['Instrument'])}" ) get_all_children(str(row['Instrument']), str(row['DSPLY_NAME'])) else: # the child is an instrument logger.info(f"{str(row['Instrument'])} is not a chain so append df" ) df_child, err_child = ek.get_data( instruments=str(row['Instrument']), fields=[ 'DSPLY_NAME', 'TR.InstrumentDescription', 'TR.AssetCategory'] ) # append to the global variable df_fin global df_fin df_fin = df_fin.append(df_child) get_all_children('0#GRAINS/CASH', 'commodity') df_fin.to_csv('out.csv', index=False)