diff --git a/java-examples/src/main/java/bisq/bots/BotUtils.java b/java-examples/src/main/java/bisq/bots/BotUtils.java index 98ae329..89d43af 100644 --- a/java-examples/src/main/java/bisq/bots/BotUtils.java +++ b/java-examples/src/main/java/bisq/bots/BotUtils.java @@ -72,7 +72,7 @@ public class BotUtils { public static BigDecimal calcTargetPrice(BigDecimal targetMarketPriceMargin, BigDecimal currentMarketPrice, String currencyCode) { - if (!isZero.test(targetMarketPriceMargin) && targetMarketPriceMargin.precision() <= 2) + if (!isZero.test(targetMarketPriceMargin) && targetMarketPriceMargin.precision() < 2) throw new IllegalArgumentException( format("Price margin percent literal argument %s is invalid;" + " it must have a precision of at least 2 decimal places.", @@ -133,12 +133,13 @@ public class BotUtils { return diff.subtract(factor); }; + /** - * Return true if the margin price based offer's market price margin (%) >= minMarketPriceMargin (%). + * Return true if the offer's margin based price >= target price. */ - public static final BiPredicate isMarginGEMinMarketPriceMargin = - (offer, minMarketPriceMargin) -> offer.getUseMarketBasedPrice() - && offer.getMarketPriceMarginPct() >= minMarketPriceMargin.doubleValue(); + public static final BiPredicate isMarginBasedPriceGETargetPrice = + (offer, targetPrice) -> offer.getUseMarketBasedPrice() + && new BigDecimal(offer.getPrice()).compareTo(targetPrice) >= 0; /** * Return true if the margin price based offer's market price margin (%) <= maxMarketPriceMargin (%). diff --git a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java index 31b2f93..030c9ae 100644 --- a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java +++ b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToBuyBtc.java @@ -37,7 +37,7 @@ import static protobuf.OfferDirection.SELL; /** * The TakeBestPricedOfferToBuyBtc bot waits for attractively priced BUY BTC offers to appear, takes the offers - * (up to a maximum of configured {@link #maxTakeOffers}, then shuts down both the API daemon and itself (the bot), + * (up to a maximum of configured {@link #maxTakeOffers}), then shuts down both the API daemon and itself (the bot), * to allow the user to start the desktop UI application and complete the trades. *

* The benefit this bot provides is freeing up the user time spent watching the offer book in the UI, waiting for the @@ -368,14 +368,14 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot { return offers.stream() .filter(o -> usesSamePaymentMethod.test(o, getPaymentAccount())) .filter(isMakerPreferredTradingPeer) - .filter(o -> isMarginGEMinMarketPriceMargin.test(o, minMarketPriceMargin) + .filter(o -> isMarginBasedPriceGETargetPrice.test(o, targetPrice) || isFixedPriceGEMinMarketPriceMargin.test(o, currentMarketPrice)) .filter(isWithinBTCAmountBounds) .findFirst(); else return offers.stream() .filter(o -> usesSamePaymentMethod.test(o, getPaymentAccount())) - .filter(o -> isMarginGEMinMarketPriceMargin.test(o, minMarketPriceMargin) + .filter(o -> isMarginBasedPriceGETargetPrice.test(o, targetPrice) || isFixedPriceGEMinMarketPriceMargin.test(o, currentMarketPrice)) .filter(isWithinBTCAmountBounds) .findFirst(); @@ -388,7 +388,7 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot { currentMarketPrice, isXmr.test(currencyCode) ? "BTC" : currencyCode); } else { - log.info("Looking for offers to {}, priced at or more than {}% {} from the current market price {} {}.", + log.info("Looking for offers to {}, priced at or more than {}% {} the current market price {} {}.", marketDescription.get(), minMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below". aboveOrBelowMarketPrice.apply(minMarketPriceMargin), @@ -419,12 +419,12 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot { iHavePreferredTradingPeers.get() ? isMakerPreferredTradingPeer.test(offer) ? "YES" : "NO" : "N/A"); - var marginPriceLabel = format("Is offer's price margin (%s%%) >= bot's min market price margin (%s%%)?", - offer.getMarketPriceMarginPct(), - minMarketPriceMargin); + var marginPriceLabel = format("Is offer's margin based price (%s) >= bot's target price (%s)?", + offer.getUseMarketBasedPrice() ? offer.getPrice() : "N/A", + offer.getUseMarketBasedPrice() ? targetPrice : "N/A"); filterResultsByLabel.put(marginPriceLabel, offer.getUseMarketBasedPrice() - ? isMarginGEMinMarketPriceMargin.test(offer, minMarketPriceMargin) + ? isMarginBasedPriceGETargetPrice.test(offer, targetPrice) : "N/A"); var fixedPriceLabel = format("Is offer's fixed-price (%s) >= bot's target price (%s)?", offer.getUseMarketBasedPrice() ? "N/A" : offer.getPrice() + " " + currencyCode, diff --git a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java index 48e2454..c34a5ec 100644 --- a/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java +++ b/java-examples/src/main/java/bisq/bots/TakeBestPricedOfferToSellBtc.java @@ -37,7 +37,7 @@ import static protobuf.OfferDirection.SELL; /** * The TakeBestPricedOfferToSellBtc bot waits for attractively priced SELL BTC offers to appear, takes the offers - * (up to a maximum of configured {@link #maxTakeOffers}, then shuts down both the API daemon and itself (the bot), + * (up to a maximum of configured {@link #maxTakeOffers}), then shuts down both the API daemon and itself (the bot), * to allow the user to start the desktop UI application and complete the trades. *

* The benefit this bot provides is freeing up the user time spent watching the offer book in the UI, waiting for the @@ -388,7 +388,7 @@ public class TakeBestPricedOfferToSellBtc extends AbstractBot { currentMarketPrice, isXmr.test(currencyCode) ? "BTC" : currencyCode); } else { - log.info("Looking for offers to {}, priced at or less than {}% {} from the current market price {} {}.", + log.info("Looking for offers to {}, priced at or less than {}% {} the current market price {} {}.", marketDescription.get(), maxMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below". aboveOrBelowMarketPrice.apply(maxMarketPriceMargin),