Skip to content

Commit

Permalink
Configurable exclusion property for provider currency.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmacxx committed May 27, 2022
1 parent 0ced87c commit 0b4b57c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
1 change: 1 addition & 0 deletions pricenode/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0b4b57c

Please sign in to comment.