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
13 1 0 2

Convert python code to ‘import eikon as ek’

Hi Team,

Can you help me to use eikon api and use the command ‘import eikon as ek’ to import the code below?

import refinitiv.data as rd

rd.open_session()

rd.get_history(

universe='CBF24^2',

fields=["SETTLE"],

count=1,

)

Could you please provide the code that can be used through eikon package?
For some reason, seems "count" is not being recognized. Please advise. Thank you!

eikoneikon-data-apirefinitiv-dataplatform-eikoneikon-com-apieikon-app-studiorefinitiv-data-platform-eikoneikon-data-api-reikon-for-officeeikon-desktop-data-apieikonapp
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
6k 18 2 8

Hi @Mark Lucio ,


As the error message suggest the issue is with requested range. Since the instrument expired on Jan, 2024 and the function by default returns values for more recent periods, you get the error. Please consider adding start and end dates. I also removed count parameter to see the whole series:

ek.get_timeseries(
        rics=['CBF24^2'],
        fields=["CLOSE"],
        interval="daily",
        start_date='2022-01-01',
        end_date='2024-01-01'
)

screenshot-2024-05-14-at-181026.png

Hope this helps.


Best regards,

Haykaz



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 @aramyan.h, thank you for your assistance as well. I will try to share this to client. Would you know if we can only see the last value instead of showing it as a timeseries?

This is the reason why we use the count=1 to only display one value. This is the equivalent of nbrows in Excel. I am looking for the code where the client do not need to indicate the start and end date which will show him/her the last value of these expired futures.

Hi @Mark Lucio ,


The best would have been to use ek.get_data for that scenario:

df, err = ek.get_data(instruments='CBF24^2', fields='CF_LAST')
df

However, this resulst in NA and the reason why can be checked by raising a content query via my.refinitiv.com

As a workaround I would suggest using get_timeseries but provide only a valid start_date and then pick the last value of the output:

df = ek.get_timeseries(
        rics=['CBF24^2'],
        fields=["CLOSE"],
        interval="daily",
        start_date='2020-01-01',
)
df['CLOSE'][-1] 
thank you @aramyan.h, will suggest this.
Upvotes
1.3k 3 2 4

Hi @Mark Lucio ,

Could you detail why "count" is not being recognized ? Do you have any error ?

On my side, same code returns this result:

CBF24^2     SETTLE
Date              
2024-01-31  262.94

Note that refinitiv-data library is meant to replace eikon, but for those who want to continue using it, it is included and can be used like this:

from refinitiv.data import eikon as ek
r1 = ek.get_data(...)
r2 = ek.get_timeseries(...)
...

But with rd.get_history(), you can request much more fields than ek.get_timeseries()

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 @pf, thank you for your assistance. Using the Python code above, it works fine.
However, since the client needs ‘import eikon as ek’, I am not certain how to convert the above code to ‘import eikon as ek’.
I tried to use:


import refinitiv.dataplatform.eikon as ek

import datetime

ek.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')

ek.get_timeseries(['CBF24^2'],

fields=["close"],

count=1,

interval="daily"

)

but it is showing error:

Error with CBF24^2: No data available for the requested date range
CBF24^2: No data available for the requested date range | 

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.