For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
155 1 1 5

get list of RICs in chain 0#GRAINS/CASH

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?


eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonchain-riccommodities
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
39.3k 76 11 27

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')
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
155 1 1 5

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)


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi, I find that this doesnt seem to work as i hit the limit i believe (400 error). Is there a way to adjust for that (some kind of sleep function?)
Hi Shadeun. i just checked my code and we do it in a bit of a lazy fashion. we just go through them, and when we get an error, we wait 10 seconds and then try again (for max 20 times). give that a shot