Recommended code pattern for handling Eikon get_data timeout

Hi,

I'm a newbie to Eikon API


Is there a proscribed code pattern for handling timeouts? I have making a call to `get_data` in a loop: Each request takes about 10s to return but occasionally I get a Timeout (408/504).

I could just trap the timeout error and re-submit using following code as a starting point, but I just wondered is there an accepted/recommended code pattern to use?


thanks



    e = None
    try:
        ek.get_data(instruments, fields)
    except ek.EikonError as err:
        e = err
# do I trap here and re-call get_data??
        raise Exception(f'Eikon error {e.code}\n{e.args}\n{e.message}')



Best Answer

  • chavalit-jintamalit
    Answer ✓

    Hi @john.lupton

    I would add a while loop with a success flag.


    ric = ['PEUP.PA']
    fields = ['TR.RetireDate']

    isSuccess = False

    while (not isSuccess):
        try:
            df,e = ek.get_data(ric, fields)
            isSuccess = True
        except ek.EikonError as err:
            raise Exception(f'Eikon error {e.code}\n{e.args}\n{e.message}')

    ## the code here, already success in API call ##
    print(df)


    image


    If your API call requires 10 seconds, I can assume that you require a large amount of data.

    Please try to split the universe or period to reduce the amount of the data in one API call.

    This would raise the success rate of the API call.

Answers