mirror of
https://github.com/bisq-network/bisq-api-reference.git
synced 2026-05-22 12:44:21 +00:00
Merge pull request #7 from ghubstan/fix-bugs-related-to-margin-config
Fix bugs related to margin config
This commit is contained in:
commit
b0e36c3359
@ -72,7 +72,7 @@ public class BotUtils {
|
|||||||
public static BigDecimal calcTargetPrice(BigDecimal targetMarketPriceMargin,
|
public static BigDecimal calcTargetPrice(BigDecimal targetMarketPriceMargin,
|
||||||
BigDecimal currentMarketPrice,
|
BigDecimal currentMarketPrice,
|
||||||
String currencyCode) {
|
String currencyCode) {
|
||||||
if (!isZero.test(targetMarketPriceMargin) && targetMarketPriceMargin.precision() <= 2)
|
if (!isZero.test(targetMarketPriceMargin) && targetMarketPriceMargin.precision() < 2)
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
format("Price margin percent literal argument %s is invalid;"
|
format("Price margin percent literal argument %s is invalid;"
|
||||||
+ " it must have a precision of at least 2 decimal places.",
|
+ " it must have a precision of at least 2 decimal places.",
|
||||||
@ -133,12 +133,13 @@ public class BotUtils {
|
|||||||
return diff.subtract(factor);
|
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<OfferInfo, BigDecimal> isMarginGEMinMarketPriceMargin =
|
public static final BiPredicate<OfferInfo, BigDecimal> isMarginBasedPriceGETargetPrice =
|
||||||
(offer, minMarketPriceMargin) -> offer.getUseMarketBasedPrice()
|
(offer, targetPrice) -> offer.getUseMarketBasedPrice()
|
||||||
&& offer.getMarketPriceMarginPct() >= minMarketPriceMargin.doubleValue();
|
&& new BigDecimal(offer.getPrice()).compareTo(targetPrice) >= 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return true if the margin price based offer's market price margin (%) <= maxMarketPriceMargin (%).
|
* Return true if the margin price based offer's market price margin (%) <= maxMarketPriceMargin (%).
|
||||||
|
|||||||
@ -307,12 +307,19 @@ public class TakeBestPricedOfferToBuyBsq extends AbstractBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printCriteriaSummary() {
|
void printCriteriaSummary() {
|
||||||
log.info("Looking for offers to {}, with a fixed-price at or greater than"
|
if (isZero.test(minMarketPriceMargin)) {
|
||||||
+ " {}% {} the 30-day average BSQ trade price of {} BTC.",
|
log.info("Looking for offers to {}, with a fixed-price at or greater than"
|
||||||
MARKET_DESCRIPTION,
|
+ " the 30-day average BSQ trade price of {} BTC.",
|
||||||
minMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below".
|
MARKET_DESCRIPTION,
|
||||||
aboveOrBelowMarketPrice.apply(minMarketPriceMargin),
|
avgBsqPrice);
|
||||||
avgBsqPrice);
|
} else {
|
||||||
|
log.info("Looking for offers to {}, with a fixed-price at or greater than"
|
||||||
|
+ " {}% {} the 30-day average BSQ trade price of {} BTC.",
|
||||||
|
MARKET_DESCRIPTION,
|
||||||
|
minMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below".
|
||||||
|
aboveOrBelowMarketPrice.apply(minMarketPriceMargin),
|
||||||
|
avgBsqPrice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
||||||
|
|||||||
@ -37,7 +37,7 @@ import static protobuf.OfferDirection.SELL;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The TakeBestPricedOfferToBuyBtc bot waits for attractively priced BUY BTC offers to appear, takes the offers
|
* 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.
|
* to allow the user to start the desktop UI application and complete the trades.
|
||||||
* <p>
|
* <p>
|
||||||
* The benefit this bot provides is freeing up the user time spent watching the offer book in the UI, waiting for the
|
* The benefit this bot provides is freeing up the user time spent watching the offer book in the UI, waiting for the
|
||||||
@ -368,26 +368,33 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot {
|
|||||||
return offers.stream()
|
return offers.stream()
|
||||||
.filter(o -> usesSamePaymentMethod.test(o, getPaymentAccount()))
|
.filter(o -> usesSamePaymentMethod.test(o, getPaymentAccount()))
|
||||||
.filter(isMakerPreferredTradingPeer)
|
.filter(isMakerPreferredTradingPeer)
|
||||||
.filter(o -> isMarginGEMinMarketPriceMargin.test(o, minMarketPriceMargin)
|
.filter(o -> isMarginBasedPriceGETargetPrice.test(o, targetPrice)
|
||||||
|| isFixedPriceGEMinMarketPriceMargin.test(o, currentMarketPrice))
|
|| isFixedPriceGEMinMarketPriceMargin.test(o, currentMarketPrice))
|
||||||
.filter(isWithinBTCAmountBounds)
|
.filter(isWithinBTCAmountBounds)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
else
|
else
|
||||||
return offers.stream()
|
return offers.stream()
|
||||||
.filter(o -> usesSamePaymentMethod.test(o, getPaymentAccount()))
|
.filter(o -> usesSamePaymentMethod.test(o, getPaymentAccount()))
|
||||||
.filter(o -> isMarginGEMinMarketPriceMargin.test(o, minMarketPriceMargin)
|
.filter(o -> isMarginBasedPriceGETargetPrice.test(o, targetPrice)
|
||||||
|| isFixedPriceGEMinMarketPriceMargin.test(o, currentMarketPrice))
|
|| isFixedPriceGEMinMarketPriceMargin.test(o, currentMarketPrice))
|
||||||
.filter(isWithinBTCAmountBounds)
|
.filter(isWithinBTCAmountBounds)
|
||||||
.findFirst();
|
.findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
void printCriteriaSummary() {
|
void printCriteriaSummary() {
|
||||||
log.info("Looking for offers to {}, priced at or more than {}% {} the current market price {} {}.",
|
if (isZero.test(minMarketPriceMargin)) {
|
||||||
marketDescription.get(),
|
log.info("Looking for offers to {}, priced at or higher than the current market price {} {}.",
|
||||||
minMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below".
|
marketDescription.get(),
|
||||||
aboveOrBelowMarketPrice.apply(minMarketPriceMargin),
|
currentMarketPrice,
|
||||||
currentMarketPrice,
|
isXmr.test(currencyCode) ? "BTC" : currencyCode);
|
||||||
isXmr.test(currencyCode) ? "BTC" : currencyCode);
|
} else {
|
||||||
|
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),
|
||||||
|
currentMarketPrice,
|
||||||
|
isXmr.test(currencyCode) ? "BTC" : currencyCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
||||||
@ -412,12 +419,12 @@ public class TakeBestPricedOfferToBuyBtc extends AbstractBot {
|
|||||||
iHavePreferredTradingPeers.get()
|
iHavePreferredTradingPeers.get()
|
||||||
? isMakerPreferredTradingPeer.test(offer) ? "YES" : "NO"
|
? isMakerPreferredTradingPeer.test(offer) ? "YES" : "NO"
|
||||||
: "N/A");
|
: "N/A");
|
||||||
var marginPriceLabel = format("Is offer's price margin (%s%%) >= bot's min market price margin (%s%%)?",
|
var marginPriceLabel = format("Is offer's margin based price (%s) >= bot's target price (%s)?",
|
||||||
offer.getMarketPriceMarginPct(),
|
offer.getUseMarketBasedPrice() ? offer.getPrice() : "N/A",
|
||||||
minMarketPriceMargin);
|
offer.getUseMarketBasedPrice() ? targetPrice : "N/A");
|
||||||
filterResultsByLabel.put(marginPriceLabel,
|
filterResultsByLabel.put(marginPriceLabel,
|
||||||
offer.getUseMarketBasedPrice()
|
offer.getUseMarketBasedPrice()
|
||||||
? isMarginGEMinMarketPriceMargin.test(offer, minMarketPriceMargin)
|
? isMarginBasedPriceGETargetPrice.test(offer, targetPrice)
|
||||||
: "N/A");
|
: "N/A");
|
||||||
var fixedPriceLabel = format("Is offer's fixed-price (%s) >= bot's target price (%s)?",
|
var fixedPriceLabel = format("Is offer's fixed-price (%s) >= bot's target price (%s)?",
|
||||||
offer.getUseMarketBasedPrice() ? "N/A" : offer.getPrice() + " " + currencyCode,
|
offer.getUseMarketBasedPrice() ? "N/A" : offer.getPrice() + " " + currencyCode,
|
||||||
|
|||||||
@ -308,15 +308,21 @@ public class TakeBestPricedOfferToSellBsq extends AbstractBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printCriteriaSummary() {
|
void printCriteriaSummary() {
|
||||||
log.info("Looking for offers to {}, with a fixed-price at or less than"
|
if (isZero.test(maxMarketPriceMargin)) {
|
||||||
+ " {}% {} the 30-day average BSQ trade price of {} BTC.",
|
log.info("Looking for offers to {}, with a fixed-price at or less than"
|
||||||
MARKET_DESCRIPTION,
|
+ " the 30-day average BSQ trade price of {} BTC.",
|
||||||
maxMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below".
|
MARKET_DESCRIPTION,
|
||||||
aboveOrBelowMarketPrice.apply(maxMarketPriceMargin),
|
avgBsqPrice);
|
||||||
avgBsqPrice);
|
} else {
|
||||||
|
log.info("Looking for offers to {}, with a fixed-price at or less than"
|
||||||
|
+ " {}% {} the 30-day average BSQ trade price of {} BTC.",
|
||||||
|
MARKET_DESCRIPTION,
|
||||||
|
maxMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below".
|
||||||
|
aboveOrBelowMarketPrice.apply(maxMarketPriceMargin),
|
||||||
|
avgBsqPrice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
||||||
log.info("Currently available {} offers -- want to take BSQ swap offer with fixed-price <= {} BTC.",
|
log.info("Currently available {} offers -- want to take BSQ swap offer with fixed-price <= {} BTC.",
|
||||||
MARKET_DESCRIPTION,
|
MARKET_DESCRIPTION,
|
||||||
|
|||||||
@ -37,7 +37,7 @@ import static protobuf.OfferDirection.SELL;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The TakeBestPricedOfferToSellBtc bot waits for attractively priced SELL BTC offers to appear, takes the offers
|
* 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.
|
* to allow the user to start the desktop UI application and complete the trades.
|
||||||
* <p>
|
* <p>
|
||||||
* The benefit this bot provides is freeing up the user time spent watching the offer book in the UI, waiting for the
|
* The benefit this bot provides is freeing up the user time spent watching the offer book in the UI, waiting for the
|
||||||
@ -382,12 +382,19 @@ public class TakeBestPricedOfferToSellBtc extends AbstractBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void printCriteriaSummary() {
|
void printCriteriaSummary() {
|
||||||
log.info("Looking for offers to {}, priced at or less than {}% {} the current market price {} {}.",
|
if (isZero.test(maxMarketPriceMargin)) {
|
||||||
marketDescription.get(),
|
log.info("Looking for offers to {}, priced at or lower than the current market price {} {}.",
|
||||||
maxMarketPriceMargin.abs(), // Hide the sign, text explains target price % "above or below".
|
marketDescription.get(),
|
||||||
aboveOrBelowMarketPrice.apply(maxMarketPriceMargin),
|
currentMarketPrice,
|
||||||
currentMarketPrice,
|
isXmr.test(currencyCode) ? "BTC" : currencyCode);
|
||||||
isXmr.test(currencyCode) ? "BTC" : currencyCode);
|
} else {
|
||||||
|
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),
|
||||||
|
currentMarketPrice,
|
||||||
|
isXmr.test(currencyCode) ? "BTC" : currencyCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
void printOffersAgainstCriteria(List<OfferInfo> offers) {
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
#
|
#
|
||||||
# Maximum # of offers to take during one bot session. When reached, bot will shut down API daemon then itself.
|
# Maximum # of offers to take during one bot session. When reached, bot will shut down API daemon then itself.
|
||||||
maxTakeOffers=10
|
maxTakeOffers=1
|
||||||
#
|
#
|
||||||
# Taker bot's payment account id. Only BUY BTC offers using the same payment method will be considered for taking.
|
# Taker bot's payment account id. Only BUY BTC offers using the same payment method will be considered for taking.
|
||||||
paymentAccountId=9ad3cc7a-7d32-453c-b9db-a3714b5b8f61
|
paymentAccountId=28030c83-f07d-4f0b-b824-019529279630
|
||||||
#
|
#
|
||||||
# Taker bot's min market price margin. A candidate BUY BTC offer's price margin must be >= minMarketPriceMargin.
|
# Taker bot's min market price margin. A candidate BUY BTC offer's price margin must be >= minMarketPriceMargin.
|
||||||
#
|
#
|
||||||
minMarketPriceMargin=1.00
|
minMarketPriceMargin=0
|
||||||
#
|
#
|
||||||
# Taker bot's min BTC amount to sell. The candidate BUY offer's amount must be >= minAmount BTC.
|
# Taker bot's min BTC amount to sell. The candidate BUY offer's amount must be >= minAmount BTC.
|
||||||
minAmount=0.01
|
minAmount=0.01
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user