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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
23 1 0 3

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 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
39.2k 75 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 5.0 MiB each and 10.0 MiB total.

Upvotes
23 1 0 3

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 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea