Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
yahoo-finance2
Advanced tools
Community API for Yahoo-Finance.
Copyright (c) 2021 by Gadi Cohen and Pilwon Huh. MIT licensed.
Supports Node 12.0.0 and up (tests are run against 12.0.0).
Stable release - supersedes the ubiquitous node-yahoo-finance v1. NB: The API has changed, see UPGRADING for more information.
This project is neither created nor endorsed by Yahoo Inc. Yahoo does not provide any official API to developers, nor makes any guarantees regarding service availability or API consistency. In practice however, the open source community has kept this project (and it's predecessor) working well since 2013.
Nevertheless, we make no guarantees and you use this package at your own risk. The developers (and obviously Yahoo) cannot be held responsible for any losses you may incur as a result of using this service. Use of this package is considered acknowledgement and acceptance of these terms and of it's license.
CLI (Command line interface)
$ npx yahoo-finance2 search AAPL
# or install it
$ npm install -g yahoo-finance2
$ yahoo-finance search AAPL '{ "someOption": true }'
Importing
// import syntax (recommended)
import yahooFinance from 'yahoo-finance2';
// require syntax (if your code base does not support imports)
const yahooFinance = require('yahoo-finance2').default; // NOTE the .default
const results = await yahooFinance.search('AAPL');
const results = await yahooFinance.search('AAPL', { someOption: true, etc });
Available modules:
,
autoc
chart
,
historical
,
quote
,
quoteSummary
(submodules:
assetProfile, balanceSheetHistory, balanceSheetHistoryQuarterly,
calendarEvents, cashflowStatementHistory, cashflowStatementHistoryQuarterly,
defaultKeyStatistics, earnings, earningsHistory, earningsTrend, financialData,
fundOwnership, fundPerformance, fundProfile, incomeStatementHistory,
incomeStatementHistoryQuarterly, indexTrend, industryTrend, insiderHolders
insiderTransactions, institutionOwnership, majorDirectHolders,
majorHoldersBreakdown, netSharePurchaseActivity, price, quoteType,
recommendationTrend, secFilings, sectorTrend, summaryDetail, summaryProfile,
symbol, topHoldings, upgradeDowngradeHistory),
search
,
recommendationsBySymbol
,
trendingSymbols
,
options
,
insights
, with more
coming soon.
Extras: quoteCombine
.
Utils: setGlobalConfig
.
See the Full Documentation.
Particularly, make sure to read the notes there on ERROR HANDLING. Be aware that if a stock gets delisted, Yahoo removes all related data, including historical (and chart) data from periods before the delisting occurred (i.e. queries that worked before will start failing, and there is no way to retrieve this data again).
const quote = await yahooFinance.quote('AAPL');
const { regularMarketPrice as price, currency } = quote;
This package is shipped as both an ES Module and a CommonJS module. Node will automatically load the ES module if:
package.json
contains a { type: module }
entry--experimental-module
flag).import
the module (require
function does not exist in ES modules)otherwise the traditional CommonJS module will be loaded. No flags are
necessary for Node 12.7.0+ and Node 13.2.0+, but for older versions, you need
to add the --experimental-module
flag).
ES Modules are "relatively" new. They got a big boost in April 2021 when Node 10, which did not support them, reached end-of-life. However, support varies by build tool and configuration, and there are some edge cases which can be tricky. Please open an issue if you run into any trouble.
require (CommonJS)
If you use load the library with require
, make sure to add .default
:
const yahooFinance = require('yahoo-finance2').default; // NOTE the .default
Working with yahoo-finance2
is a joy if you're using TypeScript (but you
don't have to), with type checking and auto completion:
Try it yourself on our Live CodeSandbox.
This project is primarily developed to be used server-side in node
.
Nevertheless, due to the large number on requests on this issue, we have
taken care to ensure the package can be imported in the browser too.
HOWEVER: you'll run into other challenges there that we can't help you with, particularly CORS issues when trying to query Yahoo's servers in the browser from non-Yahoo origins. Since Yahoo is specifically blocking such requests, we will not help you bypass them. (One way around this is to run your own server to proxy your requests, but we won't help you with this).
Pull Requests welcome! Read CONTRIBUTING.md and join our list of heroes:
Special mention goes out to pudgereyem and PythonCreator27 who made significant contributions in the very early days of this project.
FAQs
JS API for Yahoo Finance
The npm package yahoo-finance2 receives a total of 5,616 weekly downloads. As such, yahoo-finance2 popularity was classified as popular.
We found that yahoo-finance2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.