mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-31 18:58:51 -04:00
must provide fixed price unless using market price
This commit is contained in:
parent
9c5fdb5d4a
commit
9aa6bbeff6
9 changed files with 40 additions and 34 deletions
|
@ -438,7 +438,7 @@ public class CoreApi {
|
|||
return coreOffersService.getMyOpenOffer(id);
|
||||
}
|
||||
|
||||
public void createAnPlaceOffer(String currencyCode,
|
||||
public void postOffer(String currencyCode,
|
||||
String directionAsString,
|
||||
String priceAsString,
|
||||
boolean useMarketBasedPrice,
|
||||
|
@ -450,7 +450,7 @@ public class CoreApi {
|
|||
String paymentAccountId,
|
||||
Consumer<Offer> resultHandler,
|
||||
ErrorMessageHandler errorMessageHandler) {
|
||||
coreOffersService.createAndPlaceOffer(currencyCode,
|
||||
coreOffersService.postOffer(currencyCode,
|
||||
directionAsString,
|
||||
priceAsString,
|
||||
useMarketBasedPrice,
|
||||
|
|
|
@ -212,7 +212,7 @@ public class CoreOffersService {
|
|||
}
|
||||
|
||||
// Create and place new offer.
|
||||
void createAndPlaceOffer(String currencyCode,
|
||||
void postOffer(String currencyCode,
|
||||
String directionAsString,
|
||||
String priceAsString,
|
||||
boolean useMarketBasedPrice,
|
||||
|
@ -234,7 +234,7 @@ public class CoreOffersService {
|
|||
String upperCaseCurrencyCode = currencyCode.toUpperCase();
|
||||
String offerId = createOfferService.getRandomOfferId();
|
||||
OfferDirection direction = OfferDirection.valueOf(directionAsString.toUpperCase());
|
||||
Price price = Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
|
||||
Price price = priceAsString.isEmpty() ? null : Price.valueOf(upperCaseCurrencyCode, priceStringToLong(priceAsString, upperCaseCurrencyCode));
|
||||
Coin amount = Coin.valueOf(amountAsLong);
|
||||
Coin minAmount = Coin.valueOf(minAmountAsLong);
|
||||
Coin useDefaultTxFee = Coin.ZERO;
|
||||
|
|
|
@ -140,8 +140,8 @@ public class Price extends MonetaryWrapper implements Comparable<Price> {
|
|||
|
||||
public String toFriendlyString() {
|
||||
return monetary instanceof Altcoin ?
|
||||
((Altcoin) monetary).toFriendlyString() + "/BTC" :
|
||||
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "BTC/" + ((Fiat) monetary).currencyCode;
|
||||
((Altcoin) monetary).toFriendlyString() + "/XMR" :
|
||||
((Fiat) monetary).toFriendlyString().replace(((Fiat) monetary).currencyCode, "") + "XMR/" + ((Fiat) monetary).currencyCode;
|
||||
}
|
||||
|
||||
public String toPlainString() {
|
||||
|
|
|
@ -129,7 +129,7 @@ public class CreateOfferService {
|
|||
offerId,
|
||||
currencyCode,
|
||||
direction,
|
||||
price.getValue(),
|
||||
price == null ? null : price.getValue(),
|
||||
useMarketBasedPrice,
|
||||
marketPriceMargin,
|
||||
amount.value,
|
||||
|
@ -138,11 +138,17 @@ public class CreateOfferService {
|
|||
|
||||
long creationTime = new Date().getTime();
|
||||
NodeAddress makerAddress = p2PService.getAddress();
|
||||
boolean useMarketBasedPriceValue = useMarketBasedPrice &&
|
||||
boolean useMarketBasedPriceValue = price == null &&
|
||||
useMarketBasedPrice &&
|
||||
isMarketPriceAvailable(currencyCode) &&
|
||||
!paymentAccount.hasPaymentMethodWithId(HAL_CASH_ID);
|
||||
|
||||
long priceAsLong = price != null && !useMarketBasedPriceValue ? price.getValue() : 0L;
|
||||
// verify price
|
||||
if (price == null && !useMarketBasedPriceValue) {
|
||||
throw new IllegalArgumentException("Must provide fixed price because market price is unavailable");
|
||||
}
|
||||
|
||||
long priceAsLong = price != null ? price.getValue() : 0L;
|
||||
double marketPriceMarginParam = useMarketBasedPriceValue ? marketPriceMargin : 0;
|
||||
long amountAsLong = amount != null ? amount.getValue() : 0L;
|
||||
long minAmountAsLong = minAmount != null ? minAmount.getValue() : 0L;
|
||||
|
|
|
@ -70,8 +70,8 @@ public class ValidateOffer extends Task<PlaceOfferModel> {
|
|||
checkArgument(offer.getAmount().compareTo(offer.getMinAmount()) >= 0, "MinAmount is larger than Amount");
|
||||
|
||||
checkNotNull(offer.getPrice(), "Price is null");
|
||||
checkArgument(offer.getPrice().isPositive(),
|
||||
"Price must be positive. price=" + offer.getPrice().toFriendlyString());
|
||||
if (!offer.isUseMarketBasedPrice()) checkArgument(offer.getPrice().isPositive(),
|
||||
"Price must be positive unless using market based price. price=" + offer.getPrice().toFriendlyString());
|
||||
|
||||
checkArgument(offer.getDate().getTime() > 0,
|
||||
"Date must not be 0. date=" + offer.getDate().toString());
|
||||
|
|
|
@ -27,14 +27,14 @@ public class PriceTest {
|
|||
Price result = Price.parse("USD", "0.1");
|
||||
Assert.assertEquals(
|
||||
"Fiat value should be formatted with two decimals.",
|
||||
"0.10 BTC/USD",
|
||||
"0.10 XMR/USD",
|
||||
result.toFriendlyString()
|
||||
);
|
||||
|
||||
result = Price.parse("EUR", "0.1234");
|
||||
Assert.assertEquals(
|
||||
"Fiat value should be given two decimals",
|
||||
"0.1234 BTC/EUR",
|
||||
"0.1234 XMR/EUR",
|
||||
result.toFriendlyString()
|
||||
);
|
||||
|
||||
|
@ -57,19 +57,19 @@ public class PriceTest {
|
|||
|
||||
Assert.assertEquals(
|
||||
"Comma (',') as decimal separator should be converted to period ('.')",
|
||||
"0.0001 BTC/USD",
|
||||
"0.0001 XMR/USD",
|
||||
Price.parse("USD", "0,0001").toFriendlyString()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
"Too many decimals should get rounded up properly.",
|
||||
"10000.2346 LTC/BTC",
|
||||
"10000.2346 LTC/XMR",
|
||||
Price.parse("LTC", "10000,23456789").toFriendlyString()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
"Too many decimals should get rounded down properly.",
|
||||
"10000.2345 LTC/BTC",
|
||||
"10000.2345 LTC/XMR",
|
||||
Price.parse("LTC", "10000,23454999").toFriendlyString()
|
||||
);
|
||||
|
||||
|
@ -95,14 +95,14 @@ public class PriceTest {
|
|||
Price result = Price.valueOf("USD", 1);
|
||||
Assert.assertEquals(
|
||||
"Fiat value should have four decimals.",
|
||||
"0.0001 BTC/USD",
|
||||
"0.0001 XMR/USD",
|
||||
result.toFriendlyString()
|
||||
);
|
||||
|
||||
result = Price.valueOf("EUR", 1234);
|
||||
Assert.assertEquals(
|
||||
"Fiat value should be given two decimals",
|
||||
"0.1234 BTC/EUR",
|
||||
"0.1234 XMR/EUR",
|
||||
result.toFriendlyString()
|
||||
);
|
||||
|
||||
|
@ -114,13 +114,13 @@ public class PriceTest {
|
|||
|
||||
Assert.assertEquals(
|
||||
"Too many decimals should get rounded up properly.",
|
||||
"10000.2346 LTC/BTC",
|
||||
"10000.2346 LTC/XMR",
|
||||
Price.valueOf("LTC", 1000023456789L).toFriendlyString()
|
||||
);
|
||||
|
||||
Assert.assertEquals(
|
||||
"Too many decimals should get rounded down properly.",
|
||||
"10000.2345 LTC/BTC",
|
||||
"10000.2345 LTC/XMR",
|
||||
Price.valueOf("LTC", 1000023454999L).toFriendlyString()
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue