mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-31 18:58:51 -04:00
Add check at offerer for trade price
This commit is contained in:
parent
261a037020
commit
461aa9bd7f
8 changed files with 50 additions and 17 deletions
|
@ -68,7 +68,6 @@ public class ProcessModel implements Model, Serializable {
|
|||
transient private KeyRing keyRing;
|
||||
transient private P2PService p2PService;
|
||||
|
||||
|
||||
// Mutable
|
||||
public final TradingPeer tradingPeer;
|
||||
transient private TradeMessage tradeMessage;
|
||||
|
|
|
@ -26,6 +26,7 @@ import io.bitsquare.trade.Trade;
|
|||
import io.bitsquare.trade.protocol.trade.messages.PayDepositRequest;
|
||||
import io.bitsquare.trade.protocol.trade.tasks.TradeTask;
|
||||
import org.bitcoinj.core.Coin;
|
||||
import org.bitcoinj.utils.Fiat;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -76,8 +77,27 @@ public class ProcessPayDepositRequest extends TradeTask {
|
|||
if (payDepositRequest.acceptedArbitratorNodeAddresses.size() < 1)
|
||||
failed("acceptedArbitratorNames size must be at least 1");
|
||||
trade.setArbitratorNodeAddress(checkNotNull(payDepositRequest.arbitratorNodeAddress));
|
||||
|
||||
long takersTradePrice = payDepositRequest.tradePrice;
|
||||
checkArgument(takersTradePrice > 0);
|
||||
Fiat tradePriceAsFiat = Fiat.valueOf(trade.getOffer().getCurrencyCode(), takersTradePrice);
|
||||
Fiat offerPriceAsFiat = trade.getOffer().getPrice();
|
||||
double factor = (double) takersTradePrice / (double) offerPriceAsFiat.value;
|
||||
// We allow max. 2 % difference between own offer price calculation and takers calculation.
|
||||
// Market price might be different at offerers and takers side so we need a bit of tolerance.
|
||||
// The tolerance will get smaller once we have multiple price feeds avoiding fast price fluctuations
|
||||
// from one provider.
|
||||
if (Math.abs(1 - factor) > 0.02) {
|
||||
String msg = "Takers tradePrice is outside our market price tolerance.\n" +
|
||||
"tradePriceAsFiat=" + tradePriceAsFiat.toFriendlyString() + "\n" +
|
||||
"offerPriceAsFiat=" + offerPriceAsFiat.toFriendlyString();
|
||||
log.warn(msg);
|
||||
failed(msg);
|
||||
}
|
||||
trade.setTradePrice(takersTradePrice);
|
||||
|
||||
|
||||
checkArgument(payDepositRequest.tradeAmount > 0);
|
||||
trade.setTradePrice(payDepositRequest.tradePrice);
|
||||
trade.setTradeAmount(Coin.valueOf(payDepositRequest.tradeAmount));
|
||||
|
||||
// update to the latest peer address of our peer if the payDepositRequest is correct
|
||||
|
|
|
@ -110,6 +110,7 @@ public final class Preferences implements Persistable {
|
|||
private double maxPriceDistanceInPercent;
|
||||
private boolean useInvertedMarketPrice;
|
||||
private boolean useStickyMarketPrice = false;
|
||||
private boolean usePercentageBasedPrice = false;
|
||||
|
||||
// Observable wrappers
|
||||
transient private final StringProperty btcDenominationProperty = new SimpleStringProperty(btcDenomination);
|
||||
|
@ -162,6 +163,7 @@ public final class Preferences implements Persistable {
|
|||
// useTorForBitcoinJ = persisted.getUseTorForBitcoinJ();
|
||||
useTorForBitcoinJ = false;
|
||||
useStickyMarketPrice = persisted.getUseStickyMarketPrice();
|
||||
usePercentageBasedPrice = persisted.getUsePercentageBasedPrice();
|
||||
showOwnOffersInOfferBook = persisted.getShowOwnOffersInOfferBook();
|
||||
maxPriceDistanceInPercent = persisted.getMaxPriceDistanceInPercent();
|
||||
// Backward compatible to version 0.3.6. Can be removed after a while
|
||||
|
@ -368,6 +370,12 @@ public final class Preferences implements Persistable {
|
|||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
public void setUsePercentageBasedPrice(boolean usePercentageBasedPrice) {
|
||||
this.usePercentageBasedPrice = usePercentageBasedPrice;
|
||||
storage.queueUpForSave();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Getter
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -488,6 +496,10 @@ public final class Preferences implements Persistable {
|
|||
return useStickyMarketPrice;
|
||||
}
|
||||
|
||||
public boolean getUsePercentageBasedPrice() {
|
||||
return usePercentageBasedPrice;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Private
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue