Upgrade from Eikon -> Workspace. Learn about programming differences.

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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 1

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-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-apiforwards
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.

1 Answer

· Write an Answer
Upvote
Accepted
18.2k 21 13 21

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 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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