Error handling for get_timeseries()

I am using a get_timeseries() function in a loop over a long list of stocks and get different errors depending on context (I am aware of the reasons for the errors):

- No data available for the requested data range.

- Client Error: Too many requests, please try again later

Is there a way to handle these errors differently? For example, I want skip the iteration that returns "no data available" and completely stop the loop execution if "too many requests" error shows, something like this

for ticker in ticker_list:         
try:
prices = ek.get_timeseries(ticker, interval = 'daily)        
except NoDataAvailableError:
continue
except ClientError:
break

Best Answer

  • chavalit-jintamalit
    Answer ✓

    Hi @oik22

    Eikon Data API raises EikonError error.

    This is the sample code to catch it: (I simulated 2 cases, too many ric and invalid ric)

    image

    Under the except ek.EikonError, you can handle it according to your requirement.

    To either break or continue your loop.

Answers

  • Hi @oik22

    I think your handles make sense.

    Maybe add a few delays between each loop too.

  • oik22
    oik22 Newcomer

    Thanks @chavalit-jintamalitchavalit.jintamalit

    I am actually looking for the specific handles or codes for the errors that Eikon API throws in these two cases: (1) "no data available for the data range" (2) "too many requests", so that I can distinguish between them. The exception handles "NoDataAvailableError" and "ClientError" are just some random names I came up with as an example for illustrative purposes. I do not know what the actual Eikon error handles are for these two cases. Like the different Python build-in exceptions such as ValueError or ZeroDivisionError, that's what I am looking for.