-
Notifications
You must be signed in to change notification settings - Fork 15
/
coinchooseCom.js
52 lines (42 loc) · 1.76 KB
/
coinchooseCom.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
var _ = require('lodash'),
request = require('../../utils/request'),
Module =require('../../Module');
module.exports = Module.extend({
defaults: {
interval: 6 * 60 * 60 * 1e3,
coin: 'BTC'
},
viewId: 'technical',
initialize: function () {
var self = this;
self.title = 'Coinchoose.com - ' + self.config.coin;
setInterval(function () { self.updateStats(); }, self.config.interval);
self.updateStats();
},
updateStats: function () {
var self = this;
request('http://www.coinchoose.com/api.php?base=BTC').then(function (response) {
var coin = _.find(response, function (coin) {
return coin.symbol === self.config.coin;
});
if (coin) {
self.app.logger.debug('%s - fetched data from coinchoose.com', self.id, JSON.stringify(response));
self.set({
coin: self.config.coin,
algorithm: coin.algo,
blockReward: parseFloat(coin.reward),
probability: 1 / (4295032833 * parseFloat(coin.difficulty)),
difficulty: parseFloat(coin.difficulty),
networkHashrate: parseFloat(coin.networkhashrate) / 1e6,
blockChainLength: parseFloat(coin.currentBlocks),
timeBetweenBlocks: parseFloat(coin.minBlockTime)
});
} else {
self.app.logger.info('%s - error fetching data from coinchoose.com', self.id, 'Coin ' + self.config.coin + ' not found');
}
}).catch(function (err) {
self.app.logger.info('%s - error fetching data from coinchoose.com', self.id, err.toString());
});
}
});