-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathyf-test.js
29 lines (26 loc) · 957 Bytes
/
yf-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const fields = [
'symbol',
'regularMarketTime',
'regularMarketPrice',
'regularMarketPreviousClose',
'regularMarketChange',
'regularMarketChangePercent'
];
const symbols = ["^DJI", "^IXIC", "^GSPC", "^TNX", "CL=F", "EURUSD=X"];
async function getQuotes(symbolList) {
const yahooFinance = require('yahoo-finance2').default;
yahooFinance.suppressNotices(['yahooSurvey']);
const quotes = await yahooFinance.quote(symbolList, {fields: fields},{validateResult: false});
console.log("Num returned: ", quotes.length);
return quotes;
}
getQuotes(symbols).then(quotes => {
console.log("Num items = ", quotes.length);
quotes.forEach( quote => {
console.log(quote.symbol, quote.regularMarketPrice, quote.regularMarketPreviousClose,
quote.regularMarketChange, quote.regularMarketChangePercent);
});
})
.catch(err => {
console.log("Error: ", err);
});