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
19 2 1 4

Loop rics 400 bank end error

HI i need to pull the

closing price date, closing proce, volume and price to book, price to earnings of the following rics.

['MSFT.O',

'AAPL.O',

'NVDA.O',

'GOOGL.O',

'GOOG.O',

'AMZN.O',

'META.O',

'BRKb',

'LLY',

'AVGO.O',

'JPM',

'V',

'TSLA.O',

'WMT',

'XOM',

'UNH',

'MA',

'PG',

'JNJ',

'HD',

'ORCL.K',

'MRK',

'COST.O',

'ABBV.K',

'BAC',

'CVX',

'AMD.O',

'CRM',

'KO',

'NFLX.O',

'PEP.O',

'ACN',

'ADBE.O',

'DIS',

'LIN.O',

'TMO']


i keep getting a backed 400 request error. Are you able to help me write a code to pull this data? i am using ek.get_data

eikon-data-apipythonworkspace#technology
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.

Upvotes
Accepted
24.6k 54 17 14

Hello @ken03

Question 1: Can I check the difference between both codes is just the chunk size code?

Answer: Yes, the first code splits rics list into smaller one (contains 3 rics per list - chunk variable) and sends that 3 rics list as a batch request to the Workspace platform.

The second code jus iterates each RIC from the rics list and sends that one RIC request to Workspace platform (like the code from that old post).

Question 2: Can I also please check why do you place a backslash at every RICs?

Answer: I found that I cannot request the RIC without suffix (WMT, JPM, etc.) directly.

code-1.png

Then I checked the Quote App on Workspace. I found that the Quote App uses /WMT RIC code as well as other non-suffix RICs like /JPM, /V, so I add a backslash in the code, and it works fine.

code-2.png

Question 3: the 400 backend error what is it usually caused by? requesting too many rics at once?

Answer: According to the Eikon Data API Usage and Limits Guideline when a request fails because the platform is overwhelmed, an HTTP response with status code 400 and the message "Backend error. 400 Bad Request" is returned.



code-1.png (9.0 KiB)
code-2.png (52.8 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.

Upvote
24.6k 54 17 14

Hello @ken03

Can you share the code that encounters the issue?

I can request those RICs data using the strategic Data Library for Python as follows:

import refinitiv.data as rd

rd.get_data(
    universe=['MSFT.O','AAPL.O','NVDA.O','GOOGL.O','GOOG.O','AMZN.O','META.O','/BRKb','/LLY','AVGO.O','/JPM','/V','TSLA.O','/WMT','/XOM','/UNH',
              '/MA','/PG','/JNJ','/HD','ORCL.K','/MRK','COST.O','ABBV.K','/BAC','/CVX','AMD.O','/CRM','/KO','NFLX.O','PEP.O','/ACN','ADBE.O','/DIS','LIN.O','/TMO'],
    fields=['CF_CLOSE', 'CF_DATE']
)

Result:

1711957476624.png


Can you try with the Data Library?


1711957476624.png (53.9 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.

Upvote
24.6k 54 17 14

About the fields, you can use the "Data Item Browser" (DIB) app on the Workspace/Eikon to find the fields that you need.

dib-1.png

You can find more information about the Data Item Browser from this DIB Video tutorial page.

Alternatively, you may contact the Content support team directly to help you find the fields that you need. You can contact the Content support team via https://my.refinitiv.com/content/mytr/en/helpandsupport.html website.

contact-eikon-content.png



dib-1.png (113.0 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.

Upvotes
19 2 1 4

hi i am trying to get the data as a time series from 2010 to 2020

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.

Upvotes
19 2 1 4
  1. from refinitiv.data.errors import RDError
  2. import time
  3. retry_max = 5
  4. retry_count = 1
  5. bond_rics = bonds_outstanding["RIC"].tolist()
  6. bond_holders = pd.DataFrame()
  7. for ric in bond_rics: # bond_rics defined above
  8. retry = True
  9. retry_count = 1
  10. while retry==True:
  11. try:
  12. retry=False
  13. time.sleep(3)
  14. df_hold = rd.get_data(ric,['TR.H.HoldingCompanyName.HoldingCompanyName','TR.H.PARHELD','TR.H.REPORTDATE'])
  15. if len(df_hold):
  16. bond_holders = pd.concat([bond_holders,df_hold],axis=0,ignore_index=True)
  17. else:
  18. bond_holders = df_hold
  19. except RDError as err:
  20. if "Backend error. 400 Bad Request" in err.message:
  21. retry_count = retry_count + 1
  22. if retry_count<=retry_max:
  23. print("Retry "+ric)
  24. retry=True
  25. else:
  26. print("Retry reach max and unable to get the data for "+ric)
  27. else:
  28. print(err.code+" "+err.message)
  29. bond_holders # get a 400 error (timeout?)

using this type of code except rics for equities in place of bonds. and replaced the parameters with market cap and price to bv per share. and dates i put from 2005-01-01 to 2024-01-01

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.

Upvotes
24.6k 54 17 14

Hello @ken03

Thank you for the information. I am assuming that you want to subscribe time series data (2005-01-01 to 2024-01-01) for the ['MSFT.O', ...., '/TMO'] RICs using the code from this Batch request bondholders and ultimate parents for multiple bond RICs - python RDP API old post.

By default, the RD get_data() method supports request level parameter that you can specify start date and end date (see more detail on the Data Library for Python - Quick Reference Guide (Access layer) article) as follows:

rd.get_data(
    universe=['MSFT.O','AAPL.O','NVDA.O'],
    fields=['TR.CompanyMarketCap','TR.F.PriceToTangBVPerShr','TR.PriceClose.date','TR.PriceClose'],
    parameters = {'SDate': '2005-01-01', 'EDate': '2024-01-01','Frq':'D'}
)

Result:

1712047580024.png


According to the Eikon Data API Usage and Limits Guideline when a request fails because the platform is overwhelmed, an HTTP response with status code 400 and the message "Backend error. 400 Bad Request" is returned. Then the Python library raises an Error exception with the following message:

Error code 400 | Backend error. 400 Bad Request

You may need to split the RICs list into a smaller one, and iterate each request with the exception and retry logic (like this old post)

from refinitiv.data.errors import RDError
import time

rics = ['MSFT.O','AAPL.O','NVDA.O','GOOGL.O','GOOG.O','AMZN.O','META.O','/BRKb','/LLY','AVGO.O','/JPM','/V','TSLA.O',
        '/WMT','/XOM','/UNH','/MA','/PG','/JNJ','/HD','ORCL.K','/MRK','COST.O','ABBV.K','/BAC','/CVX','AMD.O','/CRM','/KO',
        'NFLX.O','PEP.O','/ACN','ADBE.O','/DIS','LIN.O','/TMO']
fields = ['TR.CompanyMarketCap','TR.F.PriceToTangBVPerShr','TR.PriceClose.date','TR.PriceClose']

retry_max = 5
retry_count = 1
chunks = []
chunk_size = 3
df_holders = pd.DataFrame()

for index in range(0, len(rics), chunk_size):
    chunk = rics[index: index + chunk_size]
    retry = True
    retry_count = 1
    while retry==True:
        try:
            retry = False
            time.sleep(3)
            df_hold = rd.get_data(universe = chunk,
                                 fields = fields,
                                 parameters = {'SDate': '2005-01-01', 'EDate': '2024-01-01','Frq':'D'})
            if len(df_hold):
                df_holders = pd.concat([df_holders, df_hold], axis = 0, ignore_index = True)
            else:
                df_holders = df_hold
        except RDError as err:
            if 'Backend error. 400 Bad Request' in err.message:
                retry_count = retry_count + 1
                if retry_count <= retry_max:
                    print('Retry ' + chunk)
                    retry = True
                else:
                    print('Retry reach max and unable to get the data for ' + chunk)
            else:
                print(err.code + ' ' + err.message)


df_holders

Result:

1712047641805.png



1712047580024.png (46.7 KiB)
1712047641805.png (53.1 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.

Upvotes
24.6k 54 17 14

Alternatively, if you want to subscribe only 1 RIC per request, here are the example code:

for ric in rics:
    retry = True
    retry_count = 1
    while retry==True:
        try:
            retry = False
            time.sleep(3)
            df_hold = rd.get_data(ric,
                                 fields = fields,
                                 parameters = {'SDate': '2005-01-01', 'EDate': '2024-01-01','Frq':'D'})
            if len(df_hold):
                df_holders = pd.concat([df_holders, df_hold], axis = 0, ignore_index = True)
            else:
                df_holders = df_hold
        except RDError as err:
            if 'Backend error. 400 Bad Request' in err.message:
                retry_count = retry_count + 1
                if retry_count <= retry_max:
                    print('Retry ' + ric)
                    retry = True
                else:
                    print('Retry reach max and unable to get the data for ' + ric)
            else:
                print(err.code + ' ' + err.message)


df_holders
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.

Upvotes
19 2 1 4

Hi Wasin,


excellent, can i check the difference between both codes is just the chunk size code?

can i also please check why do you place a backslash at every ric?

the 400 backend error what is it usually caused by? requesting too many rics at once?

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.

Upvotes
19 2 1 4

thank you wasin

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.