diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index cf70886d2d..361fb1daa3 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -344,8 +344,8 @@ public class CliMain { var minAmount = toSatoshis(opts.getMinAmount()); var useMarketBasedPrice = opts.isUsingMktPriceMargin(); var fixedPrice = opts.getFixedPrice(); - var marketPriceMargin = opts.getMktPriceMarginAsBigDecimal(); - var securityDepositPct = isSwap ? 0.00 : opts.getSecurityDepositPct(); + var marketPriceMarginPct = opts.getMktPriceMarginPct(); + var securityDepositPct = isSwap ? 0.00d : opts.getSecurityDepositPct(); var makerFeeCurrencyCode = opts.getMakerFeeCurrencyCode(); var triggerPrice = "0"; // Cannot be defined until the new offer is added to book. OfferInfo offer; @@ -361,7 +361,7 @@ public class CliMain { minAmount, useMarketBasedPrice, fixedPrice, - marketPriceMargin.doubleValue(), + marketPriceMarginPct, securityDepositPct, paymentAcctId, makerFeeCurrencyCode, diff --git a/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java b/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java index fab316f63d..40881891c8 100644 --- a/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java +++ b/cli/src/main/java/bisq/cli/opts/CreateOfferOptionParser.java @@ -20,8 +20,6 @@ package bisq.cli.opts; import joptsimple.OptionSpec; -import java.math.BigDecimal; - import static bisq.cli.opts.OptLabel.*; import static java.lang.Boolean.FALSE; import static joptsimple.internal.Strings.EMPTY; @@ -45,7 +43,7 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen final OptionSpec minAmountOpt = parser.accepts(OPT_MIN_AMOUNT, "minimum amount of btc to buy or sell") .withOptionalArg(); - final OptionSpec mktPriceMarginOpt = parser.accepts(OPT_MKT_PRICE_MARGIN, "market btc price margin (%)") + final OptionSpec mktPriceMarginPctOpt = parser.accepts(OPT_MKT_PRICE_MARGIN, "market btc price margin (%)") .withOptionalArg() .defaultsTo("0.00"); @@ -92,7 +90,7 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen if (options.has(paymentAccountIdOpt)) throw new IllegalArgumentException("cannot use a payment account id in bsq swap offer"); - if (options.has(mktPriceMarginOpt)) + if (options.has(mktPriceMarginPctOpt)) throw new IllegalArgumentException("cannot use a market price margin in bsq swap offer"); if (options.has(securityDepositPctOpt)) @@ -105,11 +103,16 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen if (!options.has(paymentAccountIdOpt) || options.valueOf(paymentAccountIdOpt).isEmpty()) throw new IllegalArgumentException("no payment account id specified"); - if (!options.has(mktPriceMarginOpt) && !options.has(fixedPriceOpt)) + if (!options.has(mktPriceMarginPctOpt) && !options.has(fixedPriceOpt)) throw new IllegalArgumentException("no market price margin or fixed price specified"); - if (options.has(mktPriceMarginOpt) && options.valueOf(mktPriceMarginOpt).isEmpty()) - throw new IllegalArgumentException("no market price margin specified"); + if (options.has(mktPriceMarginPctOpt)) { + var mktPriceMarginPctString = options.valueOf(mktPriceMarginPctOpt); + if (mktPriceMarginPctString.isEmpty()) + throw new IllegalArgumentException("no market price margin specified"); + else + verifyStringIsValidDouble(mktPriceMarginPctString); + } if (options.has(fixedPriceOpt) && options.valueOf(fixedPriceOpt).isEmpty()) throw new IllegalArgumentException("no fixed price specified"); @@ -144,16 +147,11 @@ public class CreateOfferOptionParser extends AbstractMethodOptionParser implemen } public boolean isUsingMktPriceMargin() { - return options.has(mktPriceMarginOpt); + return options.has(mktPriceMarginPctOpt); } - @SuppressWarnings("unused") - public String getMktPriceMargin() { - return isUsingMktPriceMargin() ? options.valueOf(mktPriceMarginOpt) : "0.00"; - } - - public BigDecimal getMktPriceMarginAsBigDecimal() { - return isUsingMktPriceMargin() ? new BigDecimal(options.valueOf(mktPriceMarginOpt)) : BigDecimal.ZERO; + public double getMktPriceMarginPct() { + return isUsingMktPriceMargin() ? Double.parseDouble(options.valueOf(mktPriceMarginPctOpt)) : 0.00d; } public String getFixedPrice() { diff --git a/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java b/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java index 70b004eb03..562214bdaf 100644 --- a/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java +++ b/cli/src/test/java/bisq/cli/opts/OptionParsersTest.java @@ -126,7 +126,7 @@ public class OptionParsersTest { "--" + OPT_DIRECTION + "=" + "BUY", "--" + OPT_CURRENCY_CODE + "=" + "EUR", "--" + OPT_AMOUNT + "=" + "0.125", - "--" + OPT_MKT_PRICE_MARGIN + "=" + "0.0", + "--" + OPT_MKT_PRICE_MARGIN + "=" + "3.15", "--" + OPT_SECURITY_DEPOSIT + "=" + "25.0" }; CreateOfferOptionParser parser = new CreateOfferOptionParser(args).parse(); @@ -134,7 +134,7 @@ public class OptionParsersTest { assertEquals("BUY", parser.getDirection()); assertEquals("EUR", parser.getCurrencyCode()); assertEquals("0.125", parser.getAmount()); - assertEquals("0.0", parser.getMktPriceMargin()); + assertEquals(3.15d, parser.getMktPriceMarginPct()); assertEquals(25.0, parser.getSecurityDepositPct()); }