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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 0

How do I get the components of CHFFWD=?

Hi, I need to get all the components of CHFFWD= (including but not limited to CHFON, CHFTN, CHFSW, CHF1M...) and their BID and ASK values.

The following code

data, err = ek.get_data(instruments=["CHFFWD="], fields=['BID', 'ASK'])

Throws an error. What am I missing?

Thank you

eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpythonforwards
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.

1 Answer

Upvote
Accepted
18k 21 12 20

Hi @mi.v.

Please read the chain data structure section in this article.

Here is the sample code:

LONGNEXTLR = 'CHFFWD='
fields = ['LONGLINK{}'.format(x) for x in range(1, 15)]
fields.append('LONGNEXTLR')

all_components = []

while LONGNEXTLR!='':
    df,e = ek.get_data(LONGNEXTLR,fields)
    LONGNEXTLR = df.iloc[0]['LONGNEXTLR'] if pd.notnull(df.iloc[0]['LONGNEXTLR']) else ''
    for x in range(1, 15):
        currentField = 'LONGLINK{}'.format(x)
        all_components.append(df.iloc[0][currentField]) if pd.notnull(df.iloc[0][currentField]) else None
        
df,e = ek.get_data(all_components,['BID','ASK'])
df


Output:


ahs.png (37.1 KiB)
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