Reuse sets of supported currencies

Reuse sets of supported currencies between pricenode classes and tests.
This commit is contained in:
cd2357 2020-07-13 20:39:24 +02:00
parent 329188db1d
commit 7fc5191798
No known key found for this signature in database
GPG Key ID: F26C56748514D0D3
2 changed files with 9 additions and 15 deletions

View File

@ -56,11 +56,11 @@ import java.util.stream.Stream;
*/
public abstract class ExchangeRateProvider extends PriceProvider<Set<ExchangeRate>> {
private static final Set<String> supportedCryptoCurrencies = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
public static final Set<String> SUPPORTED_CRYPTO_CURRENCIES = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
.map(TradeCurrency::getCode)
.collect(Collectors.toSet());
private static final Set<String> supportedFiatCurrencies = CurrencyUtil.getAllSortedFiatCurrencies().stream()
public static final Set<String> SUPPORTED_FIAT_CURRENCIES = CurrencyUtil.getAllSortedFiatCurrencies().stream()
.map(TradeCurrency::getCode)
.collect(Collectors.toSet());
@ -116,13 +116,13 @@ public abstract class ExchangeRateProvider extends PriceProvider<Set<ExchangeRat
// Find the desired fiat pairs (pair format is BTC-FIAT)
List<CurrencyPair> desiredFiatPairs = allCurrencyPairsOnExchange.stream()
.filter(cp -> cp.base.equals(Currency.BTC))
.filter(cp -> supportedFiatCurrencies.contains(cp.counter.getCurrencyCode()))
.filter(cp -> SUPPORTED_FIAT_CURRENCIES.contains(cp.counter.getCurrencyCode()))
.collect(Collectors.toList());
// Find the desired altcoin pairs (pair format is ALT-BTC)
List<CurrencyPair> desiredCryptoPairs = allCurrencyPairsOnExchange.stream()
.filter(cp -> cp.counter.equals(Currency.BTC))
.filter(cp -> supportedCryptoCurrencies.contains(cp.base.getCurrencyCode()))
.filter(cp -> SUPPORTED_CRYPTO_CURRENCIES.contains(cp.base.getCurrencyCode()))
.collect(Collectors.toList());
// Retrieve in bulk all tickers offered by the exchange

View File

@ -48,25 +48,19 @@ public abstract class AbstractExchangeRateProviderTest {
.map(ExchangeRate::getCurrency)
.collect(Collectors.toSet());
Set<String> supportedCryptoCurrencies = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
.map(TradeCurrency::getCode)
.collect(Collectors.toSet());
Set<String> supportedFiatCurrencies = CurrencyUtil.getAllSortedFiatCurrencies().stream()
.map(TradeCurrency::getCode)
.collect(Collectors.toSet());
Set<String> supportedFiatCurrenciesRetrieved = supportedFiatCurrencies.stream()
Set<String> supportedFiatCurrenciesRetrieved = ExchangeRateProvider.SUPPORTED_FIAT_CURRENCIES.stream()
.filter(f -> retrievedRatesCurrencies.contains(f))
.collect(Collectors.toCollection(TreeSet::new));
log.info("Retrieved rates for supported fiat currencies: " + supportedFiatCurrenciesRetrieved);
Set<String> supportedCryptoCurrenciesRetrieved = supportedCryptoCurrencies.stream()
Set<String> supportedCryptoCurrenciesRetrieved = ExchangeRateProvider.SUPPORTED_CRYPTO_CURRENCIES.stream()
.filter(c -> retrievedRatesCurrencies.contains(c))
.collect(Collectors.toCollection(TreeSet::new));
log.info("Retrieved rates for supported altcoins: " + supportedCryptoCurrenciesRetrieved);
Set<String> supportedCurrencies = Sets.union(supportedCryptoCurrencies, supportedFiatCurrencies);
Set<String> supportedCurrencies = Sets.union(
ExchangeRateProvider.SUPPORTED_CRYPTO_CURRENCIES,
ExchangeRateProvider.SUPPORTED_FIAT_CURRENCIES);
Set unsupportedCurrencies = Sets.difference(retrievedRatesCurrencies, supportedCurrencies);
assertTrue("Retrieved exchange rates contain unsupported currencies: " + unsupportedCurrencies,