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

34 lines
715 B
TypeScript
Raw Normal View History

import logger from '../logger';
import axios from 'axios';
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 async updateCurrency(): Promise<void> {
try {
const response = await axios.get('https://api.opennode.co/v1/rates');
this.tickers = response.data.data;
} catch (e) {
logger.err('Error updating currency from OpenNode: ' + e);
}
2019-07-21 16:59:47 +02:00
}
}
export default new FiatConversion();