yahoo-stock-api
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -6,2 +6,3 @@ import type { HistoricalPricesOptions, HistoricalPricesResponse } from './types/historicalPrices'; | ||
private requestPool; | ||
getTidyName(dirtyName: string): string; | ||
getHistoricalPrices({ startDate, endDate, symbol, frequency }: HistoricalPricesOptions): Promise<APIresponse>; | ||
@@ -22,2 +23,3 @@ getSymbol({ symbol }: { | ||
currency: string; | ||
name: string; | ||
} | ||
@@ -24,0 +26,0 @@ interface ErrorResponse { |
@@ -38,2 +38,7 @@ "use strict"; | ||
requestPool = new undici_1.Pool('https://finance.yahoo.com'); | ||
getTidyName(dirtyName) { | ||
const name = dirtyName; | ||
const regex = /^[^(]*/; | ||
return regex.exec(name)[0].trim(); | ||
} | ||
async getHistoricalPrices({ startDate, endDate, symbol, frequency }) { | ||
@@ -62,2 +67,3 @@ try { | ||
currency = currency ? currency.split('.')[1].replace('Currency in', '').trim() : undefined; | ||
const name = this.getTidyName($('h1').text()); | ||
const response = $('#Col1-1-HistoricalDataTable-Proxy > section > div:nth-child(2) > table > tbody > tr').map(this.getHistoricalPricesMapRows).get(); | ||
@@ -67,2 +73,3 @@ return { | ||
currency: currency || undefined, | ||
name: name || undefined, | ||
response, | ||
@@ -86,2 +93,3 @@ }; | ||
let currency = $('#quote-header-info > div:nth-child(2) > div > div > span').text(); | ||
const name = this.getTidyName($('h1').text()); | ||
currency = currency ? currency.split('.')[1].replace('Currency in', '').trim() : undefined; | ||
@@ -92,3 +100,3 @@ // @ts-ignore | ||
const col2 = $('#quote-summary > div.Pstart\\(12px\\) > table > tbody').map(this.getSymbolMapRows).get()[0]; | ||
return this.handleResponse({ updated: Date.now(), ...this.parseCol1(col1), ...this.parseCol2(col2) }, currency); | ||
return this.handleResponse({ updated: Date.now(), ...this.parseCol1(col1), ...this.parseCol2(col2) }, currency, name); | ||
} | ||
@@ -135,3 +143,3 @@ catch (err) { | ||
} | ||
handleResponse(response, currency) { | ||
handleResponse(response, currency, name) { | ||
if (!response) | ||
@@ -142,2 +150,3 @@ throw new Error('Response if not provided'); | ||
currency: currency || undefined, | ||
name: name || undefined, | ||
response, | ||
@@ -222,5 +231,5 @@ }; | ||
// @ts-ignore | ||
json[k]['start'] = start; | ||
json[k]['start'] = start || null; | ||
// @ts-ignore | ||
json[k]['end'] = end; | ||
json[k]['end'] = end || null; | ||
break; | ||
@@ -231,3 +240,3 @@ } | ||
// @ts-ignore | ||
json.forwardDividend = fdividend; | ||
json.forwardDividend = fdividend || null; | ||
// @ts-ignore | ||
@@ -239,3 +248,3 @@ json.forwardYield = fyield; | ||
// @ts-ignore | ||
json[k] = (0, utils_1.dateToUnix)(v); | ||
json[k] = !v ? null : (0, utils_1.dateToUnix)(v); | ||
break; | ||
@@ -242,0 +251,0 @@ default: |
@@ -12,8 +12,1 @@ "use strict"; | ||
yahoo.getHistoricalPrices({ startDate, endDate, symbol: 'AAPL', frequency: '1d' }).then(console.log); | ||
(async () => { | ||
const result = await yahoo.getSymbol({ symbol: "AAPL" }); | ||
if (result.error === true) | ||
return; | ||
else | ||
console.log(result.response); | ||
})(); |
{ | ||
"name": "yahoo-stock-api", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Simple package to get stock price from yahoo finance", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
109
README.md
@@ -54,38 +54,38 @@ # yahoo-stock-api | ||
currency: 'USD', | ||
data: [ | ||
response: [ | ||
{ | ||
date: 1598448600, | ||
open: 504.7200012207031, | ||
high: 507.9700012207031, | ||
low: 500.3299865722656, | ||
close: 506.0899963378906, | ||
volume: 40617600, | ||
adjclose: 506.0899963378906 | ||
date: 1598418000, | ||
open: 126.18, | ||
high: 126.99, | ||
low: 125.08, | ||
close: 126.52, | ||
adjClose: 124.81, | ||
volume: 163022400 | ||
}, | ||
{ | ||
date: 1598362200, | ||
open: 498.7900085449219, | ||
high: 500.7200012207031, | ||
low: 492.2099914550781, | ||
close: 499.29998779296875, | ||
volume: 52873900, | ||
adjclose: 499.29998779296875 | ||
date: 1598331600, | ||
open: 124.7, | ||
high: 125.18, | ||
low: 123.05, | ||
close: 124.82, | ||
adjClose: 123.13, | ||
volume: 211495600 | ||
}, | ||
{ | ||
date: 1598275800, | ||
open: 514.7899780273438, | ||
high: 515.1400146484375, | ||
low: 495.75, | ||
close: 503.42999267578125, | ||
volume: 86484400, | ||
adjclose: 503.42999267578125 | ||
date: 1598245200, | ||
open: 128.7, | ||
high: 128.79, | ||
low: 123.94, | ||
close: 125.86, | ||
adjClose: 124.15, | ||
volume: 345937600 | ||
}, | ||
{ | ||
date: 1598016600, | ||
open: 477.04998779296875, | ||
high: 499.4700012207031, | ||
low: 477, | ||
close: 497.4800109863281, | ||
volume: 84513700, | ||
adjclose: 497.4800109863281 | ||
date: 1597986000, | ||
open: 119.26, | ||
high: 124.87, | ||
low: 119.25, | ||
close: 124.37, | ||
adjClose: 122.68, | ||
volume: 338054800 | ||
} | ||
@@ -121,22 +121,22 @@ ] | ||
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 }, | ||
updated: 1673486286910, | ||
previousClose: 130.73, | ||
open: 131.25, | ||
bid: { value: 133.42, shares: 900 }, | ||
ask: { value: 133.47, shares: 1000 }, | ||
dayRange: { low: 130.46, high: 133.49 }, | ||
fiftyTwoWeekRange: { low: 124.17, high: 179.61 }, | ||
volume: 69458949, | ||
avgVolume: 83633004, | ||
marketCap: 2124000000000, | ||
beta: 1.27, | ||
peRatio: 21.85, | ||
eps: 6.11, | ||
earningsDate: { start: 1675317600, end: undefined }, | ||
forwardDividend: 0.92, | ||
forwardYield: 0.67, | ||
exDividendDate: 1659675600, | ||
oneYearTargetEst: 183.5 | ||
} | ||
} | ||
forwardYield: 0.71, | ||
exDividendDate: 1667538000, | ||
oneYearTargetEst: 173.25 | ||
} | ||
} | ||
``` | ||
@@ -160,7 +160,10 @@ </details> | ||
<table> | ||
<tr> | ||
<td align="center"><a href="https://github.com/phamleduy04"><img src="https://avatars2.githubusercontent.com/u/32657584?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Duy Pham Le</b></sub></a><br /><a href="https://github.com/phamleduy04/yahoo-stock-api/commits?author=phamleduy04" title="Code">💻</a></td> | ||
<td align="center"><a href="http://altitudequest.com"><img src="https://avatars3.githubusercontent.com/u/18537842?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Rajat</b></sub></a><br /><a href="#ideas-rajataudichya" title="Ideas, Planning, & Feedback">🤔</a></td> | ||
<td align="center"><a href="https://github.com/twhtanghk"><img src="https://avatars1.githubusercontent.com/u/1798269?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Tommy Tang</b></sub></a><br /><a href="https://github.com/phamleduy04/yahoo-stock-api/commits?author=twhtanghk" title="Code">💻</a> <a href="https://github.com/phamleduy04/yahoo-stock-api/issues?q=author%3Atwhtanghk" title="Bug reports">🐛</a></td> | ||
</tr> | ||
<tbody> | ||
<tr> | ||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/phamleduy04"><img src="https://avatars2.githubusercontent.com/u/32657584?v=4?s=100" width="100px;" alt="Duy Pham Le"/><br /><sub><b>Duy Pham Le</b></sub></a><br /><a href="https://github.com/phamleduy04/yahoo-stock-api/commits?author=phamleduy04" title="Code">💻</a></td> | ||
<td align="center" valign="top" width="14.28%"><a href="http://altitudequest.com"><img src="https://avatars3.githubusercontent.com/u/18537842?v=4?s=100" width="100px;" alt="Rajat"/><br /><sub><b>Rajat</b></sub></a><br /><a href="#ideas-rajataudichya" title="Ideas, Planning, & Feedback">🤔</a></td> | ||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/twhtanghk"><img src="https://avatars1.githubusercontent.com/u/1798269?v=4?s=100" width="100px;" alt="Tommy Tang"/><br /><sub><b>Tommy Tang</b></sub></a><br /><a href="https://github.com/phamleduy04/yahoo-stock-api/commits?author=twhtanghk" title="Code">💻</a> <a href="https://github.com/phamleduy04/yahoo-stock-api/issues?q=author%3Atwhtanghk" title="Bug reports">🐛</a></td> | ||
<td align="center" valign="top" width="14.28%"><a href="http://shykeiichi.com"><img src="https://avatars.githubusercontent.com/u/60363370?v=4?s=100" width="100px;" alt="keiichi"/><br /><sub><b>keiichi</b></sub></a><br /><a href="https://github.com/phamleduy04/yahoo-stock-api/commits?author=shykeiichi" title="Code">💻</a></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
@@ -167,0 +170,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23892
384
177