From 3157891bbbca40e59994b04ef563a6e9382ee14a Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 10 May 2021 11:59:25 -0400 Subject: [PATCH] prices are based on xmr by translating bisq price service #18 (#61) --- .../core/provider/price/PriceProvider.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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 3a69bb0f61..2c629c18b8 100644 --- a/core/src/main/java/bisq/core/provider/price/PriceProvider.java +++ b/core/src/main/java/bisq/core/provider/price/PriceProvider.java @@ -17,6 +17,7 @@ package bisq.core.provider.price; +import bisq.core.locale.CurrencyUtil; import bisq.core.provider.HttpClientProvider; import bisq.network.http.HttpClient; @@ -68,7 +69,20 @@ public class PriceProvider extends HttpClientProvider { tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue()); tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue()); + // get btc per xmr price to convert all prices to xmr + // TODO (woodser): currently using bisq price feed, switch? + Double btcPerXmr = null; List list = (ArrayList) map.get("data"); + for (Object obj : list) { + LinkedTreeMap treeMap = (LinkedTreeMap) obj; + String currencyCode = (String) treeMap.get("currencyCode"); + if ("XMR".equalsIgnoreCase(currencyCode)) { + btcPerXmr = (Double) treeMap.get("price"); + break; + } + } + + final double btcPerXmrFinal = btcPerXmr; list.forEach(obj -> { try { LinkedTreeMap treeMap = (LinkedTreeMap) obj; @@ -76,6 +90,14 @@ public class PriceProvider extends HttpClientProvider { double price = (Double) treeMap.get("price"); // json uses double for our timestampSec long value... long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec")); + + // convert price from btc to xmr + boolean isFiat = CurrencyUtil.isFiatCurrency(currencyCode); + 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 + marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true)); } catch (Throwable t) { log.error(t.toString());