diff --git a/core/src/main/java/bisq/core/api/CorePriceService.java b/core/src/main/java/bisq/core/api/CorePriceService.java index 4553689e98..c572409b46 100644 --- a/core/src/main/java/bisq/core/api/CorePriceService.java +++ b/core/src/main/java/bisq/core/api/CorePriceService.java @@ -27,7 +27,6 @@ import java.util.function.Consumer; import lombok.extern.slf4j.Slf4j; import static bisq.common.util.MathUtils.roundDouble; -import static bisq.core.locale.CurrencyUtil.isFiatCurrency; import static java.lang.String.format; @Singleton @@ -44,14 +43,11 @@ class CorePriceService { public void getMarketPrice(String currencyCode, Consumer resultHandler) { String upperCaseCurrencyCode = currencyCode.toUpperCase(); - if (!isFiatCurrency(upperCaseCurrencyCode)) - throw new IllegalStateException(format("%s is not a valid currency code", upperCaseCurrencyCode)); - if (!priceFeedService.hasPrices()) throw new IllegalStateException("price feed service has no prices"); try { - priceFeedService.setCurrencyCode(upperCaseCurrencyCode); + priceFeedService.setCurrencyCode(upperCaseCurrencyCode, false); // TODO (woodser): skipping applying to consumer to avoid console warning spam when getting market prices over the api } catch (Throwable throwable) { log.warn("Could not set currency code in PriceFeedService", throwable); } diff --git a/core/src/main/java/bisq/core/provider/price/PriceFeedService.java b/core/src/main/java/bisq/core/provider/price/PriceFeedService.java index 29b42fd7d4..ab28cac38e 100644 --- a/core/src/main/java/bisq/core/provider/price/PriceFeedService.java +++ b/core/src/main/java/bisq/core/provider/price/PriceFeedService.java @@ -19,7 +19,6 @@ package bisq.core.provider.price; import bisq.core.locale.CurrencyUtil; import bisq.core.locale.TradeCurrency; -import bisq.core.monetary.Altcoin; import bisq.core.monetary.Price; import bisq.core.provider.PriceHttpClient; import bisq.core.provider.ProvidersRepository; @@ -55,7 +54,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Optional; import java.util.Random; import java.util.Set; import java.util.function.Consumer; @@ -272,15 +270,19 @@ public class PriceFeedService { /////////////////////////////////////////////////////////////////////////////////////////// public void setCurrencyCode(String currencyCode) { + setCurrencyCode(currencyCode, true); + } + + // TODO (woodser): necessary to skip applying to consumer to avoid console warning spam when getting market prices over the api + public void setCurrencyCode(String currencyCode, boolean applyPriceToConsumer) { if (this.currencyCode == null || !this.currencyCode.equals(currencyCode)) { this.currencyCode = currencyCode; currencyCodeProperty.set(currencyCode); - if (priceConsumer != null) + if (applyPriceToConsumer && priceConsumer != null) applyPriceToConsumer(); } } - /////////////////////////////////////////////////////////////////////////////////////////// // Getter /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/provider/price/PriceProvider.java b/core/src/main/java/bisq/core/provider/price/PriceProvider.java index 2c629c18b8..217c2a5d1e 100644 --- a/core/src/main/java/bisq/core/provider/price/PriceProvider.java +++ b/core/src/main/java/bisq/core/provider/price/PriceProvider.java @@ -62,7 +62,6 @@ public class PriceProvider extends HttpClientProvider { String json = httpClient.get("getAllMarketPrices", "User-Agent", "bisq/" + Version.VERSION + hsVersion); - LinkedTreeMap map = new Gson().fromJson(json, LinkedTreeMap.class); Map tsMap = new HashMap<>(); tsMap.put("btcAverageTs", ((Double) map.get("btcAverageTs")).longValue()); @@ -96,15 +95,17 @@ public class PriceProvider extends HttpClientProvider { if (isFiat) price = price * btcPerXmrFinal; else price = price / btcPerXmrFinal; - // TODO (woodser): remove xmr from list since base currency and add btc, test by doing btc/xmr trade - + // add currency price to map marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true)); } catch (Throwable t) { log.error(t.toString()); t.printStackTrace(); } - }); + + // add btc to price map, remove xmr since base currency + marketPriceMap.put("BTC", new MarketPrice("BTC", 1 / btcPerXmrFinal, marketPriceMap.get("XMR").getTimestampSec(), true)); + marketPriceMap.remove("XMR"); return new Tuple2<>(tsMap, marketPriceMap); }