mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-05-25 18:00:58 -04:00
fix amounts in trade statistics view
This commit is contained in:
parent
59c0496d34
commit
b414ac942d
6 changed files with 32 additions and 40 deletions
|
@ -28,12 +28,8 @@ import haveno.common.util.CollectionUtils;
|
|||
import haveno.common.util.ExtraDataMapValidator;
|
||||
import haveno.common.util.JsonExclude;
|
||||
import haveno.common.util.Utilities;
|
||||
import haveno.core.locale.CurrencyUtil;
|
||||
import haveno.core.monetary.CryptoMoney;
|
||||
import haveno.core.monetary.CryptoExchangeRate;
|
||||
import haveno.core.monetary.Price;
|
||||
import haveno.core.monetary.TraditionalMoney;
|
||||
import haveno.core.monetary.TraditionalExchangeRate;
|
||||
import haveno.core.monetary.Volume;
|
||||
import haveno.core.offer.Offer;
|
||||
import haveno.core.offer.OfferPayload;
|
||||
|
@ -47,9 +43,10 @@ import haveno.network.p2p.storage.payload.PersistableNetworkPayload;
|
|||
import haveno.network.p2p.storage.payload.ProcessOncePersistableNetworkPayload;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Arrays;
|
||||
|
@ -370,19 +367,17 @@ public final class TradeStatistics3 implements ProcessOncePersistableNetworkPayl
|
|||
return priceObj;
|
||||
}
|
||||
|
||||
public Coin getTradeAmount() {
|
||||
return Coin.valueOf(amount);
|
||||
public BigInteger getTradeAmount() {
|
||||
return BigInteger.valueOf(amount);
|
||||
}
|
||||
|
||||
public Volume getTradeVolume() {
|
||||
Volume volume = this.volume;
|
||||
if (volume == null) {
|
||||
if (getTradePrice().getMonetary() instanceof CryptoMoney) {
|
||||
volume = new Volume(new CryptoExchangeRate((CryptoMoney) getTradePrice().getMonetary()).coinToCrypto(getTradeAmount()));
|
||||
} else {
|
||||
Volume exactVolume = new Volume(new TraditionalExchangeRate((TraditionalMoney) getTradePrice().getMonetary()).coinToTraditionalMoney(getTradeAmount()));
|
||||
boolean isFiat = CurrencyUtil.isFiatCurrency(exactVolume.getCurrencyCode());
|
||||
if (isFiat) volume = VolumeUtil.getRoundedFiatVolume(exactVolume);
|
||||
}
|
||||
Price price = getTradePrice();
|
||||
this.volume = volume = price.getMonetary() instanceof CryptoMoney
|
||||
? price.getVolumeByAmount(getTradeAmount())
|
||||
: VolumeUtil.getAdjustedVolume(price.getVolumeByAmount(getTradeAmount()), paymentMethod);
|
||||
}
|
||||
return volume;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class AveragePriceUtil {
|
|||
|
||||
for (TradeStatistics3 item : list) {
|
||||
accumulatedVolume += item.getTradeVolume().getValue();
|
||||
accumulatedAmount += item.getTradeAmount().getValue(); // Amount of BTC traded
|
||||
accumulatedAmount += item.getTradeAmount().longValueExact(); // Amount of XMR traded
|
||||
}
|
||||
long averagePrice;
|
||||
double accumulatedAmountAsDouble = MathUtils.scaleUpByPowerOf10((double) accumulatedAmount, CryptoMoney.SMALLEST_UNIT_EXPONENT);
|
||||
|
@ -110,7 +110,7 @@ public class AveragePriceUtil {
|
|||
.orElse(usdBTCPrice);
|
||||
var bsqAmount = MathUtils.scaleDownByPowerOf10((double) item.getTradeVolume().getValue(),
|
||||
CryptoMoney.SMALLEST_UNIT_EXPONENT);
|
||||
var btcAmount = MathUtils.scaleDownByPowerOf10((double) item.getTradeAmount().getValue(),
|
||||
var btcAmount = MathUtils.scaleDownByPowerOf10((double) item.getTradeAmount().longValueExact(),
|
||||
CryptoMoney.SMALLEST_UNIT_EXPONENT);
|
||||
usdBsqList.add(new Tuple2<>(usdBTCPrice * btcAmount, bsqAmount));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue