mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 07:07:43 +01:00
Change mktPriceMarginOpt name to mktPriceMarginPctOpt
And validate the opt value.
This commit is contained in:
parent
8f93c27deb
commit
23303187be
3 changed files with 18 additions and 20 deletions
|
@ -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,
|
||||
|
|
|
@ -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<String> minAmountOpt = parser.accepts(OPT_MIN_AMOUNT, "minimum amount of btc to buy or sell")
|
||||
.withOptionalArg();
|
||||
|
||||
final OptionSpec<String> mktPriceMarginOpt = parser.accepts(OPT_MKT_PRICE_MARGIN, "market btc price margin (%)")
|
||||
final OptionSpec<String> 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())
|
||||
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() {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue