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

35 lines
833 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 conversionRates = {
'USD': 0
2019-07-21 16:59:47 +02:00
};
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 getConversionRates() {
return this.conversionRates;
2019-07-21 16:59:47 +02:00
}
private async updateCurrency(): Promise<void> {
try {
const response = await axios.get('https://price.bisq.wiz.biz/getAllMarketPrices ');
const usd = response.data.data.find((item: any) => item.currencyCode === 'USD');
this.conversionRates = {
'USD': usd.price,
};
} catch (e) {
logger.err('Error updating fiat conversion rates: ' + e);
}
2019-07-21 16:59:47 +02:00
}
}
export default new FiatConversion();