mempool/backend/src/api/fiat-conversion.ts

34 lines
741 B
TypeScript
Raw Normal View History

2019-07-21 16:59:47 +02:00
import * as request from 'request';
import logger from '../logger';
2019-07-21 16:59:47 +02:00
class FiatConversion {
private tickers = {
'BTCUSD': {
'USD': 4110.78
},
};
constructor() { }
public startService() {
logger.info('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) => {
2020-10-15 06:12:33 +02:00
if (err) { return logger.err('Error updating currency from OpenNode: ' + err); }
2019-07-21 16:59:47 +02:00
if (body && body.data) {
this.tickers = body.data;
}
});
}
}
export default new FiatConversion();