2020-10-13 10:27:52 +02:00
|
|
|
import logger from '../logger';
|
2020-11-15 08:22:47 +01:00
|
|
|
import axios from 'axios';
|
2019-07-21 16:59:47 +02:00
|
|
|
|
|
|
|
class FiatConversion {
|
|
|
|
private tickers = {
|
|
|
|
'BTCUSD': {
|
|
|
|
'USD': 4110.78
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
|
|
|
public startService() {
|
2020-10-13 10:27:52 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-11-15 08:22:47 +01:00
|
|
|
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();
|