PriceNode: exclude currencies via config

This commit is contained in:
jmacxx 2021-06-22 14:40:09 -05:00
parent 6ab5ceca1a
commit 1c05e5d990
No known key found for this signature in database
GPG Key ID: 155297BABFE94A1B
43 changed files with 251 additions and 83 deletions

View File

@ -536,6 +536,7 @@ configure(project(':pricenode')) {
testRuntime("org.junit.jupiter:junit-jupiter-engine:$jupiterVersion")
testCompileOnly "org.projectlombok:lombok:$lombokVersion"
testAnnotationProcessor "org.projectlombok:lombok:$lombokVersion"
testCompile "org.mockito:mockito-core:$mockitoVersion"
}
test {

View File

@ -33,11 +33,14 @@ import org.knowm.xchange.service.marketdata.MarketDataService;
import org.knowm.xchange.service.marketdata.params.CurrencyPairsParam;
import org.knowm.xchange.service.marketdata.params.Params;
import org.springframework.core.env.Environment;
import java.time.Duration;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
@ -59,21 +62,55 @@ import java.util.stream.Stream;
*/
public abstract class ExchangeRateProvider extends PriceProvider<Set<ExchangeRate>> {
public static final Set<String> SUPPORTED_CRYPTO_CURRENCIES = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
.map(TradeCurrency::getCode)
.collect(Collectors.toSet());
public static final Set<String> SUPPORTED_FIAT_CURRENCIES = CurrencyUtil.getAllSortedFiatCurrencies().stream()
.map(TradeCurrency::getCode)
.collect(Collectors.toSet());
private static Set<String> SUPPORTED_CRYPTO_CURRENCIES = new HashSet<>();
private static Set<String> SUPPORTED_FIAT_CURRENCIES = new HashSet<>();
private final String name;
private final String prefix;
private final Environment env;
public ExchangeRateProvider(String name, String prefix, Duration refreshInterval) {
public ExchangeRateProvider(Environment env, String name, String prefix, Duration refreshInterval) {
super(refreshInterval);
this.name = name;
this.prefix = prefix;
this.env = env;
}
public Set<String> getSupportedFiatCurrencies() {
if (SUPPORTED_FIAT_CURRENCIES.size() == 0) { // one-time initialization
List<String> excludedFiatCurrencies =
Arrays.asList(env.getProperty("bisq.price.fiatcurrency.excluded", "")
.toUpperCase().trim().split("\\s*,\\s*"));
String validatedExclusionList = excludedFiatCurrencies.stream()
.filter(ccy -> ccy.length() > 0)
.filter(CurrencyUtil::isFiatCurrency)
.collect(Collectors.toList()).toString();
SUPPORTED_FIAT_CURRENCIES = CurrencyUtil.getAllSortedFiatCurrencies().stream()
.map(TradeCurrency::getCode)
.filter(ccy -> !validatedExclusionList.contains(ccy.toUpperCase()))
.collect(Collectors.toSet());
log.info("fiat currencies excluded: {}", validatedExclusionList);
log.info("fiat currencies supported: {}", SUPPORTED_FIAT_CURRENCIES.size());
}
return SUPPORTED_FIAT_CURRENCIES;
}
public Set<String> getSupportedCryptoCurrencies() {
if (SUPPORTED_CRYPTO_CURRENCIES.size() == 0) { // one-time initialization
List<String> excludedCryptoCurrencies =
Arrays.asList(env.getProperty("bisq.price.cryptocurrency.excluded", "")
.toUpperCase().trim().split("\\s*,\\s*"));
String validatedExclusionList = excludedCryptoCurrencies.stream()
.filter(ccy -> ccy.length() > 0)
.filter(CurrencyUtil::isCryptoCurrency)
.collect(Collectors.toList()).toString();
SUPPORTED_CRYPTO_CURRENCIES = CurrencyUtil.getAllSortedCryptoCurrencies().stream()
.map(TradeCurrency::getCode)
.filter(ccy -> !validatedExclusionList.contains(ccy.toUpperCase()))
.collect(Collectors.toSet());
log.info("crypto currencies excluded: {}", validatedExclusionList);
log.info("crypto currencies supported: {}", SUPPORTED_CRYPTO_CURRENCIES.size());
}
return SUPPORTED_CRYPTO_CURRENCIES;
}
public String getName() {
@ -119,13 +156,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 -> SUPPORTED_FIAT_CURRENCIES.contains(cp.counter.getCurrencyCode()))
.filter(cp -> getSupportedFiatCurrencies().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 -> SUPPORTED_CRYPTO_CURRENCIES.contains(cp.base.getCurrencyCode()))
.filter(cp -> getSupportedCryptoCurrencies().contains(cp.base.getCurrencyCode()))
.collect(Collectors.toList());
// Retrieve in bulk all tickers offered by the exchange

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.btcmarkets.BTCMarketsExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class BTCMarkets extends ExchangeRateProvider {
public BTCMarkets() {
super("BTCMARKETS", "btcmarkets", Duration.ofMinutes(1));
public BTCMarkets(Environment env) {
super(env, "BTCMARKETS", "btcmarkets", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.binance.BinanceExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Binance extends ExchangeRateProvider {
public Binance() {
super("BINANCE", "binance", Duration.ofMinutes(1));
public Binance(Environment env) {
super(env, "BINANCE", "binance", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.bitbay.BitbayExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Bitbay extends ExchangeRateProvider {
public Bitbay() {
super("BITBAY", "bitbay", Duration.ofMinutes(1));
public Bitbay(Environment env) {
super(env, "BITBAY", "bitbay", Duration.ofMinutes(1));
}
@Override

View File

@ -20,6 +20,7 @@ package bisq.price.spot.providers;
import bisq.price.spot.ExchangeRate;
import bisq.price.spot.ExchangeRateProvider;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -34,12 +35,12 @@ import java.util.Set;
@Component
class BitcoinAverage extends ExchangeRateProvider {
public BitcoinAverage() {
public BitcoinAverage(Environment env) {
// Simulate a deactivated BitcoinAverage provider
// We still need the class to exist and be registered as a provider though,
// because the returned data structure must contain the "btcAverageTs" key
// for backward compatibility with Bisq clients which hardcode that key
super("BA", "btcAverage", Duration.ofMinutes(100));
super(env, "BA", "btcAverage", Duration.ofMinutes(100));
}
/**

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.bitfinex.BitfinexExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Bitfinex extends ExchangeRateProvider {
public Bitfinex() {
super("BITFINEX", "bitfinex", Duration.ofMinutes(1));
public Bitfinex(Environment env) {
super(env, "BITFINEX", "bitfinex", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.bitflyer.BitflyerExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Bitflyer extends ExchangeRateProvider {
public Bitflyer() {
super("BITFLYER", "bitflyer", Duration.ofMinutes(1));
public Bitflyer(Environment env) {
super(env, "BITFLYER", "bitflyer", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.bitstamp.BitstampExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Bitstamp extends ExchangeRateProvider {
public Bitstamp() {
super("BITSTAMP", "bitstamp", Duration.ofMinutes(1));
public Bitstamp(Environment env) {
super(env, "BITSTAMP", "bitstamp", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import bisq.price.util.coingecko.CoinGeckoMarketData;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.env.Environment;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@ -44,8 +45,8 @@ class CoinGecko extends ExchangeRateProvider {
private final RestTemplate restTemplate = new RestTemplate();
public CoinGecko() {
super("COINGECKO", "coingecko", Duration.ofMinutes(1));
public CoinGecko(Environment env) {
super(env, "COINGECKO", "coingecko", Duration.ofMinutes(1));
}
@Override
@ -56,8 +57,8 @@ class CoinGecko extends ExchangeRateProvider {
Set<ExchangeRate> result = new HashSet<ExchangeRate>();
Predicate<Map.Entry> isDesiredFiatPair = t -> SUPPORTED_FIAT_CURRENCIES.contains(t.getKey());
Predicate<Map.Entry> isDesiredCryptoPair = t -> SUPPORTED_CRYPTO_CURRENCIES.contains(t.getKey());
Predicate<Map.Entry> isDesiredFiatPair = t -> getSupportedFiatCurrencies().contains(t.getKey());
Predicate<Map.Entry> isDesiredCryptoPair = t -> getSupportedCryptoCurrencies().contains(t.getKey());
getMarketData().getRates().entrySet().stream()
.filter(isDesiredFiatPair.or(isDesiredCryptoPair))
@ -65,7 +66,7 @@ class CoinGecko extends ExchangeRateProvider {
.forEach((key, ticker) -> {
boolean useInverseRate = false;
if (SUPPORTED_CRYPTO_CURRENCIES.contains(key)) {
if (getSupportedCryptoCurrencies().contains(key)) {
// Use inverse rate for alts, because the API returns the
// conversion rate in the opposite direction than what we need
// API returns the BTC/Alt rate, we need the Alt/BTC rate

View File

@ -20,6 +20,7 @@ package bisq.price.spot.providers;
import bisq.price.spot.ExchangeRate;
import bisq.price.spot.ExchangeRateProvider;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -33,8 +34,8 @@ import java.util.Set;
@Component
class CoinMarketCap extends ExchangeRateProvider {
public CoinMarketCap() {
super("CMC", "coinmarketcap", Duration.ofMinutes(5)); // large data structure, so don't request it too often
public CoinMarketCap(Environment env) {
super(env, "CMC", "coinmarketcap", Duration.ofMinutes(5)); // large data structure, so don't request it too often
}
/**

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.coinone.CoinoneExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Coinone extends ExchangeRateProvider {
public Coinone() {
super("COINONE", "coinone", Duration.ofMinutes(1));
public Coinone(Environment env) {
super(env, "COINONE", "coinone", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import bisq.price.util.coinpaprika.CoinpaprikaMarketData;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.env.Environment;
import org.springframework.http.RequestEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
@ -55,8 +56,8 @@ class Coinpaprika extends ExchangeRateProvider {
"INR, MYR, NOK, PKR, SEK, TWD, ZAR, VND, BOB, COP, PEN, ARS, ISK")
.replace(" ", ""); // Strip any spaces
public Coinpaprika() {
super("COINPAPRIKA", "coinpaprika", Duration.ofMinutes(1));
public Coinpaprika(Environment env) {
super(env, "COINPAPRIKA", "coinpaprika", Duration.ofMinutes(1));
}
@Override
@ -67,7 +68,7 @@ class Coinpaprika extends ExchangeRateProvider {
Set<ExchangeRate> result = new HashSet<ExchangeRate>();
Predicate<Map.Entry> isDesiredFiatPair = t -> SUPPORTED_FIAT_CURRENCIES.contains(t.getKey());
Predicate<Map.Entry> isDesiredFiatPair = t -> getSupportedFiatCurrencies().contains(t.getKey());
getMarketData().getQuotes().entrySet().stream()
.filter(isDesiredFiatPair)

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.exmo.ExmoExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,9 +32,9 @@ import java.util.Set;
@Component
class Exmo extends ExchangeRateProvider {
public Exmo() {
public Exmo(Environment env) {
// API rate limit = 10 calls / second from the same IP ( see https://exmo.com/en/api )
super("EXMO", "exmo", Duration.ofMinutes(1));
super(env, "EXMO", "exmo", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ 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;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Huobi extends ExchangeRateProvider {
public Huobi() {
super("HUOBI", "huobi", Duration.ofMinutes(1));
public Huobi(Environment env) {
super(env, "HUOBI", "huobi", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.independentreserve.IndependentReserveExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class IndependentReserve extends ExchangeRateProvider {
public IndependentReserve() {
super("IndependentReserve", "independentreserve", Duration.ofMinutes(1));
public IndependentReserve(Environment env) {
super(env, "IndependentReserve", "independentreserve", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.kraken.KrakenExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Kraken extends ExchangeRateProvider {
public Kraken() {
super("KRAKEN", "kraken", Duration.ofMinutes(1));
public Kraken(Environment env) {
super(env, "KRAKEN", "kraken", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.luno.LunoExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Luno extends ExchangeRateProvider {
public Luno() {
super("LUNO", "luno", Duration.ofMinutes(1));
public Luno(Environment env) {
super(env, "LUNO", "luno", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.mercadobitcoin.MercadoBitcoinExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class MercadoBitcoin extends ExchangeRateProvider {
public MercadoBitcoin() {
super("MercadoBitcoin", "mercadobitcoin", Duration.ofMinutes(1));
public MercadoBitcoin(Environment env) {
super(env, "MercadoBitcoin", "mercadobitcoin", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.paribu.ParibuExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Paribu extends ExchangeRateProvider {
public Paribu() {
super("PARIBU", "paribu", Duration.ofMinutes(1));
public Paribu(Environment env) {
super(env, "PARIBU", "paribu", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.poloniex.PoloniexExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Poloniex extends ExchangeRateProvider {
public Poloniex() {
super("POLO", "poloniex", Duration.ofMinutes(1));
public Poloniex(Environment env) {
super(env, "POLO", "poloniex", Duration.ofMinutes(1));
}
@Override

View File

@ -22,6 +22,7 @@ import bisq.price.spot.ExchangeRateProvider;
import org.knowm.xchange.quoine.QuoineExchange;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
import java.time.Duration;
@ -31,8 +32,8 @@ import java.util.Set;
@Component
class Quoine extends ExchangeRateProvider {
public Quoine() {
super("QUOINE", "quoine", Duration.ofMinutes(1));
public Quoine(Environment env) {
super(env, "QUOINE", "quoine", Duration.ofMinutes(1));
}
@Override

View File

@ -7,3 +7,5 @@ bisq.price.mining.providers.mempoolHostname.2=mempool.emzy.de
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.cryptocurrency.excluded=

View File

@ -30,7 +30,7 @@ public abstract class AbstractExchangeRateProviderTest {
// Sanity checks
assertTrue(retrievedExchangeRates.size() > 0);
checkProviderCurrencyPairs(retrievedExchangeRates);
checkProviderCurrencyPairs(exchangeProvider, retrievedExchangeRates);
}
/**
@ -40,24 +40,24 @@ public abstract class AbstractExchangeRateProviderTest {
*
* @param retrievedExchangeRates Exchange rates retrieved from the provider
*/
private void checkProviderCurrencyPairs(Set<ExchangeRate> retrievedExchangeRates) {
private void checkProviderCurrencyPairs(ExchangeRateProvider exchangeProvider, Set<ExchangeRate> retrievedExchangeRates) {
Set<String> retrievedRatesCurrencies = retrievedExchangeRates.stream()
.map(ExchangeRate::getCurrency)
.collect(Collectors.toSet());
Set<String> supportedFiatCurrenciesRetrieved = ExchangeRateProvider.SUPPORTED_FIAT_CURRENCIES.stream()
Set<String> supportedFiatCurrenciesRetrieved = exchangeProvider.getSupportedFiatCurrencies().stream()
.filter(f -> retrievedRatesCurrencies.contains(f))
.collect(Collectors.toCollection(TreeSet::new));
log.info("Retrieved rates for supported fiat currencies: " + supportedFiatCurrenciesRetrieved);
Set<String> supportedCryptoCurrenciesRetrieved = ExchangeRateProvider.SUPPORTED_CRYPTO_CURRENCIES.stream()
Set<String> supportedCryptoCurrenciesRetrieved = exchangeProvider.getSupportedCryptoCurrencies().stream()
.filter(c -> retrievedRatesCurrencies.contains(c))
.collect(Collectors.toCollection(TreeSet::new));
log.info("Retrieved rates for supported altcoins: " + supportedCryptoCurrenciesRetrieved);
Set<String> supportedCurrencies = Sets.union(
ExchangeRateProvider.SUPPORTED_CRYPTO_CURRENCIES,
ExchangeRateProvider.SUPPORTED_FIAT_CURRENCIES);
exchangeProvider.getSupportedCryptoCurrencies(),
exchangeProvider.getSupportedFiatCurrencies());
Set unsupportedCurrencies = Sets.difference(retrievedRatesCurrencies, supportedCurrencies);
assertTrue("Retrieved exchange rates contain unsupported currencies: " + unsupportedCurrencies,

View File

@ -17,6 +17,11 @@
package bisq.price.spot;
import bisq.core.locale.CurrencyUtil;
import org.springframework.core.env.Environment;
import org.springframework.core.env.StandardEnvironment;
import com.google.common.collect.Sets;
import org.apache.commons.lang3.RandomStringUtils;
@ -46,10 +51,9 @@ import org.junit.jupiter.api.Test;
import static java.lang.Thread.sleep;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
public class ExchangeRateServiceTest {
@ -156,6 +160,72 @@ public class ExchangeRateServiceTest {
assertNotEquals(0L, retrievedData.get(dummyProvider2.getPrefix() + "Ts"));
}
/**
* Tests the scenario when currencies are excluded from the PriceNode feed via configuration settings
*/
@Test
public void getAllMarketPrices_withMultipleProviders_excludedCurrencyCodes() {
String excludedCcyString = "LBP,USD,EUR";
Environment mockedEnvironment = mock(Environment.class);
when(mockedEnvironment.getProperty(eq("bisq.price.fiatcurrency.excluded"), anyString())).thenReturn(excludedCcyString);
class MockedExchangeRateProvider extends ExchangeRateProvider {
MockedExchangeRateProvider() {
super(mockedEnvironment, "ExchangeName", "EXCH", Duration.ofDays(1));
}
@Override
public boolean isRunning() {
return true;
}
@Override
public Set<ExchangeRate> doGet() {
HashSet<ExchangeRate> exchangeRates = new HashSet<>();
// Simulate rates for all the supported ccys
for (String rateCurrencyCode : getSupportedFiatCurrencies()) {
exchangeRates.add(new ExchangeRate(
rateCurrencyCode,
RandomUtils.nextDouble(1, 1000), // random price
System.currentTimeMillis(),
getName())); // ExchangeRateProvider name
}
return exchangeRates;
}
}
Logger exchangeRateProviderLogger;
String LIST_APPENDER_NAME2 = "testListAppender2";
exchangeRateProviderLogger = (Logger) LoggerFactory.getLogger(MockedExchangeRateProvider.class);
ListAppender<ILoggingEvent> listAppender2 = new ListAppender<>();
listAppender2.setName(LIST_APPENDER_NAME2);
listAppender2.start();
exchangeRateProviderLogger.addAppender(listAppender2);
// we request rates for all currencies, and check that:
// (a) the provider supplies more currency rates than the number of currencies we are trying to exclude (sanity test),
// (b) the number of missing currency rates equals the number of currencies we told PriceNode to exclude,
// (c) none of the rates supplied are for an excluded currency.
Set<String> excludedFiatCurrencies = new HashSet<>(asList(excludedCcyString.split(",")));
MockedExchangeRateProvider mockedExchangeRateProvider = new MockedExchangeRateProvider();
Set<ExchangeRate> exchangeRates = mockedExchangeRateProvider.doGet();
assertTrue(exchangeRates.size() > excludedFiatCurrencies.size());
int numSortedFiatCurrencies = CurrencyUtil.getAllSortedFiatCurrencies().size();
int numCurrenciesFromProvider = mockedExchangeRateProvider.getSupportedFiatCurrencies().size();
int missingCurrencyCount = numSortedFiatCurrencies - numCurrenciesFromProvider;
assertEquals(missingCurrencyCount, excludedFiatCurrencies.size());
for (ExchangeRate exchangeRate : exchangeRates) {
assertFalse(excludedCcyString.contains(exchangeRate.getCurrency()));
}
List<ILoggingEvent> logsList = ((ListAppender) exchangeRateProviderLogger.getAppender(LIST_APPENDER_NAME2)).list;
assertEquals(3, logsList.size());
assertEquals(Level.INFO, logsList.get(1).getLevel());
assertTrue(logsList.get(0).getFormattedMessage().endsWith("will refresh every PT24H"));
assertTrue(logsList.get(1).getFormattedMessage().endsWith("fiat currencies excluded: [LBP, USD, EUR]"));
assertTrue(logsList.get(2).getFormattedMessage().endsWith("fiat currencies supported: " + numCurrenciesFromProvider));
}
/**
* Performs generic sanity checks on the response format and contents.
*
@ -259,6 +329,7 @@ public class ExchangeRateServiceTest {
*/
private ExchangeRateProvider buildDummyExchangeRateProvider(int numberOfRatesAvailable) {
ExchangeRateProvider dummyProvider = new ExchangeRateProvider(
new StandardEnvironment(),
"ExchangeName-" + getRandomAlphaNumericString(5),
"EXCH-" + getRandomAlphaNumericString(3),
Duration.ofDays(1)) {
@ -298,6 +369,7 @@ public class ExchangeRateServiceTest {
private ExchangeRateProvider buildDummyExchangeRateProvider(Set<String> rateCurrencyCodes) {
ExchangeRateProvider dummyProvider = new ExchangeRateProvider(
new StandardEnvironment(),
"ExchangeName-" + getRandomAlphaNumericString(5),
"EXCH-" + getRandomAlphaNumericString(3),
Duration.ofDays(1)) {

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class BTCMarketsTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new BTCMarkets());
doGet_successfulCall(new BTCMarkets(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class BinanceTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Binance());
doGet_successfulCall(new Binance(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class BitbayTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Bitbay());
doGet_successfulCall(new Bitbay(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class BitfinexTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Bitfinex());
doGet_successfulCall(new Bitfinex(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class BitflyerTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Bitflyer());
doGet_successfulCall(new Bitflyer(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class BitstampTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Bitstamp());
doGet_successfulCall(new Bitstamp(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class CoinGeckoTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new CoinGecko());
doGet_successfulCall(new CoinGecko(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class CoinoneTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Coinone());
doGet_successfulCall(new Coinone(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class CoinpaprikaTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Coinpaprika());
doGet_successfulCall(new Coinpaprika(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class ExmoTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Exmo());
doGet_successfulCall(new Exmo(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class HuobiTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Huobi());
doGet_successfulCall(new Huobi(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class IndependentReserveTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new IndependentReserve());
doGet_successfulCall(new IndependentReserve(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class KrakenTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Kraken());
doGet_successfulCall(new Kraken(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class LunoTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Luno());
doGet_successfulCall(new Luno(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class MercadoBitcoinTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new MercadoBitcoin());
doGet_successfulCall(new MercadoBitcoin(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class ParibuTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Paribu());
doGet_successfulCall(new Paribu(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class PoloniexTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Poloniex());
doGet_successfulCall(new Poloniex(new StandardEnvironment()));
}
}

View File

@ -19,6 +19,8 @@ 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;
@ -28,7 +30,7 @@ public class QuoineTest extends AbstractExchangeRateProviderTest {
@Test
public void doGet_successfulCall() {
doGet_successfulCall(new Quoine());
doGet_successfulCall(new Quoine(new StandardEnvironment()));
}
}