Upgrade from Eikon -> Workspace. Learn about programming differences.

For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 0

Continuous 500 Internal Server Error and Gateway Time-out errors

Hi all, I have a few python models that have ran into updating issues in the past three weeks or so. On some days the models update just fine, but on other days (like today) I keep getting either an 500 Internal Server Error or a Gateway Time-out error.

----------------------------------------------------------------------------------------------

Here is a quick example of the code I am using to pull in the data:

lookback_days = 240 # You can change this number


today = dt.datetime.today()

start_date = (today - dt.timedelta(days=lookback_days)).strftime('%Y-%m-%d')

end_date = (today - dt.timedelta(days=1)).strftime('%Y-%m-%d') # Adjusted to get yesterday's date


pairs_rics = ['AUDCAD=R' , 'AUDCHF=R' , 'AUDNZD=R' , 'AUDJPY=R' , 'AUD=' ,

'CADCHF=R' , 'CADJPY=R' ,

'NZDCAD=R' , 'NZDCHF=R' , 'NZDJPY=R' , 'NZD=' ,

'EURAUD=R' , 'EURCAD=R' , 'EURCHF=R' , 'EURJPY=R' , 'EURNZD=R' , 'EURGBP=R' , 'EUR=' ,

'GBPAUD=R' , 'GBPCAD=R' , 'GBPCHF=R' , 'GBPJPY=R' , 'GBPNZD=R' , 'GBP=' ,

'CHFJPY=R' ,

'CHF=' , 'JPY=' , 'CAD=',

'US2YT=RR', 'DE2YT=RR', 'GB2YT=RR', 'JP2YT=RR', 'AU2YT=RR', 'NZ2YT=RR', 'CA2YT=RR', 'CH2YT=RR',

'US10YT=RR', 'DE10YT=RR', 'GB10YT=RR', 'JP10YT=RR', 'AU10YT=RR', 'NZ10YT=RR', 'CA10YT=RR', 'CH10YT=RR']


final_data = pd.DataFrame()


for pair in pairs_rics:

data = ek.get_timeseries(pair,

fields=["CLOSE"],

start_date=start_date,

end_date=today, # use end_date instead of today

interval='daily')

----------------------------------------------------------------------------------------------

I was told that I needed to reduce the amount of RICs and the lookback period, but even after limiting it to one RIC and just 5 lookback days I still got the same error.

Is there any advice on how I can solve this?

Someone told me I should consider moving away from the ek.get_timeseries and rather using rd.get_history but am struggling to find the same output compared to the other.

Any advice would be appreciated.

Regards.

eikon-data-apipythonworkspace#productpython api
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @Arries ,

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?
If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.

Thanks,
AHS

Hi @Arries,

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,
AHS

1 Answer

· Write an Answer
Upvotes
Accepted
5.8k 21 2 6

Hi @Arries,


Having a look at this article, I thought it best to try the below. Please let me know if it helps. Indeed, it is best with rd, but only via the Content Layer:


import datetime as dt
import pandas as pd
import refinitiv.data as rd
rd.open_session(config_name="C:/Example.DataLibrary.Python-main/Configuration/refinitiv-data.config.json") # https://github.com/LSEG-API-Samples/Example.DataLibrary.Python/blob/main/Configuration/refinitiv-data.config.json
rd.open_session("desktop.workspace")

lookback_days = 10
today = dt.datetime.today()
start_date = (today - dt.timedelta(days=lookback_days)).strftime('%Y-%m-%d')
end_date = (today - dt.timedelta(days=1)).strftime('%Y-%m-%d') # Adjusted to get yesterday's date

pairs_rics = [
    'AUDCAD=R' , 'AUDCHF=R' , 'AUDNZD=R' , 'AUDJPY=R' , 'AUD=' ,
    'CADCHF=R' , 'CADJPY=R' , 'NZDCAD=R' , 'NZDCHF=R' , 'NZDJPY=R' , 'NZD=' ,
    'EURAUD=R' , 'EURCAD=R' , 'EURCHF=R' , 'EURJPY=R' ,
    'EURNZD=R' , 'EURGBP=R' , 'EUR=' ,
    'GBPAUD=R' , 'GBPCAD=R' , 'GBPCHF=R' , 'GBPJPY=R' , 'GBPNZD=R' , 'GBP=' ,
    'CHFJPY=R' , 'CHF=' , 'JPY=' , 'CAD=',
    'US2YT=RR', 'DE2YT=RR', 'GB2YT=RR', 'JP2YT=RR', 'AU2YT=RR',
    'NZ2YT=RR', 'CA2YT=RR', 'CH2YT=RR',
    'US10YT=RR', 'DE10YT=RR', 'GB10YT=RR', 'JP10YT=RR',
    'AU10YT=RR', 'NZ10YT=RR', 'CA10YT=RR', 'CH10YT=RR']

def chunks(lst, n):
    """Yield successive n-sized chunks from lst."""
    _lst = []
    for i in range(0, len(lst), n):
        _lst.append(lst[i:i + n])
    return _lst

batched_rics = chunks(lst = pairs_rics, n = 10)

for i,j in enumerate(batched_rics):
    __optn_mrkt_price_gmt = rd.content.historical_pricing.summaries.Definition(
        universe=j,
        start=start_date,
        end=end_date,
        interval='P1D', # 'PT1M', 'PT10M', rd.content.historical_pricing.Intervals.DAILY
        fields=['TRDPRC_1', 'SETTLE', 'BID', 'ASK']).get_data().data.df # 'LST_TRD_PR', 'CF_LAST', 'CF_CLOSE', 'SETTLE', 'TRDPRC_1', 'BID', 'ASK'
    if i == 0:
        final_data = __optn_mrkt_price_gmt.T
    else:
        final_data = final_data.append(__optn_mrkt_price_gmt.T)
final_data = final_data.T
display(final_data)
rd.close_session()

1704287555482.png




1704287555482.png (64.3 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.