Data turns to NA while extending time series request

Hi all, I am trying to retrieve some data but when I try to extend the time series (from 2019 to 2020 or more), I am loosing the data for some series... Do you know why? how to fix this issue? Ideally I would like to retrieve data up to today.

Clémence

1678109990652.png1678109957995.png


Best Answer

  • @ClemenceD Thanks for your question - so this is because you are probably coming up against some API Limits detailed here. In your case you have probably reached this limit of 3000 data rows per call :

    • get_timeseries: The current limit value (10-Oct-2019) is 3,000 data points (rows) for interday intervals and 50,000 data points for intraday intervals. This limit applies to the whole request, whatever the number of requested instrument.

    So you could just loop for each RIC yourself then concatenate - this code does this with some error handling:

    import time
    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.1)
            else:
                break
        else:
            var = "p"
    data1

    1678114814019.png

    I hope this can help.

Answers

  • Very useful, thank you! What if we need would like to extend the time series over 3000 observations to get earlier data, say from 2000, for all series?

    Many thanks

    Clémence