Tidy up and javadoc the TakeBestPricedOfferToSellXmr bot

This commit is contained in:
ghubstan 2022-06-29 19:28:13 -03:00
parent a355138b47
commit 195b62c477
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
2 changed files with 25 additions and 17 deletions

View File

@ -33,12 +33,12 @@ import static protobuf.OfferDirection.BUY;
/** /**
* This bot's general use case is to buy XMR with BTC at a low BTC price. It periodically checks the Sell XMR (Buy BTC) * This bot's general use case is to buy XMR with BTC at a low BTC price. It periodically checks the Sell XMR (Buy BTC)
* market, and takes a configured number of offers to sell you XMR according to criteria you define in the bot's * market, and takes a configured maximum number of offers to sell you XMR according to criteria you define in the bot's
* configuration file TakeBestPricedOfferToSellXmr.properties (located in project's src/main/resources directory). * configuration file: TakeBestPricedOfferToSellXmr.properties (located in project's src/main/resources directory).
* You will need to replace the default values in the configuration file for your use cases. * You will need to replace the default values in the configuration file for your use cases.
* <p><br/> * <p><br/>
* After the maximum number of offers have been taken (good to start with 1), the bot will shut down the API daemon, * After the maximum number of offers have been taken (good to start with 1), the bot will shut down the API daemon,
* then the bot itself. You have to confirm the offer maker's XMR payment(s) offline, then complete the trade(s) in * then itself. You have to confirm the offer maker's XMR payment(s) outside Bisq, then complete the trade(s) in
* the <a href="https://bisq.network">Bisq Desktop</a> application. * the <a href="https://bisq.network">Bisq Desktop</a> application.
* <p> * <p>
* Here is one possible use case: * Here is one possible use case:
@ -60,9 +60,13 @@ import static protobuf.OfferDirection.BUY;
* </pre> * </pre>
* <b>Usage</b> * <b>Usage</b>
* <p><br/> * <p><br/>
* You must encrypt your wallet password before running this bot. If it is not already, you can use the CLI:
* <pre>
* $ ./bisq-cli --password=xyz --port=9998 setwalletpassword --wallet-password="be careful"
* </pre>
* There are some {@link bisq.bots.Config program options} common to all the Java bot examples, passed on the command * There are some {@link bisq.bots.Config program options} common to all the Java bot examples, passed on the command
* line. The only one required every time the bot is run is your API daemon's password option: `--password <String>`. * line. The only one you must provide (no default value) is your API daemon's password option:
* The bot will prompt you for your wallet-password in the console. * `--password <String>`. The bot will prompt you for your wallet-password in the console.
* <p><br/> * <p><br/>
* You can pass the '--dryrun=true' option to the program to see what offers your bot <i>would take</i> with a given * You can pass the '--dryrun=true' option to the program to see what offers your bot <i>would take</i> with a given
* configuration. This will help you avoid taking offers by mistake. * configuration. This will help you avoid taking offers by mistake.
@ -169,7 +173,6 @@ public class TakeBestPricedOfferToSellXmr extends AbstractBot {
takeCriteria.printOfferAgainstCriteria(cheapestOffer); takeCriteria.printOfferAgainstCriteria(cheapestOffer);
}); });
printDryRunProgress();
runCountdown(log, pollingInterval); runCountdown(log, pollingInterval);
pingDaemon(startTime); pingDaemon(startTime);
} }
@ -183,16 +186,21 @@ public class TakeBestPricedOfferToSellXmr extends AbstractBot {
private void takeOffer(TakeCriteria takeCriteria, OfferInfo offer) { private void takeOffer(TakeCriteria takeCriteria, OfferInfo offer) {
log.info("Will attempt to take offer '{}'.", offer.getId()); log.info("Will attempt to take offer '{}'.", offer.getId());
takeCriteria.printOfferAgainstCriteria(offer); takeCriteria.printOfferAgainstCriteria(offer);
// An encrypted wallet must be unlocked before calling takeoffer and gettrade(s).
// Unlock the wallet for 5 minutes. If the wallet is already unlocked, this request
// will override the timeout of the previous unlock request.
try {
unlockWallet(walletPassword, 300);
} catch (NonFatalException nonFatalException) {
handleNonFatalException(nonFatalException, pollingInterval);
}
if (isDryRun) { if (isDryRun) {
addToOffersTaken(offer); addToOffersTaken(offer);
numOffersTaken++; numOffersTaken++;
maybeShutdownAfterSuccessfulTradeCreation(numOffersTaken, maxTakeOffers);
} else { } else {
// An encrypted wallet must be unlocked before calling takeoffer and gettrade.
// Unlock the wallet for 5 minutes. If the wallet is already unlocked,
// this command will override the timeout of the previous unlock command.
try { try {
unlockWallet(walletPassword, 600);
printBTCBalances("BTC Balances Before Take Offer Attempt"); printBTCBalances("BTC Balances Before Take Offer Attempt");
// Blocks until new trade is prepared, or times out. // Blocks until new trade is prepared, or times out.
takeV1ProtocolOffer(offer, paymentAccount, bisqTradeFeeCurrency, pollingInterval); takeV1ProtocolOffer(offer, paymentAccount, bisqTradeFeeCurrency, pollingInterval);
@ -207,12 +215,12 @@ public class TakeBestPricedOfferToSellXmr extends AbstractBot {
printBTCBalances("BTC Balances After Simulated Trade Completion"); printBTCBalances("BTC Balances After Simulated Trade Completion");
} }
numOffersTaken++; numOffersTaken++;
maybeShutdownAfterSuccessfulTradeCreation(numOffersTaken, maxTakeOffers);
} catch (NonFatalException nonFatalException) { } catch (NonFatalException nonFatalException) {
handleNonFatalException(nonFatalException, pollingInterval); handleNonFatalException(nonFatalException, pollingInterval);
} catch (StatusRuntimeException fatalException) { } catch (StatusRuntimeException fatalException) {
shutdownAfterTakeOfferFailure(fatalException); shutdownAfterTakeOfferFailure(fatalException);
} }
maybeShutdownAfterSuccessfulTradeCreation(numOffersTaken, maxTakeOffers);
} }
} }

View File

@ -1,17 +1,17 @@
# Maximum # of offers to take during one bot session. When reached, bot will shut down (but not the API daemon). # Maximum # of offers to take during one bot session. When reached, bot will shut down (but not the API daemon).
maxTakeOffers=1 maxTakeOffers=2
# #
# Taker bot's payment account id. Only SELL BTC offers using the same payment method will be considered for taking. # Taker bot's payment account id. Only SELL BTC offers using the same payment method will be considered for taking.
paymentAccountId=a15d0f15-e355-4b89-8322-e262097623ae paymentAccountId=fafeec6e-fb95-4ff5-a537-ea7e9d1ad683
# #
# Taker bot's max market price margin. A candidate buy BTC offer's price margin must be <= maxMarketPriceMargin. # Taker bot's max market price margin. A candidate buy BTC offer's price margin must be <= maxMarketPriceMargin.
maxMarketPriceMargin=1.10 maxMarketPriceMargin=1
# #
# Taker bot's min BTC amount to buy. The candidate buy BTC offer's amount must be >= minAmount BTC. # Taker bot's min BTC amount to buy. The candidate buy BTC offer's amount must be >= minAmount BTC.
minAmount=0.01 minAmount=0.01
# #
# Taker bot's max BTC amount to buy. The candidate buy BTC offer's amount must be <= maxAmount BTC. # Taker bot's max BTC amount to buy. The candidate buy BTC offer's amount must be <= maxAmount BTC.
maxAmount=0.90 maxAmount=1.00
# #
# Taker bot's max acceptable transaction fee rate (sats / byte). # Taker bot's max acceptable transaction fee rate (sats / byte).
# Regtest fee rates are from https://price.bisq.wiz.biz/getFees # Regtest fee rates are from https://price.bisq.wiz.biz/getFees
@ -25,4 +25,4 @@ bisqTradeFeeCurrency=BSQ
preferredTradingPeers=localhost:8888 preferredTradingPeers=localhost:8888
# #
# Offer polling frequency must be >= 1s (1000ms) between each getoffers request. # Offer polling frequency must be >= 1s (1000ms) between each getoffers request.
pollingInterval=30000 pollingInterval=60000