business-science / tidyquant

Bringing financial analysis to the tidyverse
https://business-science.github.io/tidyquant/
Other
854 stars 175 forks source link

tq_exchange returning error message #190

Closed mcfsalla closed 3 years ago

mcfsalla commented 3 years ago

The tq_exchange function is returning the same error for any exchange: Error: Can't rename columns that don't exist. x Column 'Symbol' doesn't exist.

mdancho84 commented 3 years ago

Here's the website. https://www.nasdaq.com/market-activity/stocks/screener?exchange=nyse

I can't find the link that will download the CSV from it. Seems like they don't want people getting the CSV via CURL.

mcfsalla commented 3 years ago

Yes, I figured it out, sorry for not closing the issue. On 29 Jan 2021 16:49 -0300, Matt Dancho notifications@github.com, wrote:

Here's the website. https://www.nasdaq.com/market-activity/stocks/screener?exchange=nyse I can't find the link that will download the CSV from it. Seems like they don't want people getting the CSV via CURL. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

tzeenech commented 3 years ago

I ran into the same issue. I found when you click on the download CSV button there is an API call made that returns a JSON envelope back with the info. No authorization header required.

https://api.nasdaq.com/api/screener/stocks?tableonly=true&limit=25&offset=0&exchange=nyse&download=true

The exchange can be tweaked, the limit=25 doesn't seem to matter.

mdancho84 commented 3 years ago

Awesome! This could be the solution.

HarryGrosse commented 3 years ago

Ran into the same problem:

tq_exchange("NASDAQ")
Error: Can't rename columns that don't exist.
x Column `Symbol` doesn't exist.

Looking for guidance from the team, It seems like this is the path to a solution: https://stackoverflow.com/questions/37996827/convert-json-file-to-a-csv-file-using-r

Agree?

tzeenech commented 3 years ago

I ended up using httr's GET() function which can do json parsing. It produces a data frame with the column headers and a list of rows, each being a list of values.

mdancho84 commented 3 years ago

Solution seems straightforward. I'm tied up and won't be able to tackle for a bit. If someone can make a pull request, it would be much appreciated. Otherwise I'll tackle once I get some free time.

mgei commented 3 years ago

I tried to fix it, works for me: https://github.com/business-science/tidyquant/pull/194

mdancho84 commented 3 years ago

Hey everyone, #194 has just been merged. Thanks @mgei for helping with integrating. It works very fast. Give him a 👏

mdancho84 commented 3 years ago

Until this fix gets to CRAN please install using:

remotes::install_github("business-science/tidyquant")