-
Notifications
You must be signed in to change notification settings - Fork 62
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
Yahoo stopped to allow .historical() request : unauthorized error #795
Comments
Thanks, we were tracking this at #349 (comment) but going to move here to make this easier to find (as a recent issue). My original response: Mmm, on the Yahoo page for this, e.g. https://finance.yahoo.com/quote/TSLA/history/, I'm pretty sure there used to be a "download" link that would let us retrieve this data as CSV. I don't see that link anymore. Maybe it still appears if you're logged in? I didn't try as I don't have a Yahoo account. In any event, all the data on the page itself (vs from a "download" link), seems to come from the
https://github.com/gadicc/node-yahoo-finance2/blob/devel/docs/modules/chart.md |
{"finance":{"result":null,"error":{"code":"forbidden","description":"User is not subscribed to Premium or has invalid cookies"}}} |
I guess I was able to fix the problem in the short term at Ghostfolio by switching from |
Worked for me, its a good temporary solution for those that are looking for this |
Thanks ! According to https://github.com/ghostfolio/ghostfolio/pull/3737/files#diff-7be88e7782ecbd969f1651da9ab3b2fc9ec36a2963784030dc2cbcec79cae690R313, these are simple steps to temporary fix this issue :
import { ChartResultArray } from 'yahoo-finance2/dist/esm/src/modules/chart';
import { HistoricalHistoryResult } from 'yahoo-finance2/dist/esm/src/modules/historical';
/*
// Original answer:
const convertToHistoricalResult = (
result: ChartResultArray
): HistoricalHistoryResult => {
return result.quotes;
}
*/
// ⚠️ As chart and historical types have some different behaviour, you may have to convert a little bit differently with :
const convertToHistoricalResult = (
result: ChartResultArray
): HistoricalHistoryResult => {
return result.quotes
.map((quote) => ({
...quote,
open: quote.open || null,
high: quote.high || null,
low: quote.low || null,
close: quote.close || null,
volume: quote.volume || null,
}))
.filter(
(dailyQuote) => dailyQuote.low !== null || dailyQuote.high !== null
);
};
In case you used .historical to get dividends, use this function instead of import { HistoricalDividendsResult, HistoricalHistoryResult } from 'yahoo-finance2/dist/esm/src/modules/historical';
// ...
const convertToDividendResult = (
result: ChartResultArray
): HistoricalDividendsResult => {
return result.events.dividends.map(({ amount: dividends, date }) => {
return { date, dividends };
});
} |
Hey all, just a big thanks from me to everyone above, for sharing all your findings, and most especially, your solutions and their verification, which is a great help to the community at a time when I'm tied down with other commitments. I'll just note that switching to yf2's Thanks again everyone 🙏 |
Thanks for laying this out so plainly, refactoring a project now and this is a godsend |
Thanks for the temp solution. Does anyone know if historical() will be fixed? When will it probably be fixed? thanks |
This is amazing thank you so much <3 |
hello, does anyone know when the error will be fixed on |
Historical is working fine in python script, for node js you can use chart() function |
Previously it used the "download" API which is no longer available. See the above issue for more info.
Thanks, everyone. Finally had a chance to work on this. As discussed, it's simply a convenience to map the requests to
There'll be an automated message here once the build is published. As this build contains a number of other big internal changes, early testing and feedback (even without using |
# [2.12.0](v2.11.3...v2.12.0) (2024-09-16) ### Bug Fixes * **chart:** fix and improve non-Date handling code for periods ([f1106c2](f1106c2)) * **circleci,readme:** use node:18.0.0 for tests, make clear in readme ([8365a90](8365a90)) * **historical:** map requests to chart() with deprec notice ([#795](#795)) ([c212df9](c212df9)) * **imports:** add import assertions required in node since 17.5.0. ([7d0deea](7d0deea)) * **imports:** specify ".js" on local imports for full ESM compat ([46ee6c1](46ee6c1)) * **index:** remove erroneously removed moduleExec import ([fe1a493](fe1a493)) * **notices:** historical() note, type improvement, onceOnly text ([c131e5c](c131e5c)) * **pkg/scripts:** still need `prepublishOnly` to run `build` ([4da1273](4da1273)) * **pkg:** add babel importAttributes plugin ([e41f65d](e41f65d)) * **pkg:** drop ts-jest, use [@swc-jest](https://github.com/swc-jest), { keepImportAssertions: false } ([a0e2847](a0e2847)) * **pkg:** use swc, remove babel (faster, fixes import assertions) ([110d28d](110d28d)) * **tests-modules:** use swc here too ([c7e849c](c7e849c)) ### Features * **notices:** notices lib, refactor, use for "yahooSurvey" ([#783](#783)) ([b4c016b](b4c016b))
🎉 This issue has been resolved in version 2.12.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolved but leaving this issue open for feedback and discoverability. |
Oops, now I'm seeing some of those null errors that @stouch mentioned 😅 That fix will come next 😅😅 e.g. |
Above issue fixed in 2.12.1. I re-used the old row null logic from before (and as described in docs/historical.md#null-rows), which skips when entries when everything is null, but throws otherwise and asks the user to report. In the last few years that's never happened but who knows, could come in handy in the future 😅 P.S. @stouch, in your fix you have |
I've just updated to version 2.12.1, but I cannot compile because the following types are no longer exported: import { HistoricalDividendsResult, HistoricalHistoryResult, HistoricalRowDividend, HistoricalRowHistory } from 'yahoo-finance2/dist/esm/src/modules/historical'; Any ideas on how to solve it. Thanks |
Pre-typebox, we exported all interfaces & types, actually because this was required for schema generation. Now that we don't need that anymore, whether or not we should do this in the longterm is a conversation that deserves merit, however, since some users make sure of these exports, we need to export them all to avoid it being a breaking change. In `quoteSummmary-iface.ts`, renamed the schemas to have a *Schema suffix and exported types without that suffix, like in other modules. Similar small change like that in `quoteSummary.ts` too. cc: @eddie-atkinson
@mtorregrosa, right you are, this was a mistake on our side when we changed over to the new type system. Hopefully fixed in 2.12.2, can you confirm? And everyone, one other critical fix in this release is the broken coercion (e.g. you wouldn't get |
For me, seems all fine in version 2.12.2, except that the following types have dissapeared: import { HistoricalRowDividend, HistoricalRowHistory } from 'yahoo-finance2/dist/esm/src/modules/historical' |
Furthermore, types seem to have changed from previous versions. |
Thanks, @mtorregrosa, this is really helpful. Our apologies again for the hassle and our thanks for taking the time to report and for your patience. I'm moving the type issues to #797 so we can track them all in one place 🙏 |
Another small issue with the conversion that I found, for adjClose, because:
We don't currently handle this correctly, I need to fix it. |
Above fixed / released in 2.12.14 🎉 |
Bug Report
Describe the bug
.historical()
requests now fails with "User not logged in" error. https://www.reddit.com/r/sheets/comments/1farvxr/broken_yahoo_finance_url/The text was updated successfully, but these errors were encountered: