yahoo-stock-api
💰 NPM package to get stock and historical price from finance.yahoo.com
⚠️ Breaking changes ⚠️
v2.0.0 of this package have breaking changes and can affect your code, please review it and change according to the documentation below!
![
Installaion
npm i yahoo-stock-api
or yarn add yahoo-stock-api
if you use yarn.
API
Everything in this API will return Promise so remember to use async/await
or callback
getHistoricalPrices: async function({ startDate, endDate, symbol, frequency })
- startDate: Date
- endDate: Date
- symbol: String (stock symbol)
- frequency: String ('1d', '1wk' or '1mo' only)
- 1d: 1day
- 1wk: 1 week
- 1mo: 1 month
Return Promise
Example
Code
const yahooStockAPI = require('yahoo-stock-api').default;
const yahoo = new yahooStockAPI();
const startDate = new Date('08/21/2020');
const endDate = new Date('08/26/2020');
yahoo.getHistoricalPrices({ startDate, endDate, symbol: 'AAPL', frequency: '1d' }).then(console.log);
Response
{
error: false,
currency: 'USD',
data: [
{
date: 1598448600,
open: 504.7200012207031,
high: 507.9700012207031,
low: 500.3299865722656,
close: 506.0899963378906,
volume: 40617600,
adjclose: 506.0899963378906
},
{
date: 1598362200,
open: 498.7900085449219,
high: 500.7200012207031,
low: 492.2099914550781,
close: 499.29998779296875,
volume: 52873900,
adjclose: 499.29998779296875
},
{
date: 1598275800,
open: 514.7899780273438,
high: 515.1400146484375,
low: 495.75,
close: 503.42999267578125,
volume: 86484400,
adjclose: 503.42999267578125
},
{
date: 1598016600,
open: 477.04998779296875,
high: 499.4700012207031,
low: 477,
close: 497.4800109863281,
volume: 84513700,
adjclose: 497.4800109863281
}
]
}
getSymbol({ symbol })
- symbol: String (stock symbol)
Return Promise
Example
Code
const yahooStockAPI = require('yahoo-stock-api').default;
const yahoo = new yahooStockAPI();
yahoo.getSymbol({ symbol: 'AAPL' }).then(console.log);
Response
{
error: false,
currency: 'USD',
response: {
updated: 1664829357507,
previousClose: 138.2,
open: 138.21,
bid: { value: 142.42, shares: 1100 },
ask: { value: 142.44, shares: 1300 },
dayRange: { low: 137.68, high: 143.07 },
fiftyTwoWeekRange: { low: 129.04, high: 182.94 },
volume: 113578851,
avgVolume: 78897638,
marketCap: 2289000000000,
beta: 1.23,
peRatio: 23.55,
eps: 6.05,
earningsDate: { start: 1666760400, end: 1667192400 },
forwardDividend: 0.92,
forwardYield: 0.67,
exDividendDate: 1659675600,
oneYearTargetEst: 183.5
}
}
Test
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
License