From 3546d3d931fd8bc7bbd97de6778142a243e9548b Mon Sep 17 00:00:00 2001 From: woodser <13068859+woodser@users.noreply.github.com> Date: Sun, 29 Jun 2025 13:49:12 -0400 Subject: [PATCH] fix average calculation in trade charts view --- .../desktop/main/market/trades/ChartCalculations.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/desktop/src/main/java/haveno/desktop/main/market/trades/ChartCalculations.java b/desktop/src/main/java/haveno/desktop/main/market/trades/ChartCalculations.java index c8ba1af3af..39b67d1942 100644 --- a/desktop/src/main/java/haveno/desktop/main/market/trades/ChartCalculations.java +++ b/desktop/src/main/java/haveno/desktop/main/market/trades/ChartCalculations.java @@ -76,7 +76,7 @@ public class ChartCalculations { dateMapsPerTickUnit.forEach((tick, map) -> { HashMap priceMap = new HashMap<>(); - map.forEach((date, tradeStatisticsList) -> priceMap.put(date, getAveragePrice(tradeStatisticsList))); + map.forEach((date, tradeStatisticsList) -> priceMap.put(date, getAverageTraditionalPrice(tradeStatisticsList))); usdAveragePriceMapsPerTickUnit.put(tick, priceMap); }); return usdAveragePriceMapsPerTickUnit; @@ -210,7 +210,7 @@ public class ChartCalculations { return roundToTick(time.toInstant().atZone(ChartCalculations.ZONE_ID).toLocalDateTime(), tickUnit); } - private static long getAveragePrice(List tradeStatisticsList) { + private static long getAverageTraditionalPrice(List tradeStatisticsList) { long accumulatedAmount = 0; // TODO: use BigInteger long accumulatedVolume = 0; for (TradeStatistics3 tradeStatistics : tradeStatisticsList) { @@ -262,7 +262,7 @@ public class ChartCalculations { boolean isBullish; if (CurrencyUtil.isCryptoCurrency(currencyCode)) { isBullish = close < open; - double accumulatedAmountAsDouble = MathUtils.scaleUpByPowerOf10((double) accumulatedAmount, 4 + CryptoMoney.SMALLEST_UNIT_EXPONENT); + double accumulatedAmountAsDouble = MathUtils.scaleUpByPowerOf10((double) accumulatedAmount, CryptoMoney.SMALLEST_UNIT_EXPONENT - 4); averagePrice = MathUtils.roundDoubleToLong(accumulatedAmountAsDouble / accumulatedVolume); } else { isBullish = close > open;