|
|
@ -18,16 +18,11 @@ var FETCH_INTERVAL = 15; // In minutes |
|
|
|
|
|
|
|
function FiatRateService() {}; |
|
|
|
|
|
|
|
FiatRateService.prototype.start = function(opts, cb) { |
|
|
|
FiatRateService.prototype.init = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
if (_.isArray(opts.providers)) { |
|
|
|
self.providers = opts.providers; |
|
|
|
} else { |
|
|
|
self.providers = _.values(require('./fiatrateproviders')); |
|
|
|
} |
|
|
|
self.request = opts.request || request; |
|
|
|
self.defaultProvider = opts.defaultProvider || DEFAULT_PROVIDER; |
|
|
|
|
|
|
@ -45,19 +40,27 @@ FiatRateService.prototype.start = function(opts, cb) { |
|
|
|
], function(err) { |
|
|
|
if (err) { |
|
|
|
log.error(err); |
|
|
|
return cb(err); |
|
|
|
} |
|
|
|
return cb(err); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
FiatRateService.prototype.startCron = function(opts, cb) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
var interval = opts.fetchInterval || FETCH_INTERVAL; |
|
|
|
if (interval) { |
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
self.providers = _.values(require('./fiatrateproviders')); |
|
|
|
|
|
|
|
var interval = opts.fetchInterval || FETCH_INTERVAL; |
|
|
|
if (interval) { |
|
|
|
self._fetch(); |
|
|
|
setInterval(function() { |
|
|
|
self._fetch(); |
|
|
|
setInterval(function() { |
|
|
|
self._fetch(); |
|
|
|
}, interval * 60 * 1000); |
|
|
|
} |
|
|
|
}, interval * 60 * 1000); |
|
|
|
} |
|
|
|
|
|
|
|
return cb(); |
|
|
|
}); |
|
|
|
return cb(); |
|
|
|
}; |
|
|
|
|
|
|
|
FiatRateService.prototype._fetch = function(cb) { |
|
|
@ -112,7 +115,7 @@ FiatRateService.prototype.getRate = function(code, opts, cb) { |
|
|
|
|
|
|
|
opts = opts || {}; |
|
|
|
|
|
|
|
var provider = opts.provider || DEFAULT_PROVIDER; |
|
|
|
var provider = opts.provider || self.defaultProvider; |
|
|
|
var ts = opts.ts || Date.now(); |
|
|
|
|
|
|
|
async.map([].concat(ts), function(ts, cb) { |
|
|
|