Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for issues #2741, #2944, #2955 #2976

Merged
merged 8 commits into from
Aug 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,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:

####################################################################
Expand Down Expand Up @@ -610,7 +611,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
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;
Expand Down Expand Up @@ -304,20 +305,20 @@ CandleData getCandleData(long tick, Set<TradeStatistics2> set) {
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)));
Expand All @@ -327,6 +328,9 @@ CandleData getCandleData(long tick, Set<TradeStatistics2> set) {
}

long averagePrice;
Long[] prices = new Long[tradePrices.size()];
tradePrices.toArray(prices);
long medianPrice = findMedian(prices);
boolean isBullish;
if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) {
isBullish = close < open;
Expand All @@ -343,9 +347,20 @@ CandleData getCandleData(long tick, Set<TradeStatistics2> set) {
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +40,7 @@ public CandleData(long tick, long open, long close, long high, long low, long av
this.high = high;
this.low = low;
this.average = average;
this.median = median;
this.accumulatedAmount = accumulatedAmount;
this.accumulatedVolume = accumulatedVolume;
this.numTrades = numTrades;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -118,6 +122,7 @@ public void update(CandleData candleData) {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ public void testGetCandleData() {
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;
Expand All @@ -161,6 +162,7 @@ public void testGetCandleData() {
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);
Expand Down