diff --git a/core/src/main/java/bisq/core/trade/ClosedTradableFormatter.java b/core/src/main/java/bisq/core/trade/ClosedTradableFormatter.java index b64b2880f3..36a882b66b 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.offer.OpenOffer; 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.DISPUTE_CLOSED; 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 class ClosedTradableFormatter { } 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 9f8b934c11..ca57722f49 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 class PriceUtil { 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 b194334b7c..99274f8272 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 @@ class OpenOfferListItem implements FilterableListItem { 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(""); }