From 0b4b57ca5d8747047e5171d1a5df37a774668a0e Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Fri, 27 May 2022 10:31:52 -0500 Subject: [PATCH 1/2] Configurable exclusion property for provider currency. --- .../bisq/price/spot/ExchangeRateProvider.java | 18 +++++++++++++++++- .../src/main/resources/application.properties | 1 + .../price/spot/ExchangeRateServiceTest.java | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pricenode/src/main/java/bisq/price/spot/ExchangeRateProvider.java b/pricenode/src/main/java/bisq/price/spot/ExchangeRateProvider.java index 67f9b60d9b7..dae93a2c0ff 100644 --- a/pricenode/src/main/java/bisq/price/spot/ExchangeRateProvider.java +++ b/pricenode/src/main/java/bisq/price/spot/ExchangeRateProvider.java @@ -64,6 +64,7 @@ public abstract class ExchangeRateProvider extends PriceProvider<Set<ExchangeRat private static Set<String> SUPPORTED_CRYPTO_CURRENCIES = new HashSet<>(); private static Set<String> SUPPORTED_FIAT_CURRENCIES = new HashSet<>(); + private Set<String> providerExclusionList = new HashSet<>(); private final String name; private final String prefix; private final Environment env; @@ -73,6 +74,18 @@ public ExchangeRateProvider(Environment env, String name, String prefix, Duratio this.name = name; this.prefix = prefix; this.env = env; + List<String> excludedByProvider = + Arrays.asList(env.getProperty("bisq.price.fiatcurrency.excludedByProvider", "") + .toUpperCase().trim().split("\\s*,\\s*")); + for (String s: excludedByProvider) { + String[] splits = s.split(":"); + if (splits.length == 2 && splits[0].equalsIgnoreCase(name) && CurrencyUtil.isFiatCurrency(splits[1])) { + providerExclusionList.add(splits[1]); + } + } + if (providerExclusionList.size() > 0) { + log.info("{} specific exclusion list={}", name, providerExclusionList.toString()); + } } public Set<String> getSupportedFiatCurrencies() { @@ -91,7 +104,10 @@ public Set<String> getSupportedFiatCurrencies() { log.info("fiat currencies excluded: {}", validatedExclusionList); log.info("fiat currencies supported: {}", SUPPORTED_FIAT_CURRENCIES.size()); } - return SUPPORTED_FIAT_CURRENCIES; + // filter out any provider specific ccy exclusions + return SUPPORTED_FIAT_CURRENCIES.stream() + .filter(ccy -> !providerExclusionList.contains(ccy.toUpperCase())) + .collect(Collectors.toSet()); } public Set<String> getSupportedCryptoCurrencies() { diff --git a/pricenode/src/main/resources/application.properties b/pricenode/src/main/resources/application.properties index bba1a31c88f..276bad51d90 100644 --- a/pricenode/src/main/resources/application.properties +++ b/pricenode/src/main/resources/application.properties @@ -8,4 +8,5 @@ bisq.price.mining.providers.mempoolHostname.3=mempool.ninja bisq.price.mining.providers.mempoolHostname.4=mempool.bisq.services # bisq.price.mining.providers.mempoolHostname.5=someHostOrIP bisq.price.fiatcurrency.excluded=LBP,ARS +bisq.price.fiatcurrency.excludedByProvider=HUOBI:BRL bisq.price.cryptocurrency.excluded= diff --git a/pricenode/src/test/java/bisq/price/spot/ExchangeRateServiceTest.java b/pricenode/src/test/java/bisq/price/spot/ExchangeRateServiceTest.java index 04a1658cd93..642f3fe8566 100644 --- a/pricenode/src/test/java/bisq/price/spot/ExchangeRateServiceTest.java +++ b/pricenode/src/test/java/bisq/price/spot/ExchangeRateServiceTest.java @@ -166,8 +166,10 @@ public void getAllMarketPrices_withMultipleProviders_overlappingCurrencyCodes() @Test public void getAllMarketPrices_withMultipleProviders_excludedCurrencyCodes() { String excludedCcyString = "LBP,USD,EUR"; + String providerExcludedCcyString = "HUOBI:BRL,BINANCE:GBP,BINANCE:SEK"; Environment mockedEnvironment = mock(Environment.class); when(mockedEnvironment.getProperty(eq("bisq.price.fiatcurrency.excluded"), anyString())).thenReturn(excludedCcyString); + when(mockedEnvironment.getProperty(eq("bisq.price.fiatcurrency.excludedByProvider"), anyString())).thenReturn(providerExcludedCcyString); class MockedExchangeRateProvider extends ExchangeRateProvider { MockedExchangeRateProvider() { From 031095896712ecff3a13b6af62fe01da7179b2fc Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Sat, 28 May 2022 16:51:59 -0500 Subject: [PATCH 2/2] Remove Huobi provider. --- .../java/bisq/price/spot/providers/Huobi.java | 46 ------------------- .../bisq/price/spot/providers/HuobiTest.java | 36 --------------- 2 files changed, 82 deletions(-) delete mode 100644 pricenode/src/main/java/bisq/price/spot/providers/Huobi.java delete mode 100644 pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java diff --git a/pricenode/src/main/java/bisq/price/spot/providers/Huobi.java b/pricenode/src/main/java/bisq/price/spot/providers/Huobi.java deleted file mode 100644 index cd2f429628a..00000000000 --- a/pricenode/src/main/java/bisq/price/spot/providers/Huobi.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see <http://www.gnu.org/licenses/>. - */ - -package bisq.price.spot.providers; - -import bisq.price.spot.ExchangeRate; -import bisq.price.spot.ExchangeRateProvider; - -import org.knowm.xchange.huobi.HuobiExchange; - -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -import java.time.Duration; - -import java.util.Set; - -@Component -class Huobi extends ExchangeRateProvider { - - public Huobi(Environment env) { - super(env, "HUOBI", "huobi", Duration.ofMinutes(1)); - } - - @Override - public Set<ExchangeRate> doGet() { - // Supported fiat: - - // Supported alts: BTM, DASH, DCR, DOGE, ETC, ETH, FAIR, LTC, XMR, XZC, ZEC, ZEN - return doGet(HuobiExchange.class); - } - -} diff --git a/pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java b/pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java deleted file mode 100644 index da5062a8073..00000000000 --- a/pricenode/src/test/java/bisq/price/spot/providers/HuobiTest.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see <http://www.gnu.org/licenses/>. - */ - -package bisq.price.spot.providers; - -import bisq.price.AbstractExchangeRateProviderTest; - -import org.springframework.core.env.StandardEnvironment; - -import lombok.extern.slf4j.Slf4j; - -import org.junit.jupiter.api.Test; - -@Slf4j -public class HuobiTest extends AbstractExchangeRateProviderTest { - - @Test - public void doGet_successfulCall() { - doGet_successfulCall(new Huobi(new StandardEnvironment())); - } - -}