From 1521d47cc7079184f801a48777c458f5f4ecaaba Mon Sep 17 00:00:00 2001 From: softsimon Date: Sun, 22 Nov 2020 16:48:55 +0700 Subject: [PATCH] Replace opennode usd price source with wiz api. fixes #166 --- backend/src/api/fiat-conversion.ts | 19 ++++++++++--------- backend/src/api/websocket-handler.ts | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/backend/src/api/fiat-conversion.ts b/backend/src/api/fiat-conversion.ts index 954b5c606..6b1038ff0 100644 --- a/backend/src/api/fiat-conversion.ts +++ b/backend/src/api/fiat-conversion.ts @@ -2,10 +2,8 @@ import logger from '../logger'; import axios from 'axios'; class FiatConversion { - private tickers = { - 'BTCUSD': { - 'USD': 4110.78 - }, + private conversionRates = { + 'USD': 0 }; constructor() { } @@ -16,16 +14,19 @@ class FiatConversion { this.updateCurrency(); } - public getTickers() { - return this.tickers; + public getConversionRates() { + return this.conversionRates; } private async updateCurrency(): Promise { try { - const response = await axios.get('https://api.opennode.co/v1/rates'); - this.tickers = response.data.data; + 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 currency from OpenNode: ' + e); + logger.err('Error updating fiat conversion rates: ' + e); } } } diff --git a/backend/src/api/websocket-handler.ts b/backend/src/api/websocket-handler.ts index f66bdbe1a..e6401f508 100644 --- a/backend/src/api/websocket-handler.ts +++ b/backend/src/api/websocket-handler.ts @@ -86,7 +86,7 @@ class WebsocketHandler { 'vBytesPerSecond': memPool.getVBytesPerSecond(), 'lastDifficultyAdjustment': blocks.getLastDifficultyAdjustmentTime(), 'blocks': _blocks, - 'conversions': fiatConversion.getTickers()['BTCUSD'], + 'conversions': fiatConversion.getConversionRates(), 'mempool-blocks': mempoolBlocks.getMempoolBlocks(), 'transactions': memPool.getLatestTransactions(), 'git-commit': backendInfo.gitCommitHash,