Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In batch api --> JSONDecodeError #53

Open
mig9mili opened this issue Mar 20, 2023 · 3 comments
Open

In batch api --> JSONDecodeError #53

mig9mili opened this issue Mar 20, 2023 · 3 comments

Comments

@mig9mili
Copy link

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 104621
Screenshot 2023-03-20 104719

@SoartheCat717
Copy link

I found similar error too.

image

@SoartheCat717
Copy link

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

@rohitx01
Copy link

rohitx01 commented Apr 4, 2023

Screenshot (267)
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.

But make sure to remove it in the final code piece when making requests so that it will loop over every single stock

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(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants