Skip to content

Commit

Permalink
Merge pull request #6936 from jmacxx/fix_trade_history_deviation_column
Browse files Browse the repository at this point in the history
Fix deviation in portfolio offers & history.
  • Loading branch information
alejandrogarcia83 authored Oct 31, 2023
2 parents 2d2ed94 + 7f4bde8 commit f43c0fc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
10 changes: 4 additions & 6 deletions core/src/main/java/bisq/core/trade/ClosedTradableFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/java/bisq/core/util/PriceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public Price getBsq30DayAveragePrice() {
return bsq30DayAveragePrice;
}

public static Optional<Double> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}
Expand Down

0 comments on commit f43c0fc

Please sign in to comment.