2019-07-21 16:59:47 +02:00
|
|
|
import * as request from 'request';
|
|
|
|
|
|
|
|
class FiatConversion {
|
|
|
|
private tickers = {
|
|
|
|
'BTCUSD': {
|
|
|
|
'USD': 4110.78
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
public startService() {
|
2020-02-26 11:49:53 +01:00
|
|
|
console.log('Starting currency rates service');
|
2019-07-21 16:59:47 +02:00
|
|
|
setInterval(this.updateCurrency.bind(this), 1000 * 60 * 60);
|
|
|
|
this.updateCurrency();
|
|
|
|
}
|
|
|
|
|
|
|
|
public getTickers() {
|
|
|
|
return this.tickers;
|
|
|
|
}
|
|
|
|
|
|
|
|
private updateCurrency() {
|
|
|
|
request('https://api.opennode.co/v1/rates', { json: true }, (err, res, body) => {
|
|
|
|
if (err) { return console.log(err); }
|
|
|
|
if (body && body.data) {
|
|
|
|
this.tickers = body.data;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new FiatConversion();
|