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

Using Python API: Check all elements in a list are a valid RIC

My ultimate aim is to be able to do a Ekion Python API query like this

df_ric, err = ek.get_data(RIC_List,

['TR.PriceClose','TRDPRC_1'],)


Where RIC_List has 1800 elements, 99% of which are RICs in string format and the remaining 1% are not RICs and need to be skipped automatically. (Querying each element using a "try" function takes too long, so I hope the 1 big query is faster).


My thoughts are to do this in two steps


1. Feed the list into 1 Reuters Ekion Python API query that returns if each element in the list is in fact a RIC, with the output being a smaller list "RIC_List2" with only RICs.

2. Feed "RIC_List2" into the initial code written above to get all the data i need.


Please let me know if it is possible to do something like (1.) or any other ideas


to put in another way I would want something like

test_list= [[nan],'ASML.AS','adjfoi;dsa','NOVN.S']


to eventually return


Instrument Price Close TRDPRC_1

0 ASML.AS 547.1 554.6

1 NOVN.S 91.94 88.09

(04/10/2023, 13:55 UK Time)



Thanks in advance


python#productpython apirics
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.

@toby.mcmanners

Hi,

Thank you for your participation in the forum.

Is the reply below satisfactory in answering your question?

If yes please click the 'Accept' text next to the reply. This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.


Thanks,

AHS

1 Answer

· Write an Answer
Upvotes
Accepted
14.2k 30 5 10

Hi @toby.mcmanners ,

Can it be this way

# import libraries
import refinitiv.data.eikon as ek
ek.set_app_key('DEFAULT_CODE_BOOK_APP_KEY')
import numpy as np

# define ric list (with invalid values)
RIC_List=[None,'ASML.AS','adjfoi;dsa','NOVN.S']

# remove None value as it cannot be passing into get_data function
ric_list_not_none = [x for x in RIC_List if x is not None]

# use the ric list above to retrieve data on field 'TR.RIC'
df_ric, err = ek.get_data(ric_list_not_none,
                          ['TR.RIC'])

# drop row with empty value in RIC column
df_ric['RIC'].replace('', np.nan, inplace=True)
df_ric.dropna(subset=['RIC'], inplace=True)

# convert RIC column to RIC list
valid_ric_list = df_ric['RIC'].to_list()

# retrive the data
df_ric, err = ek.get_data(valid_ric_list,
                          ['TR.PriceClose','TRDPRC_1'])
df_ric

1696427005358.png


1696427005358.png (43.3 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.