towards / basic_yahoo_finance

Simple Ruby gem for Yahoo! Finance API
GNU General Public License v3.0
19 stars 9 forks source link

v7 API down #3

Closed daviddigital closed 1 year ago

daviddigital commented 1 year ago

Thanks for building this gem.

As you are no doubt aware the current version API is broken (https://query1.finance.yahoo.com/v7/finance/quote?symbols=AAPL), and the fix is committed but not released (using v6 instead of v7 in api path).

brigriffin commented 1 year ago

Hi @daviddigital,

Yes, there have been some changes and using the v6 instead of the v7 API is just a workaround for now. I will nevertheless plan a new release of this gem probably still today.

brigriffin commented 1 year ago

@daviddigital the new version 0.4.0 of the gem has now been released.

daviddigital commented 1 year ago

Awesome work @brigriffin

daviddigital commented 1 year ago

Now v6 is down 😢 https://query1.finance.yahoo.com/v6/finance/quote?symbols=AAPL

Looking into alternatives and I'll create a PR if I find one

daviddigital commented 1 year ago

Short of doing something like using this endpoint for the graph (very wasteful) https://query1.finance.yahoo.com/v8/finance/chart/AAPL I couldn't see anything having a google and inspecting the network tab on their site.

I am probably going to have to investigate other options like https://site.financialmodelingprep.com/developer/docs/#Ticker-Search which unfortunately may not be suitable for this gem but meets my use case of getting some data for a hobby project.

daviddigital commented 1 year ago

If I'm wrong and you do think this resource provider would be useful I could submit a PR. Users of this gem would need to provide an API key for the service still.

I have seen some others move to this service e.g. OpenBB

daviddigital commented 1 year ago

Something promising via yfinance: https://github.com/ranaroussi/yfinance/blob/d9bfd291131ca70121c0fd0b027512a268b2fc8b/yfinance/scrapers/quote.py#LL23C16-L23C73

e.g. https://query2.finance.yahoo.com/v10/finance/quoteSummary/AAPL?modules=price

daviddigital commented 1 year ago

I’ll submit a PR for the v10 option yfinance use for review shortly

brigriffin commented 1 year ago

It was really just a matter of time until they also take down the v6 version of their API unfortunately... If you have a moment a PR would be very welcome for their new v10 API.

daviddigital commented 1 year ago

Thanks for merging the the PR @brigriffin

Checking out your commits, looks good, like defaulting to price, but I had one thought about this inefficient process of handling multiple tickers.

For the request https://github.com/towards/basic_yahoo_finance/blob/156a24137209e73b7e17483e7f5b0c9ce3abbdfa/lib/basic_yahoo_finance.rb#L23

Do you know how open-uri is handling the requests in terms of whether its starting a new connection each time? Yahoo finance's api can handle persistent connections so we should be able to use sometihng like this so that we open the connection -> perform each of the requests -> close the connection.

Let me know your thoughts. Maybe something for the future

daviddigital commented 1 year ago

Relevant gem which is a wrapper on the above https://github.com/drbrain/net-http-persistent

daviddigital commented 1 year ago

Confirming that open-uri is opening up a new connection each time.

Let me know if you'd like me to put together a PR @brigriffin

hostingnuggets commented 1 year ago

Great idea regarding the persistent connections, it should make the querying of multiple symbols faster. I tested with around 15 symbols and the speed it not too bad. If you have time a PR would be good, no urgency though as for now it works nicely.

daviddigital commented 1 year ago

Cool, I'll have a look next weekend, do you mind if we release the current build now and I'll close this issue?

daviddigital commented 1 year ago

Actually I ended up implementing this, just sorting out the error handling, seems to be a lot faster, PR to come shortly.

daviddigital commented 1 year ago

5

brigriffin commented 1 year ago

Have a look at my latest commit 6644308 it includes full code coverage and that would be the commit I will use for a new release of the gem if you are fine with that.

daviddigital commented 1 year ago

Looks great @brigriffin thanks for fixing that test, let’s ship it!

daviddigital commented 1 year ago

What’s the best way let people know that they will need to append [“fmt”] to their existing code to get the formatted value? It’s in the updated readme under usage, do you think that’s enough?

brigriffin commented 1 year ago

Thanks for your feedback and contribution. I think for now it's fine like that, if many people open an issue because of that, we can always add a big warning in the README. I just released version 0.5.0 of the gem which includes all the newest changes.