mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-20 02:12:00 +01:00
Apply inverted price to trade charts
This commit is contained in:
parent
57e3c19b89
commit
7a827c970e
@ -18,12 +18,14 @@
|
||||
package io.bitsquare.gui.main.market.trades;
|
||||
|
||||
import io.bitsquare.common.UserThread;
|
||||
import io.bitsquare.common.util.MathUtils;
|
||||
import io.bitsquare.gui.common.view.ActivatableViewAndModel;
|
||||
import io.bitsquare.gui.common.view.FxmlView;
|
||||
import io.bitsquare.gui.main.market.trades.charts.price.CandleStickChart;
|
||||
import io.bitsquare.gui.main.market.trades.charts.volume.VolumeChart;
|
||||
import io.bitsquare.gui.util.BSFormatter;
|
||||
import io.bitsquare.gui.util.GUIUtil;
|
||||
import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.locale.TradeCurrency;
|
||||
import io.bitsquare.trade.statistics.TradeStatistics;
|
||||
import javafx.beans.property.ReadOnlyObjectWrapper;
|
||||
@ -233,7 +235,11 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
|
||||
priceAxisY.setTickLabelFormatter(new StringConverter<Number>() {
|
||||
@Override
|
||||
public String toString(Number object) {
|
||||
return formatter.formatPrice(Fiat.valueOf(model.getCurrencyCode(), new Double((double) object).longValue()));
|
||||
if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
|
||||
final double value = (double) object / 100000000D;
|
||||
return String.valueOf(MathUtils.roundDouble(value, 8));
|
||||
} else
|
||||
return formatter.formatPrice(Fiat.valueOf(model.getCurrencyCode(), new Double((double) object).longValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -245,7 +251,12 @@ public class TradesChartsView extends ActivatableViewAndModel<VBox, TradesCharts
|
||||
priceChart = new CandleStickChart(priceAxisX, priceAxisY, new StringConverter<Number>() {
|
||||
@Override
|
||||
public String toString(Number object) {
|
||||
return formatter.formatPriceWithCode(Fiat.valueOf(model.getCurrencyCode(), (long) object));
|
||||
if (CurrencyUtil.isCryptoCurrency(model.getCurrencyCode())) {
|
||||
final double value = (long) object / 100000000D;
|
||||
return String.valueOf(MathUtils.roundDouble(value, 8)) + " " + formatter.getCurrencyPair(model.getCurrencyCode());
|
||||
} else {
|
||||
return formatter.formatPriceWithCode(Fiat.valueOf(model.getCurrencyCode(), (long) object));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,6 +20,7 @@ package io.bitsquare.gui.main.market.trades;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.inject.Inject;
|
||||
import io.bitsquare.btc.pricefeed.PriceFeedService;
|
||||
import io.bitsquare.common.util.MathUtils;
|
||||
import io.bitsquare.gui.Navigation;
|
||||
import io.bitsquare.gui.common.model.ActivatableViewModel;
|
||||
import io.bitsquare.gui.main.MainView;
|
||||
@ -235,9 +236,10 @@ class TradesChartsViewModel extends ActivatableViewModel {
|
||||
|
||||
// create CandleData for defined time interval
|
||||
List<CandleData> candleDataList = itemsPerInterval.entrySet().stream()
|
||||
.filter(entry -> entry.getKey() >= 0)
|
||||
.map(entry -> getCandleData(entry.getKey(), entry.getValue()))
|
||||
.filter(e -> e.tick >= 0)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
candleDataList.sort((o1, o2) -> (o1.tick < o2.tick ? -1 : (o1.tick == o2.tick ? 0 : 1)));
|
||||
|
||||
priceItems.setAll(candleDataList.stream()
|
||||
@ -259,9 +261,15 @@ class TradesChartsViewModel extends ActivatableViewModel {
|
||||
long accumulatedAmount = 0;
|
||||
|
||||
for (TradeStatistics item : set) {
|
||||
final long tradePriceAsLong = item.tradePrice;
|
||||
low = (low != 0) ? Math.min(low, tradePriceAsLong) : tradePriceAsLong;
|
||||
high = (high != 0) ? Math.max(high, tradePriceAsLong) : tradePriceAsLong;
|
||||
long tradePriceAsLong = item.tradePrice;
|
||||
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;
|
||||
}
|
||||
|
||||
accumulatedVolume += (item.getTradeVolume() != null) ? item.getTradeVolume().value : 0;
|
||||
accumulatedAmount += item.tradeAmount;
|
||||
}
|
||||
@ -279,8 +287,19 @@ class TradesChartsViewModel extends ActivatableViewModel {
|
||||
String dateString = tickUnit.ordinal() > TickUnit.DAY.ordinal() ?
|
||||
formatter.formatDateTime(date) :
|
||||
formatter.formatDate(date);
|
||||
return new CandleData(tick, open, close, high, low, averagePrice, accumulatedAmount, accumulatedVolume,
|
||||
isBullish, dateString);
|
||||
if (CurrencyUtil.isCryptoCurrency(getCurrencyCode())) {
|
||||
return new CandleData(tick, getInvertedPrice(open), getInvertedPrice(close), getInvertedPrice(high),
|
||||
getInvertedPrice(low), getInvertedPrice(averagePrice), accumulatedAmount, accumulatedVolume,
|
||||
isBullish, dateString);
|
||||
} else {
|
||||
return new CandleData(tick, open, close, high, low, averagePrice, accumulatedAmount, accumulatedVolume,
|
||||
isBullish, dateString);
|
||||
}
|
||||
}
|
||||
|
||||
long getInvertedPrice(long price) {
|
||||
final double value = price != 0 ? 1000000000000D / price : 0;
|
||||
return Math.round(MathUtils.roundDouble(value, 8));
|
||||
}
|
||||
|
||||
long getTickFromTime(long tradeDateAsTime, TickUnit tickUnit) {
|
||||
|
Loading…
Reference in New Issue
Block a user