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

getOptionChain can no longer access Yahoo Finance with the URL it uses #407

Closed
cotyreh opened this issue Jan 26, 2024 · 13 comments
Closed
Assignees
Labels

Comments

@cotyreh
Copy link

cotyreh commented Jan 26, 2024

Description

As of the morning of 26 Jan 2023 CST, there was some change on Yahoo Finance's side where getOptionChain() no longer has permission to access the option chain data with the link it uses. I know that it happened early in the morning because my script logs show that it was running as intended until the error popped up.

Expected behavior

Here is an example from my logs of before and after the error started occurring:

Loading required package: TTR
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
Loading required package: xts
Loading required package: zoo

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Loading required package: TTR
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
Warning: no data for '^SPX' expiry , omitting
	(server response: cannot open the connection to 'https://query2.finance.yahoo.com/v7/finance/options/^SPX')
Warning message:
In open.connection(con, "rb") :
  cannot open URL 'https://query2.finance.yahoo.com/v7/finance/options/^SPX': HTTP status was '401 Unauthorized'

I tried different symbols and none of them worked. I also checked that the getQuote still works, so the issue is contained to accessing the options chains from Yahoo Finance.

@lynncullotta
Copy link

lynncullotta commented Jan 29, 2024

Ran into similar issue. My Mboum options data feed simultaneously broke so I wonder if the problem isn't further down the line?

Edit: I am also using the yfinance package in Python, not this package

@ethanbsmith
Copy link
Contributor

looks like yahoo is using a crumb in the call. possibly related to what we saw w/ getQuote and GDPR. may be able to reuse some of the work we did on that

for reference:

https://query1.finance.yahoo.com/v7/finance/options/SPY?date=1706832000&formatted=true&straddle=false&lang=en-US&region=US&crumb=qnrVMPmwwBR

@joshuaulrich
Copy link
Owner

looks like yahoo is using a crumb in the call

That's it! It works when I add the crumb to the URL. I'll work on getting a patch pushed.

@joshuaulrich joshuaulrich self-assigned this Jan 29, 2024
@joshuaulrich
Copy link
Owner

This should be fixed now. Please install and test with remotes::install_github("joshuaulrich/quantmod@407-getoptionchain")

@cotyreh
Copy link
Author

cotyreh commented Jan 29, 2024

This should be fixed now. Please install and test with remotes::install_github("joshuaulrich/quantmod@407-getoptionchain")

It works!

`

SPX <-getOptionChain("^SPX")
print(SPX)
$calls
ContractID ConractSize Currency Expiration Strike Last Chg ChgPct Bid Ask Vol
1 SPXW240129C01200000 REGULAR USD 2024-01-29 1200 3594.25 0.0000000 0.00000000 3719.3 3737.7 2
2 SPXW240129C01800000 REGULAR USD 2024-01-29 1800 3088.40 0.0000000 0.00000000 3119.3 3137.7 1
3 SPXW240129C02000000 REGULAR USD 2024-01-29 2000 2888.70 0.0000000 0.00000000 2919.3 2937.7 9
4 SPXW240129C02600000 REGULAR USD 2024-01-29 2600 2288.52 0.0000000 0.00000000 2319.3 2337.7 5
5 SPXW240129C03600000 REGULAR USD 2024-01-29 3600 1181.60 0.0000000 0.00000000 1319.3 1337.7 2`

@joshuaulrich
Copy link
Owner

Thanks for verifying the fix!

@avhz
Copy link

avhz commented Feb 1, 2024

I'm still running into this issue after installing from GitHub.

@steversteves
Copy link

I'm still running into this issue after installing from GitHub.

Still having the error as well, any other suggestions?
Is quantmod going to be patched? I know Python had the same issue but yf has been since patched but it seems quantmod has not.

@joshuaulrich
Copy link
Owner

joshuaulrich commented Feb 2, 2024

@avhz and @steversteves are you in GDPR countries?

@steversteves are you able to use yfinance to import options from yahoo? You say it had the same issue but has since been patched... but yfinance was last updated on Jan-21 and this issue began on Jan-26, 5 days after the last yfinance update.

@avhz
Copy link

avhz commented Feb 2, 2024

@joshuaulrich No, Australia.

@steversteves
Copy link

@avhz and @steversteves are you in GDPR countries?

@steversteves are you able to use yfinance to import options from yahoo? You say it had the same issue but has since been patched... but yfinance was last updated on Jan-21 and this issue began on Jan-26, 5 days after the last yfinance update.

Thanks for getting back!
No I am in Canada, I am not a Python user personally, it was just reported to me by a Python user that there was also an issue that they had to update the yf library.

I can't import options no, I get the crumb error, I am completely blocked out of anything option related. I did run your patch it just didn't fix the issue for me and I did try to update quantmod, but again it didn't fix.
I'm also a very noob coder so its probably me! :-(

@joshuaulrich
Copy link
Owner

@avhz can you try https://github.com/ranaroussi/yfinance and let me know if it works for you?

@joshuaulrich joshuaulrich added this to the Release 0.4.26 milestone Feb 14, 2024
@justinjtownsend
Copy link

Just looking at this (from the UK) and it's this check NROW(curl::handle_cookies(ses$h)) > 1) which for me fails the test for ses$can.crumb.

If I add a test crumb to the v7 API URL endpoint for options ( e.g. https://query2.finance.yahoo.com/v7/finance/options/%5ESPX?crumb=YdJC5tMaYMS ) then the dataset comes back successfully.

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

No branches or pull requests

7 participants