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

[Bug] Unable to pull multiple earnings reports using for loop #6239

Open
kchander92 opened this issue Mar 20, 2024 · 4 comments
Open

[Bug] Unable to pull multiple earnings reports using for loop #6239

kchander92 opened this issue Mar 20, 2024 · 4 comments
Assignees

Comments

@kchander92
Copy link

I'm trying to write a for loop to pull cash statements for all the tickers in the NYSE. The for loop below contains a try-except block for when quarterly cash statements for a given ticker cannot be returned from Polygon from the last ten years:

cash_statements = {}

for ticker in nyse.symbol:
    try:
        cash_statements[ticker] = obb.equity.fundamental.cash(ticker, provider="polygon", limit=40, period='quarter').to_df()
    except:
        print('{} not available'.format(ticker))

A sample of the output is shown below, with the following tickers not having cash statements available as the for loop is executing:
image

Note that "JPM not available" is underlined. The quarterly cash statements from the last 10 years couldn't be pulled using the for loop. However, when I call the code below to pull JPM's cash statements, I do get an output:
obb.equity.fundamental.cash('JPM', provider="polygon", limit=40, period='quarter').to_df()
image
(The dataframe has been truncated for the sake of brevity.)

Do you know what could be causing this inconsistency, for the stand-alone cash statement query to work for JPM but not when it's run in a for loop? Is there a better way you would recommend pulling the cash statements for multiple tickers? Thanks.

  • OS: Windows 11
  • Python version 3.11.8
@IgorWounds
Copy link
Contributor

Hello,

Can you check your Polygon API key privileges and make sure that you're not being rate-limited?

I can't reproduce this on my end completely as I'm not sure what nyse.symbol looks like. Here is a dummy version that works for me:

cash_statements = {}
symbols = ["JPM", "XOM", "MA"]

for ticker in symbols:
    try:
        cash_statements[ticker] = obb.equity.fundamental.cash(ticker, provider="polygon", limit=40, period='quarter').to_df()
    except Exception as e:
        print(e)

@IgorWounds IgorWounds self-assigned this Mar 20, 2024
@kchander92
Copy link
Author

It looks like the free plan for Polygon as the source allows 5 API calls per minute, so there does appear to be rate limiting going on.

@IgorWounds
Copy link
Contributor

Can you show me the full exception that is being thrown, please?

@deeleeramone
Copy link
Contributor

FYI, Polygon uses a period for share classes and not a "-". BRK-A = BRK.A

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