From 7f4bde86698b93028c7d66b5cde3f267fcbb6469 Mon Sep 17 00:00:00 2001 From: jmacxx <47253594+jmacxx@users.noreply.github.com> Date: Mon, 23 Oct 2023 14:26:01 -0500 Subject: [PATCH] Fix deviation in open portfolio offers & history. --- .../java/bisq/core/trade/ClosedTradableFormatter.java | 10 ++++------ core/src/main/java/bisq/core/util/PriceUtil.java | 9 +++++++++ .../main/portfolio/openoffer/OpenOfferListItem.java | 4 ++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/bisq/core/trade/ClosedTradableFormatter.java b/core/src/main/java/bisq/core/trade/ClosedTradableFormatter.java index b64b2880f3f..36a882b66b7 100644 --- a/core/src/main/java/bisq/core/trade/ClosedTradableFormatter.java +++ b/core/src/main/java/bisq/core/trade/ClosedTradableFormatter.java @@ -26,6 +26,7 @@ import bisq.core.trade.model.Tradable; import bisq.core.trade.model.bisq_v1.Trade; import bisq.core.util.FormattingUtils; +import bisq.core.util.PriceUtil; import bisq.core.util.coin.BsqFormatter; import bisq.core.util.coin.CoinFormatter; @@ -49,7 +50,6 @@ import static bisq.core.trade.model.bisq_v1.Trade.DisputeState.MEDIATION_CLOSED; import static bisq.core.trade.model.bisq_v1.Trade.DisputeState.REFUND_REQUEST_CLOSED; import static bisq.core.util.FormattingUtils.BTC_FORMATTER_KEY; -import static bisq.core.util.FormattingUtils.formatPercentagePrice; import static bisq.core.util.FormattingUtils.formatToPercentWithSymbol; import static bisq.core.util.VolumeUtil.formatVolume; import static bisq.core.util.VolumeUtil.formatVolumeWithCode; @@ -142,11 +142,9 @@ public String getTotalTradeFeeInBtcAsString(Coin totalTradeAmount, Coin totalTra } public String getPriceDeviationAsString(Tradable tradable) { - if (tradable.getOffer().isUseMarketBasedPrice()) { - return formatPercentagePrice(tradable.getOffer().getMarketPriceMargin()); - } else { - return Res.get("shared.na"); - } + return PriceUtil.offerPercentageToDeviation(tradable.getOffer()) + .map(FormattingUtils::formatPercentagePrice) + .orElse(Res.get("shared.na")); } public String getVolumeAsString(Tradable tradable, boolean appendCode) { diff --git a/core/src/main/java/bisq/core/util/PriceUtil.java b/core/src/main/java/bisq/core/util/PriceUtil.java index 9f8b934c111..ca57722f49c 100644 --- a/core/src/main/java/bisq/core/util/PriceUtil.java +++ b/core/src/main/java/bisq/core/util/PriceUtil.java @@ -129,6 +129,15 @@ public Price getBsq30DayAveragePrice() { return bsq30DayAveragePrice; } + public static Optional offerPercentageToDeviation(Offer offer) { + if (offer.isUseMarketBasedPrice()) { + return Optional.of(offer.getDirection() == OfferDirection.SELL ? + offer.getMarketPriceMargin() : -offer.getMarketPriceMargin()); + } else { + return Optional.empty(); + } + } + public boolean hasMarketPrice(Offer offer) { String currencyCode = offer.getCurrencyCode(); checkNotNull(priceFeedService, "priceFeed must not be null"); diff --git a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOfferListItem.java b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOfferListItem.java index b194334b7c3..99274f8272a 100644 --- a/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOfferListItem.java +++ b/desktop/src/main/java/bisq/desktop/main/portfolio/openoffer/OpenOfferListItem.java @@ -85,12 +85,12 @@ public String getPriceAsString() { public Double getPriceDeviationAsDouble() { Offer offer = getOffer(); - return priceUtil.getMarketBasedPrice(offer, offer.getMirroredDirection()).orElse(0d); + return PriceUtil.offerPercentageToDeviation(offer).orElse(0d); } public String getPriceDeviationAsString() { Offer offer = getOffer(); - return priceUtil.getMarketBasedPrice(offer, offer.getMirroredDirection()) + return PriceUtil.offerPercentageToDeviation(offer) .map(FormattingUtils::formatPercentagePrice) .orElse(""); }