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
Best Answer
-
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.
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.
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.
0
Answers
-
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:
Can you try with the Data Library?
1 -
About the fields, you can use the "Data Item Browser" (DIB) app on the Workspace/Eikon to find the fields that you need.
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.
1 -
hi i am trying to get the data as a time series from 2010 to 2020
0 -
- from refinitiv.data.errors import RDError
- import time
- retry_max = 5
- retry_count = 1
- bond_rics = bonds_outstanding["RIC"].tolist()
- bond_holders = pd.DataFrame()
- for ric in bond_rics: # bond_rics defined above
- retry = True
- retry_count = 1
- while retry==True:
- try:
- retry=False
- time.sleep(3)
- df_hold = rd.get_data(ric,['TR.H.HoldingCompanyName.HoldingCompanyName','TR.H.PARHELD','TR.H.REPORTDATE'])
- if len(df_hold):
- bond_holders = pd.concat([bond_holders,df_hold],axis=0,ignore_index=True)
- else:
- bond_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)
- 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
0 -
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:
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_holdersResult:
0 -
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_holders0 -
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?
0 -
thank you wasin
0
Categories
- All Categories
- 6 AHS
- 37 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 59 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛