Backend Error 400 - python API - way to avoid?

Hi, I got always the same problem running a python script.

My RIC list is split into subsequences to allow the run.

microsoftteams-image.pngHow can I overcome this issue?

Best Answer

  • @ilaria.leoni2 Thanks for your question and sorry to hear about your issue. So I cannot see the size of the field list (val_items) that you are using - but in general the guidance for per API call limits is given in this document. Generally you should try to code defensively in a try-except type structure where you can capture errors and try to re-present the failing API calls. Also consider the timing of the calls - around market opens is when loads on services are highest and can result in such errors.

    instruments = ['CAD=','US2YT=RR','CA2YT=RR']
    s = '2012-01-06'
    e = '2023-03-01'
    inv = 'daily'

    data1 = pd.DataFrame()

    for i in instruments:
        succeed = False
        while succeed == False:
            try:
                df1 = ek.get_timeseries(i,  # RICs
                    fields=['CLOSE'],  # fields to be retrieved
                    start_date=s,  # start time
                    end_date=e,  # end time
                    interval=inv)
                df1.rename(columns = {'CLOSE': i}, inplace = True)
                if len(data1):
                    data1 = pd.concat([data1, df1], axis=1)
                else:
                    data1 = df1
                succeed = True
            except:
                time.sleep(0.2)
            else:
                break
        else:
            var = "p"
    data1

    This is an example to show you how it might be implemented - you can swap the API call out with your one. I hope this can help.