From d613aec395375a1d80cfd38ee5fd9af29f9164bf Mon Sep 17 00:00:00 2001 From: wiz Date: Mon, 23 Nov 2020 22:46:14 +0900 Subject: [PATCH] Modify /bisq/api/v1/markets/markets to only return active markets As per https://github.com/bisq-network/bisq/issues/4826 and https://github.com/bisq-network/bisq/pull/4831 --- backend/src/api/bisq/markets-api.ts | 16 ++++++++++++---- backend/src/api/bisq/markets.ts | 6 +++++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/backend/src/api/bisq/markets-api.ts b/backend/src/api/bisq/markets-api.ts index 559a94faf..acc8093c7 100644 --- a/backend/src/api/bisq/markets-api.ts +++ b/backend/src/api/bisq/markets-api.ts @@ -6,6 +6,8 @@ import * as datetime from 'locutus/php/datetime'; class BisqMarketsApi { private cryptoCurrencyData: Currency[] = []; private fiatCurrencyData: Currency[] = []; + private activeCryptoCurrencyData: Currency[] = []; + private activeFiatCurrencyData: Currency[] = []; private offersData: OffersData[] = []; private tradesData: TradesData[] = []; private fiatCurrenciesIndexed: { [code: string]: true } = {}; @@ -32,9 +34,11 @@ class BisqMarketsApi { }); } - setCurrencyData(cryptoCurrency: Currency[], fiatCurrency: Currency[]) { + setCurrencyData(cryptoCurrency: Currency[], fiatCurrency: Currency[], activeCryptoCurrency: Currency[], activeFiatCurrency: Currency[]) { this.cryptoCurrencyData = cryptoCurrency, - this.fiatCurrencyData = fiatCurrency; + this.fiatCurrencyData = fiatCurrency, + this.activeCryptoCurrencyData = activeCryptoCurrency, + this.activeFiatCurrencyData = activeFiatCurrency; this.fiatCurrenciesIndexed = {}; this.allCurrenciesIndexed = {}; @@ -56,7 +60,7 @@ class BisqMarketsApi { } getCurrencies( - type: 'crypto' | 'fiat' | 'all' = 'all', + type: 'crypto' | 'fiat' | 'active' | 'all' = 'all', ): Currencies { let currencies: Currency[]; @@ -67,6 +71,9 @@ class BisqMarketsApi { case 'crypto': currencies = this.cryptoCurrencyData; break; + case 'active': + currencies = this.activeCryptoCurrencyData.concat(this.activeFiatCurrencyData); + break; case 'all': default: currencies = this.cryptoCurrencyData.concat(this.fiatCurrencyData); @@ -136,9 +143,10 @@ class BisqMarketsApi { getMarkets(): Markets { const allCurrencies = this.getCurrencies(); + const activeCurrencies = this.getCurrencies('active'); const markets = {}; - for (const currency of Object.keys(allCurrencies)) { + for (const currency of Object.keys(activeCurrencies)) { if (allCurrencies[currency].code === 'BTC') { continue; } diff --git a/backend/src/api/bisq/markets.ts b/backend/src/api/bisq/markets.ts index a209a055c..1d6169366 100644 --- a/backend/src/api/bisq/markets.ts +++ b/backend/src/api/bisq/markets.ts @@ -8,6 +8,8 @@ class Bisq { private static FOLDER_WATCH_CHANGE_DETECTION_DEBOUNCE = 4000; private static MARKET_JSON_PATH = config.BISQ_MARKETS.DATA_PATH; private static MARKET_JSON_FILE_PATHS = { + activeCryptoCurrency: '/active_crypto_currency_list.json', + activeFiatCurrency: '/active_fiat_currency_list.json', cryptoCurrency: '/crypto_currency_list.json', fiatCurrency: '/fiat_currency_list.json', offers: '/offers_statistics.json', @@ -66,8 +68,10 @@ class Bisq { if (cryptoMtime > this.cryptoCurrencyLastMtime || fiatMtime > this.fiatCurrencyLastMtime) { const cryptoCurrencyData = await this.loadData(Bisq.MARKET_JSON_FILE_PATHS.cryptoCurrency); const fiatCurrencyData = await this.loadData(Bisq.MARKET_JSON_FILE_PATHS.fiatCurrency); + const activeCryptoCurrencyData = await this.loadData(Bisq.MARKET_JSON_FILE_PATHS.activeCryptoCurrency); + const activeFiatCurrencyData = await this.loadData(Bisq.MARKET_JSON_FILE_PATHS.activeFiatCurrency); logger.debug('Updating Bisq Market Currency Data'); - bisqMarket.setCurrencyData(cryptoCurrencyData, fiatCurrencyData); + bisqMarket.setCurrencyData(cryptoCurrencyData, fiatCurrencyData, activeCryptoCurrencyData, activeFiatCurrencyData); if (cryptoMtime > this.cryptoCurrencyLastMtime) { this.cryptoCurrencyLastMtime = cryptoMtime; }