must provide fixed price unless using market price

This commit is contained in:
woodser 2022-11-26 13:02:07 +00:00
parent 9c5fdb5d4a
commit 9aa6bbeff6
9 changed files with 40 additions and 34 deletions

View file

@ -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,

View file

@ -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;

View file

@ -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() {

View file

@ -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;

View file

@ -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());