Open mig9mili opened 1 year ago
I found similar error too.
Ok, I found the reason. Since I am using the free trial of the API, so they only allocate 5 requests per second for me. That's what caused the error.
What you can do is to reduce your batch call to 5.
I have tried to reduce the batch call to 20 or 10. But there are errors that occurred as well, though some of the batch calls may successfully requested.
To fix this problem, you can either upgrade your plan or reduce your batch call to 5(if you are using IEX Apperate API).
Just use this piece of code
The request error can arise due to the requesting a large number of Batch API calls all at once Therefore for that use
[:i]
at end of
for symbol_string in symbol_strings:
for symbol_string in symbol_strings [:i]:
and you can change the call to 20 calls or less to see if it works.
Even after this, the main error occurs at data['symbol'] For that use this piece of code below the FOR loop; the reason for that is these 3 stocks have been delisted and calls to them cause errors in the Series -------->
if symbol == 'HFC' or symbol == 'VIAC' or symbol == 'WLTW' or symbol == 'DISCA':
continue
else:
final_dataframe = final_dataframe.append(
symbol_groups = list(chunks(stocks['Ticker'], 100)) symbol_strings = [] for i in range(0, len(symbol_groups)): symbol_strings.append(','.join(symbol_groups[i]))
final_dataframe = pd.DataFrame(columns=my_col)
for symbol_string in symbol_strings: batch_api_call_url = f'https://cloud.iexapis.com/stable/stock/market/batch/types=quote&symbols={symbol_string}&token={IEX_CLOUD_API_TOKEN}' data = requests.get(batch_api_call_url).json() for symbol in data: if data[symbol]['quote']: final_dataframe = final_dataframe.append( pd.Series([symbol, data[symbol]['quote']['latestPrice'], data[symbol]['quote']['marketCap'], 'N/A'], index=my_col), ignore_index=True)
final_dataframe
![Screenshot 2023-03-20 104719](https://user-images.githubusercontent.com/89625729/226253005-f98f686f-342f-44f0-a805-36a5e11b5bbb.png)