mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
use Fiat for price
This commit is contained in:
parent
c8699dd66b
commit
454dc94965
@ -36,7 +36,7 @@ public class OfferListItem {
|
||||
this.offer = offer;
|
||||
|
||||
this.date.set(BSFormatter.formatDateTime(offer.getCreationDate()));
|
||||
this.price.set(BSFormatter.formatPrice(offer.getPrice()));
|
||||
this.price.set(BSFormatter.formatFiat(offer.getPrice()));
|
||||
|
||||
this.amount.set(BSFormatter.formatCoin(
|
||||
offer.getAmount()) + " (" + BSFormatter.formatCoin(offer.getMinAmount()) + ")");
|
||||
|
@ -279,7 +279,7 @@ public class PendingTradeController extends CachedViewController {
|
||||
secondaryBankAccountIDTitleLabel.setText("Refunded collateral:");
|
||||
|
||||
bankAccountTypeTextField.setText(BSFormatter.formatCoinWithCode(trade.getTradeAmount()));
|
||||
holderNameTextField.setText(BSFormatter.formatVolume(trade.getTradeVolume()));
|
||||
holderNameTextField.setText(BSFormatter.formatFiat(trade.getTradeVolume()));
|
||||
primaryBankAccountIDTextField.setText(
|
||||
BSFormatter.formatCoinWithCode(FeePolicy.CREATE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
secondaryBankAccountIDTextField.setText(BSFormatter.formatCoinWithCode(trade.getCollateralAmount()));
|
||||
|
@ -90,7 +90,7 @@ public class TradeController extends CachedViewController {
|
||||
((TabPane) root).getTabs().addListener((ListChangeListener<Tab>) change -> {
|
||||
change.next();
|
||||
List<? extends Tab> removedTabs = change.getRemoved();
|
||||
if (removedTabs.size() == 1 && createOfferView.equals(removedTabs.get(0).getContent())) {
|
||||
if (removedTabs.size() == 1 && removedTabs.get(0).getContent().equals(createOfferView)) {
|
||||
if (createOfferCodeBehind != null) {
|
||||
createOfferCodeBehind.terminate();
|
||||
createOfferCodeBehind = null;
|
||||
|
@ -45,6 +45,7 @@ import io.bitsquare.util.Utilities;
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.InsufficientMoneyException;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
|
||||
@ -549,7 +550,8 @@ public class OrderBookController extends CachedViewController {
|
||||
private void updateVolume() {
|
||||
double a = textInputToNumber(amount.getText(), amount.getText());
|
||||
double p = textInputToNumber(price.getText(), price.getText());
|
||||
volume.setText(BSFormatter.formatPrice(a * p));
|
||||
//TODO
|
||||
volume.setText(BSFormatter.formatFiat(Fiat.valueOf("EUR", (long) (a * p))));
|
||||
}
|
||||
|
||||
public void onCreateOfferViewRemoved() {
|
||||
|
@ -34,7 +34,8 @@ public class OrderBookListItem {
|
||||
|
||||
public OrderBookListItem(Offer offer) {
|
||||
this.offer = offer;
|
||||
this.price.set(BSFormatter.formatPrice(offer.getPrice()));
|
||||
this.price.set(BSFormatter.formatFiat(offer.getPrice()));
|
||||
this.price.set(BSFormatter.formatFiat(offer.getPrice()));
|
||||
this.amount.set(BSFormatter.formatCoin(
|
||||
offer.getAmount()) + " (" + BSFormatter.formatCoin(offer.getMinAmount()) + ")");
|
||||
this.volume.set(BSFormatter.formatVolumeWithMinVolume(
|
||||
|
@ -33,6 +33,7 @@ import io.bitsquare.trade.protocol.trade.taker.SellerTakesOfferProtocol;
|
||||
import io.bitsquare.trade.protocol.trade.taker.SellerTakesOfferProtocolListener;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
@ -120,7 +121,7 @@ public class TakeOfferController extends CachedViewController {
|
||||
amountTextField.setText(requestedAmount.toPlainString());
|
||||
amountTextField.setPromptText(BSFormatter.formatCoinWithCode(
|
||||
offer.getMinAmount()) + " - " + BSFormatter.formatCoinWithCode(offer.getAmount()));
|
||||
priceTextField.setText(BSFormatter.formatPrice(offer.getPrice()));
|
||||
priceTextField.setText(BSFormatter.formatFiat(offer.getPrice()));
|
||||
applyVolume();
|
||||
collateralLabel.setText("Collateral (" + getCollateralAsPercent() + "):");
|
||||
applyCollateral();
|
||||
@ -197,7 +198,7 @@ public class TakeOfferController extends CachedViewController {
|
||||
accordion.setExpandedPane(summaryTitledPane);
|
||||
|
||||
summaryPaidTextField.setText(BSFormatter.formatCoinWithCode(trade.getTradeAmount()));
|
||||
summaryReceivedTextField.setText(BSFormatter.formatVolume(trade.getTradeVolume()));
|
||||
summaryReceivedTextField.setText(BSFormatter.formatFiat(trade.getTradeVolume()));
|
||||
summaryFeesTextField.setText(BSFormatter.formatCoinWithCode(
|
||||
FeePolicy.TAKE_OFFER_FEE.add(FeePolicy.TX_FEE)));
|
||||
summaryCollateralTextField.setText(BSFormatter.formatCoinWithCode(
|
||||
@ -265,7 +266,7 @@ public class TakeOfferController extends CachedViewController {
|
||||
|
||||
// formatted
|
||||
private String getFormattedVolume() {
|
||||
return BSFormatter.formatVolume(getVolume());
|
||||
return BSFormatter.formatFiat(getVolume());
|
||||
}
|
||||
|
||||
private String getFormattedTotal() {
|
||||
@ -291,8 +292,9 @@ public class TakeOfferController extends CachedViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private double getVolume() {
|
||||
return offer.getPrice() * getAmountAsDouble();
|
||||
private Fiat getVolume() {
|
||||
//TODO
|
||||
return Fiat.valueOf("EUR", (long) (offer.getPrice().longValue() * getAmountAsDouble()));
|
||||
}
|
||||
|
||||
private Coin getFee() {
|
||||
@ -305,13 +307,11 @@ public class TakeOfferController extends CachedViewController {
|
||||
|
||||
private Coin getCollateralAsCoin() {
|
||||
Coin amountAsCoin = BSFormatter.parseToCoin(getAmountString());
|
||||
return amountAsCoin.divide((long) (1d / offer.getCollateral()));
|
||||
return amountAsCoin.multiply(getCollateral()).divide(1000L);
|
||||
}
|
||||
|
||||
private String getFormattedCollateralAsBtc() {
|
||||
Coin amountAsCoin = BSFormatter.parseToCoin(getAmountString());
|
||||
Coin collateralAsCoin = amountAsCoin.divide((long) (1d / getCollateral()));
|
||||
return BSFormatter.formatCoin(collateralAsCoin);
|
||||
return BSFormatter.formatCoin(getCollateralAsCoin());
|
||||
}
|
||||
|
||||
private String getCollateralAsPercent() {
|
||||
@ -319,7 +319,6 @@ public class TakeOfferController extends CachedViewController {
|
||||
}
|
||||
|
||||
private long getCollateral() {
|
||||
// TODO
|
||||
return offer.getCollateral();
|
||||
}
|
||||
|
||||
|
@ -70,11 +70,6 @@ public class BSFormatter {
|
||||
|
||||
private static String currencyCode = Currency.getInstance(Locale.getDefault()).getCurrencyCode();
|
||||
|
||||
static {
|
||||
//useMilliBitFormat(true);
|
||||
// setLocale(Locale.US);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Config
|
||||
@ -252,11 +247,11 @@ public class BSFormatter {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String formatDouble(double value) {
|
||||
public static String formatDouble(Fiat value) {
|
||||
return formatDouble(value, 4);
|
||||
}
|
||||
|
||||
public static String formatDouble(double value, int fractionDigits) {
|
||||
public static String formatDouble(Fiat value, int fractionDigits) {
|
||||
DecimalFormat decimalFormat = getDecimalFormat(fractionDigits);
|
||||
return decimalFormat.format(value);
|
||||
}
|
||||
@ -333,19 +328,8 @@ public class BSFormatter {
|
||||
return getDecimalFormat(1).format(collateral / 10) + " %";
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatPrice(double volume) {
|
||||
return formatDouble(volume);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatVolume(double volume) {
|
||||
return formatDouble(volume);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String formatVolumeWithMinVolume(double volume, double minVolume) {
|
||||
return formatDouble(volume) + " (" + formatDouble(minVolume) + ")";
|
||||
public static String formatVolumeWithMinVolume(Fiat volume, Fiat minVolume) {
|
||||
return formatFiat(volume) + " (" + formatFiat(minVolume) + ")";
|
||||
}
|
||||
/*
|
||||
@Deprecated
|
||||
|
@ -22,6 +22,7 @@ import io.bitsquare.bank.BankAccountType;
|
||||
import io.bitsquare.locale.Country;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -47,7 +48,7 @@ public class Offer implements Serializable {
|
||||
|
||||
private final Date creationDate;
|
||||
|
||||
private final double price;
|
||||
private final Fiat price;
|
||||
private final Coin amount;
|
||||
private final Coin minAmount;
|
||||
//TODO use hex string
|
||||
@ -70,7 +71,7 @@ public class Offer implements Serializable {
|
||||
public Offer(String id,
|
||||
PublicKey messagePublicKey,
|
||||
Direction direction,
|
||||
double price,
|
||||
Fiat price,
|
||||
Coin amount,
|
||||
Coin minAmount,
|
||||
BankAccountType bankAccountType,
|
||||
@ -118,7 +119,7 @@ public class Offer implements Serializable {
|
||||
return id;
|
||||
}
|
||||
|
||||
public double getPrice() {
|
||||
public Fiat getPrice() {
|
||||
return price;
|
||||
}
|
||||
|
||||
@ -154,17 +155,18 @@ public class Offer implements Serializable {
|
||||
return acceptedLanguageLocales;
|
||||
}
|
||||
|
||||
public double getVolumeForCoin(Coin coin) {
|
||||
public Fiat getVolumeForCoin(Coin coin) {
|
||||
BigDecimal amountBD = BigDecimal.valueOf(coin.longValue());
|
||||
BigDecimal volumeBD = amountBD.multiply(BigDecimal.valueOf(price));
|
||||
return volumeBD.divide(BigDecimal.valueOf(Coin.COIN.value)).doubleValue();
|
||||
BigDecimal volumeBD = amountBD.multiply(BigDecimal.valueOf(price.longValue() / 10000));
|
||||
long fiatAsDouble = volumeBD.divide(BigDecimal.valueOf(Coin.COIN.value)).longValue();
|
||||
return Fiat.valueOf("EUR", fiatAsDouble);
|
||||
}
|
||||
|
||||
public double getOfferVolume() {
|
||||
public Fiat getOfferVolume() {
|
||||
return getVolumeForCoin(amount);
|
||||
}
|
||||
|
||||
public double getMinOfferVolume() {
|
||||
public Fiat getMinOfferVolume() {
|
||||
return getVolumeForCoin(minAmount);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package io.bitsquare.trade;
|
||||
|
||||
import com.google.bitcoin.core.Coin;
|
||||
import com.google.bitcoin.core.Transaction;
|
||||
import com.google.bitcoin.utils.Fiat;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -57,7 +58,7 @@ public class Trade implements Serializable {
|
||||
_stateChangedProperty = new SimpleStringProperty();
|
||||
}
|
||||
|
||||
public double getTradeVolume() {
|
||||
public Fiat getTradeVolume() {
|
||||
return offer.getVolumeForCoin(tradeAmount);
|
||||
}
|
||||
|
||||
@ -173,7 +174,7 @@ public class Trade implements Serializable {
|
||||
}
|
||||
|
||||
public Coin getCollateralAmount() {
|
||||
return tradeAmount.divide((long) (1d / offer.getCollateral()));
|
||||
return tradeAmount.multiply(offer.getCollateral()).divide(1000L);
|
||||
}
|
||||
|
||||
|
||||
|
@ -167,11 +167,10 @@ public class TradeManager {
|
||||
TransactionResultHandler resultHandler,
|
||||
ErrorMessageHandler errorMessageHandler) {
|
||||
|
||||
// TODO price.value -> use Fiat in Offer for price
|
||||
Offer offer = new Offer(id,
|
||||
user.getMessagePublicKey(),
|
||||
direction,
|
||||
price.value,
|
||||
price,
|
||||
amount,
|
||||
minAmount,
|
||||
user.getCurrentBankAccount().getBankAccountType(),
|
||||
@ -216,7 +215,7 @@ public class TradeManager {
|
||||
|
||||
private void addOffer(Offer offer) throws IOException {
|
||||
if (offers.containsKey(offer.getId()))
|
||||
throw new IllegalStateException("An offer with the id " + offer.getId() + " already exists. ");
|
||||
log.error("An offer with the id " + offer.getId() + " already exists. ");
|
||||
|
||||
offers.put(offer.getId(), offer);
|
||||
persistOffers();
|
||||
@ -224,7 +223,7 @@ public class TradeManager {
|
||||
|
||||
public void removeOffer(Offer offer) {
|
||||
if (!offers.containsKey(offer.getId())) {
|
||||
throw new IllegalStateException("offers does not contain the offer with the ID " + offer.getId());
|
||||
log.error("offers does not contain the offer with the ID " + offer.getId());
|
||||
}
|
||||
|
||||
offers.remove(offer.getId());
|
||||
@ -251,9 +250,8 @@ public class TradeManager {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public Trade createTrade(Offer offer) {
|
||||
if (trades.containsKey(offer.getId())) {
|
||||
throw new IllegalStateException("trades contains already an trade with the ID " + offer.getId());
|
||||
}
|
||||
if (trades.containsKey(offer.getId()))
|
||||
log.error("trades contains already an trade with the ID " + offer.getId());
|
||||
|
||||
Trade trade = new Trade(offer);
|
||||
trades.put(offer.getId(), trade);
|
||||
@ -266,9 +264,8 @@ public class TradeManager {
|
||||
}
|
||||
|
||||
public void removeTrade(Trade trade) {
|
||||
if (!trades.containsKey(trade.getId())) {
|
||||
throw new IllegalStateException("trades does not contain the trade with the ID " + trade.getId());
|
||||
}
|
||||
if (!trades.containsKey(trade.getId()))
|
||||
log.error("trades does not contain the trade with the ID " + trade.getId());
|
||||
|
||||
trades.remove(trade.getId());
|
||||
saveTrades();
|
||||
|
@ -25,7 +25,6 @@ import io.bitsquare.locale.CurrencyUtil;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OrderBookListener;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.Direction;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.TradeManager;
|
||||
import io.bitsquare.user.User;
|
||||
@ -137,12 +136,14 @@ public class OrderBook implements OrderBookListener {
|
||||
// Apply applyFilter only if there is a valid value set
|
||||
boolean priceResult = true;
|
||||
if (orderBookFilter.getPrice() > 0) {
|
||||
if (offer.getDirection() == Direction.SELL) {
|
||||
priceResult = orderBookFilter.getPrice() >= offer.getPrice();
|
||||
//TODO
|
||||
/* if (offer.getDirection() == Direction.SELL) {
|
||||
priceResult = orderBookFilter.getPrice() //>= offer.getPrice();
|
||||
}
|
||||
else {
|
||||
priceResult = orderBookFilter.getPrice() <= offer.getPrice();
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
// The arbitrator defined in the offer must match one of the accepted arbitrators defined in the settings
|
||||
|
@ -58,7 +58,7 @@ public class VerifyOffer {
|
||||
"Amount is less then " + Restrictions.MIN_TRADE_AMOUNT);
|
||||
checkArgument(offer.getAmount().compareTo(offer.getMinAmount()) >= 0, "MinAmount is larger then Amount");
|
||||
checkArgument(offer.getCollateral() > 0, "Collateral is 0");
|
||||
checkArgument(offer.getPrice() > 0, "Price is 0");
|
||||
checkArgument(offer.getPrice().isPositive(), "Price is 0 or negative");
|
||||
|
||||
// TODO check balance
|
||||
// Coin collateralAsCoin = offer.getAmount().divide((long) (1d / offer.getCollateral()));
|
||||
|
Loading…
Reference in New Issue
Block a user