mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 18:03:12 +01:00
Merge pull request #2976 from niyid/master
Fixes for issues #2741, #2944, #2955
This commit is contained in:
commit
fb1c96d24c
@ -306,6 +306,7 @@ market.trades.tooltip.candle.close=Close:
|
||||
market.trades.tooltip.candle.high=High:
|
||||
market.trades.tooltip.candle.low=Low:
|
||||
market.trades.tooltip.candle.average=Average:
|
||||
market.trades.tooltip.candle.median=Median:
|
||||
market.trades.tooltip.candle.date=Date:
|
||||
|
||||
####################################################################
|
||||
@ -614,7 +615,7 @@ message.state.SENT=Message sent
|
||||
# suppress inspection "UnusedProperty"
|
||||
message.state.ARRIVED=Message arrived at peer
|
||||
# suppress inspection "UnusedProperty"
|
||||
message.state.STORED_IN_MAILBOX=Message stored in mailbox
|
||||
message.state.STORED_IN_MAILBOX=Message of payment sent but not yet received by peer
|
||||
# suppress inspection "UnusedProperty"
|
||||
message.state.ACKNOWLEDGED=Peer confirmed message receipt
|
||||
# suppress inspection "UnusedProperty"
|
||||
|
@ -65,6 +65,7 @@ import java.time.ZonedDateTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -304,20 +305,20 @@ class TradesChartsViewModel extends ActivatableViewModel {
|
||||
long accumulatedVolume = 0;
|
||||
long accumulatedAmount = 0;
|
||||
long numTrades = set.size();
|
||||
List<Long> tradePrices = new ArrayList<>(set.size());
|
||||
|
||||
for (TradeStatistics2 item : set) {
|
||||
long tradePriceAsLong = item.getTradePrice().getValue();
|
||||
if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) {
|
||||
low = (low != 0) ? Math.max(low, tradePriceAsLong) : tradePriceAsLong;
|
||||
high = (high != 0) ? Math.min(high, tradePriceAsLong) : tradePriceAsLong;
|
||||
} else {
|
||||
low = (low != 0) ? Math.min(low, tradePriceAsLong) : tradePriceAsLong;
|
||||
high = (high != 0) ? Math.max(high, tradePriceAsLong) : tradePriceAsLong;
|
||||
}
|
||||
// Previously a check was done which inverted the low and high for
|
||||
// crytocurrencies.
|
||||
low = (low != 0) ? Math.min(low, tradePriceAsLong) : tradePriceAsLong;
|
||||
high = (high != 0) ? Math.max(high, tradePriceAsLong) : tradePriceAsLong;
|
||||
|
||||
accumulatedVolume += (item.getTradeVolume() != null) ? item.getTradeVolume().getValue() : 0;
|
||||
accumulatedAmount += item.getTradeAmount().getValue();
|
||||
tradePrices.add(item.getTradePrice().getValue());
|
||||
}
|
||||
Collections.sort(tradePrices);
|
||||
|
||||
List<TradeStatistics2> list = new ArrayList<>(set);
|
||||
list.sort((o1, o2) -> (o1.getTradeDate().getTime() < o2.getTradeDate().getTime() ? -1 : (o1.getTradeDate().getTime() == o2.getTradeDate().getTime() ? 0 : 1)));
|
||||
@ -327,6 +328,9 @@ class TradesChartsViewModel extends ActivatableViewModel {
|
||||
}
|
||||
|
||||
long averagePrice;
|
||||
Long[] prices = new Long[tradePrices.size()];
|
||||
tradePrices.toArray(prices);
|
||||
long medianPrice = findMedian(prices);
|
||||
boolean isBullish;
|
||||
if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) {
|
||||
isBullish = close < open;
|
||||
@ -343,9 +347,20 @@ class TradesChartsViewModel extends ActivatableViewModel {
|
||||
String dateString = tickUnit.ordinal() > TickUnit.DAY.ordinal() ?
|
||||
formatter.formatDateTimeSpan(dateFrom, dateTo) :
|
||||
formatter.formatDate(dateFrom) + " - " + formatter.formatDate(dateTo);
|
||||
return new CandleData(tick, open, close, high, low, averagePrice, accumulatedAmount, accumulatedVolume,
|
||||
return new CandleData(tick, open, close, high, low, averagePrice, medianPrice, accumulatedAmount, accumulatedVolume,
|
||||
numTrades, isBullish, dateString);
|
||||
}
|
||||
|
||||
Long findMedian(Long[] prices) {
|
||||
int middle = prices.length / 2;
|
||||
long median;
|
||||
if (prices.length % 2 == 1) {
|
||||
median = prices[middle];
|
||||
} else {
|
||||
median = MathUtils.roundDoubleToLong((prices[middle - 1] + prices[middle]) / 2.0);
|
||||
}
|
||||
return median;
|
||||
}
|
||||
|
||||
Date roundToTick(Date time, TickUnit tickUnit) {
|
||||
ZonedDateTime zdt = time.toInstant().atZone(ZoneId.systemDefault());
|
||||
|
@ -24,13 +24,14 @@ public class CandleData {
|
||||
public final long high;
|
||||
public final long low;
|
||||
public final long average;
|
||||
public final long median;
|
||||
public final long accumulatedAmount;
|
||||
public final long accumulatedVolume;
|
||||
public final long numTrades;
|
||||
public final boolean isBullish;
|
||||
public final String date;
|
||||
|
||||
public CandleData(long tick, long open, long close, long high, long low, long average,
|
||||
public CandleData(long tick, long open, long close, long high, long low, long average, long median,
|
||||
long accumulatedAmount, long accumulatedVolume, long numTrades,
|
||||
boolean isBullish, String date) {
|
||||
this.tick = tick;
|
||||
@ -39,6 +40,7 @@ public class CandleData {
|
||||
this.high = high;
|
||||
this.low = low;
|
||||
this.average = average;
|
||||
this.median = median;
|
||||
this.accumulatedAmount = accumulatedAmount;
|
||||
this.accumulatedVolume = accumulatedVolume;
|
||||
this.numTrades = numTrades;
|
||||
|
@ -74,6 +74,7 @@ public class CandleTooltip extends GridPane {
|
||||
private final Label highValue = new AutoTooltipLabel();
|
||||
private final Label lowValue = new AutoTooltipLabel();
|
||||
private final Label averageValue = new AutoTooltipLabel();
|
||||
private final Label medianValue = new AutoTooltipLabel();
|
||||
private final Label dateValue = new AutoTooltipLabel();
|
||||
|
||||
CandleTooltip(StringConverter<Number> priceStringConverter) {
|
||||
@ -88,6 +89,7 @@ public class CandleTooltip extends GridPane {
|
||||
Label high = new AutoTooltipLabel(Res.get("market.trades.tooltip.candle.high"));
|
||||
Label low = new AutoTooltipLabel(Res.get("market.trades.tooltip.candle.low"));
|
||||
Label average = new AutoTooltipLabel(Res.get("market.trades.tooltip.candle.average"));
|
||||
Label median = new AutoTooltipLabel(Res.get("market.trades.tooltip.candle.median"));
|
||||
Label date = new AutoTooltipLabel(Res.get("market.trades.tooltip.candle.date"));
|
||||
setConstraints(open, 0, 0);
|
||||
setConstraints(openValue, 1, 0);
|
||||
@ -99,8 +101,10 @@ public class CandleTooltip extends GridPane {
|
||||
setConstraints(lowValue, 1, 3);
|
||||
setConstraints(average, 0, 4);
|
||||
setConstraints(averageValue, 1, 4);
|
||||
setConstraints(date, 0, 5);
|
||||
setConstraints(dateValue, 1, 5);
|
||||
setConstraints(median, 0, 5);
|
||||
setConstraints(medianValue, 1, 5);
|
||||
setConstraints(date, 0, 6);
|
||||
setConstraints(dateValue, 1, 6);
|
||||
|
||||
ColumnConstraints columnConstraints1 = new ColumnConstraints();
|
||||
columnConstraints1.setHalignment(HPos.RIGHT);
|
||||
@ -109,7 +113,7 @@ public class CandleTooltip extends GridPane {
|
||||
columnConstraints2.setHgrow(Priority.ALWAYS);
|
||||
getColumnConstraints().addAll(columnConstraints1, columnConstraints2);
|
||||
|
||||
getChildren().addAll(open, openValue, close, closeValue, high, highValue, low, lowValue, average, averageValue, date, dateValue);
|
||||
getChildren().addAll(open, openValue, close, closeValue, high, highValue, low, lowValue, average, averageValue, median, medianValue, date, dateValue);
|
||||
}
|
||||
|
||||
public void update(CandleData candleData) {
|
||||
@ -118,6 +122,7 @@ public class CandleTooltip extends GridPane {
|
||||
highValue.setText(priceStringConverter.toString(candleData.high));
|
||||
lowValue.setText(priceStringConverter.toString(candleData.low));
|
||||
averageValue.setText(priceStringConverter.toString(candleData.average));
|
||||
medianValue.setText(priceStringConverter.toString(candleData.median));
|
||||
dateValue.setText(candleData.date);
|
||||
}
|
||||
}
|
||||
|
@ -143,6 +143,7 @@ public class TradesChartsViewModelTest {
|
||||
long close = Fiat.parseFiat("EUR", "580").value;
|
||||
long high = Fiat.parseFiat("EUR", "600").value;
|
||||
long average = Fiat.parseFiat("EUR", "550").value;
|
||||
long median = Fiat.parseFiat("EUR", "550").value;
|
||||
long amount = Coin.parseCoin("4").value;
|
||||
long volume = Fiat.parseFiat("EUR", "2200").value;
|
||||
boolean isBullish = true;
|
||||
@ -161,6 +162,7 @@ public class TradesChartsViewModelTest {
|
||||
assertEquals(high, candleData.high);
|
||||
assertEquals(low, candleData.low);
|
||||
assertEquals(average, candleData.average);
|
||||
assertEquals(median, candleData.median);
|
||||
assertEquals(amount, candleData.accumulatedAmount);
|
||||
assertEquals(volume, candleData.accumulatedVolume);
|
||||
assertEquals(isBullish, candleData.isBullish);
|
||||
|
Loading…
Reference in New Issue
Block a user