forked from charlesamoreira/cotacoes-bovespa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cotacoes-bovespa.js
30 lines (22 loc) · 1.37 KB
/
cotacoes-bovespa.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
30
var request = require('request');
module.exports.getCurrentQuote = function(ticker, callback){
request("https://finance.yahoo.com/quote/" + ticker + ".sa/", function(err, res, body){
if (err) {
callback(err);
}
var main = JSON.parse(body.split("root.App.main = ")[1].split(";\n}(this));")[0]);
var quote = {};
if(main.context.dispatcher.stores.QuoteSummaryStore.financialData !== undefined){
quote.price = parseFloat(main.context.dispatcher.stores.QuoteSummaryStore.financialData.currentPrice.fmt);
quote.open = parseFloat(main.context.dispatcher.stores.QuoteSummaryStore.price.regularMarketOpen.fmt);
quote.high = parseFloat(main.context.dispatcher.stores.QuoteSummaryStore.price.regularMarketDayHigh.fmt);
quote.low = parseFloat(main.context.dispatcher.stores.QuoteSummaryStore.price.regularMarketDayLow.fmt);
quote.previousClose = parseFloat(main.context.dispatcher.stores.QuoteSummaryStore.price.regularMarketPreviousClose.fmt);
quote.volume = parseFloat(main.context.dispatcher.stores.QuoteSummaryStore.price.regularMarketVolume.fmt);
quote.marketChange = parseFloat(main.context.dispatcher.stores.QuoteSummaryStore.price.regularMarketChange.fmt);
quote.shortName = main.context.dispatcher.stores.QuoteSummaryStore.price.shortName;
quote.longName = main.context.dispatcher.stores.QuoteSummaryStore.price.longName;
}
callback(null, quote);
});
};