How to handle error after transition from Eikon to Workspace

Hi,

I'm pulling data from API on thousands of RIC daily. I may have RIC's that's no longer valid, or with typo.

Under Eikon, my Python code below will return DataFrame containing information with NA for invalid RIC ('BF.B' and 'BONDS') if I simply ignore df_error, when the list RIC are all invalid.

import refinitiv.dataplatform.eikon as ek
ek.set_app_key(app_key='APP_KEY')
df_eikon, df_error = ek.get_data(
['BONDS', 'BF.B', 'IGUSDD10Y='],
['TR.BIDPRICE.date', 'TR.BIDPRICE', 'CF_DATE', 'TR.CLOSEPRICE', 'CF_LAST'],
{'SDate': 0, 'FRQ': 'D'})

print(df_eikon)

The result is below, which is what I am expecting:

image.png

But under Workspace, the rd.get_data won't allow for two DataFrames to house result and error separately any more, and I can only do below to get an error message:

import lseg.data as rd
rd.open_session(app_key='APP_KEY')
df_workspace = rd.get_data(
['BONDS', 'BF.B'],
['TR.BIDPRICE.date', 'TR.BIDPRICE', 'CF_DATE', 'TR.CLOSEPRICE', 'CF_LAST'],
{'SDate': 0, 'FRQ': 'D'})

print(df_workspace)

I will get below error:

image.png

The Workspace code above works fine when I have a mix of valid and invalid RIC, but will not work when all RIC are invalid. I cannot verify the validity of RIC one by one for thousands of RIC. How can I resolve this to avoid getting an error like Eikon? Thank you.

Best Answers

  • Jirapongse
    Jirapongse ✭✭✭✭✭
    Answer ✓

    @rgustin

    Thank you for reaching out to us.

    The library will raise the LDError instead of returning the error. Therefore, the code needs to be able to handle the LDError, as shown below.

    from lseg.data.errors import LDError
    try:
        df_workspace = ld.get_data(
    
            ['BONDS', 'BF.B'],
    
            ['TR.BIDPRICE.date', 'TR.BIDPRICE', 'CF_DATE', 'TR.CLOSEPRICE', 'CF_LAST'],
    
            {'SDate': 0, 'FRQ': 'D'})
    
    
        print(df_workspace)
    except LDError as e:
        print("LDError code :", e.code) 
        print("LDError message:", e.message)
    

Answers