From 5538914cf87f194874d5263a7af732d8a8e041ce Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 12:03:06 -0300 Subject: [PATCH 01/40] Add line break --- core/src/main/java/bisq/core/api/CoreApi.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index bfc814c67a6..fb3c8f8a380 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -73,7 +73,8 @@ public class CoreApi { @Inject public CoreApi(Config config, CoreDisputeAgentsService coreDisputeAgentsService, - CoreHelpService coreHelpService, CoreOffersService coreOffersService, + CoreHelpService coreHelpService, + CoreOffersService coreOffersService, CorePaymentAccountsService paymentAccountsService, CorePriceService corePriceService, CoreTradesService coreTradesService, From ef4acc0b732700de2da188180ac772c6201d779a Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 13:44:02 -0300 Subject: [PATCH 02/40] Make opt description generic --- cli/src/main/java/bisq/cli/opts/WithdrawFundsOptionParser.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/src/main/java/bisq/cli/opts/WithdrawFundsOptionParser.java b/cli/src/main/java/bisq/cli/opts/WithdrawFundsOptionParser.java index 382fe2c883a..f47432fa860 100644 --- a/cli/src/main/java/bisq/cli/opts/WithdrawFundsOptionParser.java +++ b/cli/src/main/java/bisq/cli/opts/WithdrawFundsOptionParser.java @@ -27,7 +27,7 @@ public class WithdrawFundsOptionParser extends AbstractMethodOptionParser implements MethodOpts { - final OptionSpec tradeIdOpt = parser.accepts(OPT_TRADE_ID, "id of trade to get") + final OptionSpec tradeIdOpt = parser.accepts(OPT_TRADE_ID, "id of trade") .withRequiredArg() .defaultsTo(EMPTY); From 629f408bdf0b6825c4bf9632bdcd19c5a379ba72 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 13:45:07 -0300 Subject: [PATCH 03/40] Add method help docs --- .../main/resources/help/canceloffer-help.txt | 25 ++++++++++ .../help/confirmpaymentreceived-help.txt | 27 ++++++++++ .../help/confirmpaymentstarted-help.txt | 26 ++++++++++ .../main/resources/help/getmyoffer-help.txt | 25 ++++++++++ .../main/resources/help/getmyoffers-help.txt | 33 ++++++++++++ .../src/main/resources/help/getoffer-help.txt | 26 ++++++++++ .../main/resources/help/getoffers-help.txt | 39 +++++++++++++++ .../src/main/resources/help/gettrade-help.txt | 32 ++++++++++++ .../main/resources/help/keepfunds-help.txt | 31 ++++++++++++ .../resources/help/withdrawfunds-help.txt | 50 +++++++++++++++++++ 10 files changed, 314 insertions(+) create mode 100644 core/src/main/resources/help/canceloffer-help.txt create mode 100644 core/src/main/resources/help/confirmpaymentreceived-help.txt create mode 100644 core/src/main/resources/help/confirmpaymentstarted-help.txt create mode 100644 core/src/main/resources/help/getmyoffer-help.txt create mode 100644 core/src/main/resources/help/getmyoffers-help.txt create mode 100644 core/src/main/resources/help/getoffer-help.txt create mode 100644 core/src/main/resources/help/getoffers-help.txt create mode 100644 core/src/main/resources/help/gettrade-help.txt create mode 100644 core/src/main/resources/help/keepfunds-help.txt create mode 100644 core/src/main/resources/help/withdrawfunds-help.txt diff --git a/core/src/main/resources/help/canceloffer-help.txt b/core/src/main/resources/help/canceloffer-help.txt new file mode 100644 index 00000000000..10627ce7045 --- /dev/null +++ b/core/src/main/resources/help/canceloffer-help.txt @@ -0,0 +1,25 @@ +canceloffer + +NAME +---- +canceloffer - cancel an existing offer to buy or sell BTC + +SYNOPSIS +-------- +canceloffer + --offer-id= + +DESCRIPTION +----------- +Cancel an existing offer. The offer will be removed from other Bisq users' offer views. + +OPTIONS +------- +--offer-id + The ID of the buy or sell offer to cancel. + +EXAMPLES +-------- +To cancel an offer with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea: +$ ./bisq-cli --password=xyz --port=9998 canceloffer -offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea + diff --git a/core/src/main/resources/help/confirmpaymentreceived-help.txt b/core/src/main/resources/help/confirmpaymentreceived-help.txt new file mode 100644 index 00000000000..dc43cba2fa4 --- /dev/null +++ b/core/src/main/resources/help/confirmpaymentreceived-help.txt @@ -0,0 +1,27 @@ +confirmpaymentreceived + +NAME +---- +confirmpaymentreceived - confirm payment has been received + +SYNOPSIS +-------- +confirmpaymentreceived + --trade-id= + +DESCRIPTION +----------- +After the seller receives payment from the BTC buyer, confirmpaymentreceived notifies +the buyer the payment has arrived. The seller can release locked BTC only after the +this confirmation message has been sent. + +OPTIONS +------- +--trade-id + The ID of the trade (the full offer-id). + +EXAMPLES +-------- +A BTC seller has taken an offer with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea, and has recently +received the required fiat payment from the buyer's fiat account: +$ ./bisq-cli --password=xyz --port=9998 confirmpaymentreceived -trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea diff --git a/core/src/main/resources/help/confirmpaymentstarted-help.txt b/core/src/main/resources/help/confirmpaymentstarted-help.txt new file mode 100644 index 00000000000..e266e2ef3e6 --- /dev/null +++ b/core/src/main/resources/help/confirmpaymentstarted-help.txt @@ -0,0 +1,26 @@ +confirmpaymentstarted + +NAME +---- +confirmpaymentstarted - confirm payment has been sent + +SYNOPSIS +-------- +confirmpaymentstarted + --trade-id= + +DESCRIPTION +----------- +After the buyer initiates payment to the BTC seller, confirmpaymentstarted notifies +the seller to begin watching for a funds deposit in her payment account. + +OPTIONS +------- +--trade-id + The ID of the trade (the full offer-id). + +EXAMPLES +-------- +A BTC buyer has taken an offer with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea, and has recently +initiated the required fiat payment to the seller's fiat account: +$ ./bisq-cli --password=xyz --port=9998 confirmpaymentstarted -trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea diff --git a/core/src/main/resources/help/getmyoffer-help.txt b/core/src/main/resources/help/getmyoffer-help.txt new file mode 100644 index 00000000000..4e93e43f1cd --- /dev/null +++ b/core/src/main/resources/help/getmyoffer-help.txt @@ -0,0 +1,25 @@ +getmyoffer + +NAME +---- +getmyoffer - get your offer to buy or sell BTC + +SYNOPSIS +-------- +getmyoffer + --offer-id= + +DESCRIPTION +----------- +List one of your existing offer's details. + +OPTIONS +------- +--offer-id + The ID of your buy or sell offer. + +EXAMPLES +-------- +To view your offer with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea: +$ ./bisq-cli --password=xyz --port=9998 getmyoffer -offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea + diff --git a/core/src/main/resources/help/getmyoffers-help.txt b/core/src/main/resources/help/getmyoffers-help.txt new file mode 100644 index 00000000000..7d2c3d3eb85 --- /dev/null +++ b/core/src/main/resources/help/getmyoffers-help.txt @@ -0,0 +1,33 @@ +getmyoffers + +NAME +---- +getmyoffers - get your own buy or sell BTC offers for a fiat currency + +SYNOPSIS +-------- +getmyoffers + --direction= + --currency-code= + +DESCRIPTION +----------- +List your existing offers for a direction (SELL|BUY) and currency (EUR|GBP|USD|BRL|...). + +OPTIONS +------- +--direction + The direction of the offer (BUY or SELL). + +--currency-code + The three letter code for the fiat used to buy or sell BTC, e.g., EUR, USD, BRL, ... + +EXAMPLES +-------- +List all of your existing BUY offers for BRL: +$ ./bisq-cli --password=xyz --port=9998 getmyoffers --direction=buy --currency-code=brl + +List all of your existing SELL offers for EUR: +$ ./bisq-cli --password=xyz --port=9998 getmyoffers --direction=sell --currency-code=eur + + diff --git a/core/src/main/resources/help/getoffer-help.txt b/core/src/main/resources/help/getoffer-help.txt new file mode 100644 index 00000000000..23056674387 --- /dev/null +++ b/core/src/main/resources/help/getoffer-help.txt @@ -0,0 +1,26 @@ +getoffer + +NAME +---- +getoffer - get an offer to buy or sell BTC + +SYNOPSIS +-------- +getoffer + --offer-id= + +DESCRIPTION +----------- +List an existing offer's details. The offer cannot be one of your own, and be +available for the taking, or it will not be viewable. + +OPTIONS +------- +--offer-id + The ID of the buy or sell offer to view. + +EXAMPLES +-------- +To view an offer with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea: +$ ./bisq-cli --password=xyz --port=9998 getoffer -offer-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea + diff --git a/core/src/main/resources/help/getoffers-help.txt b/core/src/main/resources/help/getoffers-help.txt new file mode 100644 index 00000000000..c76c2dfbda9 --- /dev/null +++ b/core/src/main/resources/help/getoffers-help.txt @@ -0,0 +1,39 @@ +getoffers + +NAME +---- +getoffers - get available buy or sell BTC offers for a fiat currency + +SYNOPSIS +-------- +getoffers + --direction= + --currency-code= + +DESCRIPTION +----------- +List existing offers for a direction (SELL|BUY) and currency (EUR|GBP|USD|BRL|...). +All of the listed offers will be available for the taking because you have a +matching payment account, and none of the offers listed will be one of yours. + +OPTIONS +------- +--direction + The direction of the offer (BUY or SELL). + +--currency-code + The three letter code for the fiat used to buy or sell BTC, e.g., EUR, USD, BRL, ... + +EXAMPLES +-------- +You have one Brazilian Real payment account with a face-to-face payment method type. +To view available offers to BUY BTC with BRL, created by other users with the same +face-to-fact account type: +$ ./bisq-cli --password=xyz --port=9998 getoffers --direction=buy --currency-code=brl + +You have several EUR payment accounts, each with a different payment method type. +To view available offers to SELL BTC with EUR, created by other users having at +least one payment account that matches any of your own: +$ ./bisq-cli --password=xyz --port=9998 getoffers --direction=sell --currency-code=eur + + diff --git a/core/src/main/resources/help/gettrade-help.txt b/core/src/main/resources/help/gettrade-help.txt new file mode 100644 index 00000000000..1c54c96ab58 --- /dev/null +++ b/core/src/main/resources/help/gettrade-help.txt @@ -0,0 +1,32 @@ +gettrade + +NAME +---- +gettrade - get a buy or sell BTC trade + +SYNOPSIS +-------- +gettrade + --trade-id= + [--show-contract=] + +DESCRIPTION +----------- +List details of a trade with the given trade-id. If the trade has not yet been completed, +the details can inform each side of the trade of the current phase of the trade protocol. + +OPTIONS +------- +--trade-id + The ID of the trade (the full offer-id). + +--show-contract + Optionally display the trade's full contract details in json format. The default = false. + +EXAMPLES +-------- +To see the summary of a trade with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea: +$ ./bisq-cli --password=xyz --port=9998 gettrade -trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea + +To see the full contract for a trade with ID 83e8b2e2-51b6-4f39-a748-3ebd29c22aea: +$ ./bisq-cli --password=xyz --port=9998 gettrade -trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea --show-contract=true diff --git a/core/src/main/resources/help/keepfunds-help.txt b/core/src/main/resources/help/keepfunds-help.txt new file mode 100644 index 00000000000..b5739744e8b --- /dev/null +++ b/core/src/main/resources/help/keepfunds-help.txt @@ -0,0 +1,31 @@ +keepfunds + +NAME +---- +keepfunds - keep BTC received during a trade in Bisq wallet + +SYNOPSIS +-------- +keepfunds + --trade-id= + +DESCRIPTION +----------- +A BTC buyer completes the final step in the trade protocol by keeping received BTC in his +Bisq wallet. This step may not seem necessary from the buyer's perspective, but it is +necessary for correct transition of a trade's state to CLOSED, within the Bisq server. + +The alternative way to close out the trade is to sen the received BTC to an external +BTC wallet, using the withdrawfunds command. + +OPTIONS +------- +--trade-id + The ID of the trade (the full offer-id). + +EXAMPLES +-------- +A BTC seller has informed the buyer that fiat payment has been received for trade with ID +83e8b2e2-51b6-4f39-a748-3ebd29c22aea, and locked BTC has been released to the buyer. +The BTC buyer closes out the trade by keeping the received BTC in her Bisq wallet: +$ ./bisq-cli --password=xyz --port=9998 keepfunds -trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea diff --git a/core/src/main/resources/help/withdrawfunds-help.txt b/core/src/main/resources/help/withdrawfunds-help.txt new file mode 100644 index 00000000000..dbef9e277d0 --- /dev/null +++ b/core/src/main/resources/help/withdrawfunds-help.txt @@ -0,0 +1,50 @@ +withdrawfunds + +NAME +---- +withdrawfunds - send BTC received during a trade to an external BTC wallet + +SYNOPSIS +-------- +withdrawfunds + --trade-id= + --address= + [--memo=<"memo">] + +DESCRIPTION +----------- +A BTC buyer completes the final step in the trade protocol by sending received BTC to +an external BTC wallet. + +The alternative way to close out the trade is to keep the received BTC in the Bisq wallet, +using the keepfunds command. + +The buyer needs to complete the trade protocol using the keepfunds or withdrawfunds or command. +This step may not seem necessary from the buyer's perspective, but it is necessary for correct +transition of a trade's state to CLOSED, within the Bisq server. + +OPTIONS +------- +--trade-id + The ID of the trade (the full offer-id). + +--address + The destination btc address for the send btc transaction. + +--memo + An optional memo to be saved with the send btc transaction. + A multi word memo must be enclosed in double quotes. + +EXAMPLES +-------- +A BTC seller has informed the buyer that fiat payment has been received for trade with ID +83e8b2e2-51b6-4f39-a748-3ebd29c22aea, and locked BTC has been released to the buyer. +The BTC buyer closes out the trade by sending the received BTC to an external BTC wallet: +$ ./bisq-cli --password=xyz --port=9998 withdrawfunds -trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \ + --address=2N5J6MyjAsWnashimGiNwoRzUXThsQzRmbv (bitcoin regtest address) + + +A seller sends a trade's BTC proceeds to an external wallet, and includes an optional memo: +$ ./bisq-cli --password=xyz --port=9998 withdrawfunds -trade-id=83e8b2e2-51b6-4f39-a748-3ebd29c22aea \ + --address=2N5J6MyjAsWnashimGiNwoRzUXThsQzRmbv + --memo="note to self" From 03f6c2a4d3b8c9ddd4157ddb93bedd750941aec4 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:04:23 -0300 Subject: [PATCH 04/40] Add method help docs --- .../resources/help/createpaymentacct-help.txt | 46 +++++++++++++++++++ .../resources/help/getaddressbalance-help.txt | 23 ++++++++++ .../main/resources/help/getbalance-help.txt | 30 ++++++++++++ .../help/getpaymentacctform-help.txt | 44 ++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 core/src/main/resources/help/createpaymentacct-help.txt create mode 100644 core/src/main/resources/help/getaddressbalance-help.txt create mode 100644 core/src/main/resources/help/getbalance-help.txt create mode 100644 core/src/main/resources/help/getpaymentacctform-help.txt diff --git a/core/src/main/resources/help/createpaymentacct-help.txt b/core/src/main/resources/help/createpaymentacct-help.txt new file mode 100644 index 00000000000..cdc837f7f15 --- /dev/null +++ b/core/src/main/resources/help/createpaymentacct-help.txt @@ -0,0 +1,46 @@ +createpaymentacct + +NAME +---- +createpaymentacct - create a payment account + +SYNOPSIS +-------- +createpaymentacct + --payment-account-form= + +DESCRIPTION +----------- +Create a Bisq trading account with a payment account form. + +The details of the payment account are defined in a manually edited json file generated +by a getpaymentacctform command, e.g., + + { + "_COMMENTS_": [ + "Do not manually edit the paymentMethodId field.", + "Edit the salt field only if you are recreating a payment account on a new installation and wish to preserve the account age." + ], + "paymentMethodId": "SEPA", + "accountName": "your accountname", + "bic": "your bic", + "country": "your country", + "holderName": "your holdername", + "iban": "your iban", + "salt": "" + } + + +EXAMPLES +-------- +To create a new SEPA payment account, find the payment-method-id for the getpaymentacctform command: +$ ./bisq-cli --password=xyz --port=9998 getpaymentmethods + +Get a new, blank SEPA payment account form: +$ ./bisq-cli --password=xyz --port=9998 getpaymentacctform --payment-method-id=SEPA + +The previous command created a json file named sepa_1610817857085.json. The timestamp +in the file name is to ensure each generated file is uniquely named (you can rename the file). + +Manually edit the json file, and pass the file's path to the createpaymentacct command: +$ ./bisq-cli --password=xyz --port=9998 createpaymentacct --payment-account-form=sepa_1610817857085.json diff --git a/core/src/main/resources/help/getaddressbalance-help.txt b/core/src/main/resources/help/getaddressbalance-help.txt new file mode 100644 index 00000000000..ff8149a285a --- /dev/null +++ b/core/src/main/resources/help/getaddressbalance-help.txt @@ -0,0 +1,23 @@ +getaddressbalance + +NAME +---- +getaddressbalance - get btc address balance + +SYNOPSIS +-------- +getaddressbalance + --address= + +DESCRIPTION +----------- +Returns the balance of a BTC address in the Bisq server's wallet. + +OPTIONS +------- +--address= + The BTC address. + +EXAMPLES +-------- +$ ./bisq-cli --password=xyz --port=9998 getaddressbalance -address=bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 diff --git a/core/src/main/resources/help/getbalance-help.txt b/core/src/main/resources/help/getbalance-help.txt new file mode 100644 index 00000000000..52e27e8de98 --- /dev/null +++ b/core/src/main/resources/help/getbalance-help.txt @@ -0,0 +1,30 @@ +getbalance + +NAME +---- +getbalance - get wallet balance(s) + +SYNOPSIS +-------- +getbalance + [--currency-code=] + +DESCRIPTION +----------- +Returns full balance information for Bisq BSQ and/or BTC wallets. + +OPTIONS +------- +--currency-code= + The three letter Bisq wallet crypto currency code. + +EXAMPLES +-------- +Show full BSQ and BTC wallet balance information: +$ ./bisq-cli --password=xyz --port=9998 getbalance + +Show full BSQ wallet balance information: +$ ./bisq-cli --password=xyz --port=9998 getbalance --currency-code=bsq + +Show full BTC wallet balance information: +$ ./bisq-cli --password=xyz --port=9998 getbalance --currency-code=btc diff --git a/core/src/main/resources/help/getpaymentacctform-help.txt b/core/src/main/resources/help/getpaymentacctform-help.txt new file mode 100644 index 00000000000..5086728c35b --- /dev/null +++ b/core/src/main/resources/help/getpaymentacctform-help.txt @@ -0,0 +1,44 @@ +getpaymentacctform + +NAME +---- +getpaymentacctform - get a blank payment account form for a payment method + +SYNOPSIS +-------- +getpaymentacctform + --payment-method-id= + +DESCRIPTION +----------- +Returns a new, blank payment account form as a json file, e.g., + + { + "_COMMENTS_": [ + "Do not manually edit the paymentMethodId field.", + "Edit the salt field only if you are recreating a payment account on a new installation and wish to preserve the account age." + ], + "paymentMethodId": "CLEAR_X_CHANGE", + "accountName": "your accountname", + "emailOrMobileNr": "your emailormobilenr", + "holderName": "your holdername", + "salt": "" + } + +This form is manually edited, and used as a parameter to the createpaymentacct command, +which creates the new payment account. + +EXAMPLES +-------- +To create a new CLEAR_X_CHANGE (Zelle) payment account, find the payment-method-id for +the getpaymentacctform command: +$ ./bisq-cli --password=xyz --port=9998 getpaymentmethods + +Get a new, blank CLEAR_X_CHANGE (Zelle) payment account form: +$ ./bisq-cli --password=xyz --port=9998 getpaymentacctform --payment-method-id=CLEAR_X_CHANGE_ID + +The previous command created a json file named clear_x_change_1610818248040.json. The timestamp +in the file name is to ensure each generated file is uniquely named (you can rename the file). + +Manually edit the json file, and pass the file's path to the createpaymentacct command: +$ ./bisq-cli --password=xyz --port=9998 createpaymentacct --payment-account-form=clear_x_change_1610818248040.json From d14fc4002904c968e457e992175d005c74bf3170 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:07:06 -0300 Subject: [PATCH 05/40] Fix help text typos --- cli/src/main/java/bisq/cli/CliMain.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index 6c3e796942f..cadde5d405d 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -806,10 +806,10 @@ private static void printHelp(OptionParser parser, @SuppressWarnings("SameParame stream.println(); stream.format(rowFormat, getunusedbsqaddress.name(), "", "Get unused BSQ address"); stream.println(); - stream.format(rowFormat, sendbsq.name(), "--address= --amount= \\", "Send BSQ"); + stream.format(rowFormat, sendbsq.name(), "--address= --amount= \\", "Send BSQ"); stream.format(rowFormat, "", "[--tx-fee-rate=]", ""); stream.println(); - stream.format(rowFormat, sendbtc.name(), "--address= --amount= \\", "Send BTC"); + stream.format(rowFormat, sendbtc.name(), "--address= --amount= \\", "Send BTC"); stream.format(rowFormat, "", "[--tx-fee-rate=]", ""); stream.println(); stream.format(rowFormat, gettxfeerate.name(), "", "Get current tx fee rate in sats/byte"); From 68092a0f82b619b0e5e14f6d41cef2e9e6fb08f2 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:09:52 -0300 Subject: [PATCH 06/40] Add --memo opt to help text --- cli/src/main/java/bisq/cli/CliMain.java | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index cadde5d405d..eb9253b3be7 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -811,6 +811,7 @@ private static void printHelp(OptionParser parser, @SuppressWarnings("SameParame stream.println(); stream.format(rowFormat, sendbtc.name(), "--address= --amount= \\", "Send BTC"); stream.format(rowFormat, "", "[--tx-fee-rate=]", ""); + stream.format(rowFormat, "", "[--memo=<\"memo\">]", ""); stream.println(); stream.format(rowFormat, gettxfeerate.name(), "", "Get current tx fee rate in sats/byte"); stream.println(); From cde9a6d7c8361f3b4d64eccf0d75fd17e36d4828 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:27:14 -0300 Subject: [PATCH 07/40] Add method help docs --- core/src/main/resources/help/sendbsq-help.txt | 38 ++++++++++++++ core/src/main/resources/help/sendbtc-help.txt | 51 +++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 core/src/main/resources/help/sendbsq-help.txt create mode 100644 core/src/main/resources/help/sendbtc-help.txt diff --git a/core/src/main/resources/help/sendbsq-help.txt b/core/src/main/resources/help/sendbsq-help.txt new file mode 100644 index 00000000000..92a03cea1a6 --- /dev/null +++ b/core/src/main/resources/help/sendbsq-help.txt @@ -0,0 +1,38 @@ +sendbsq + +NAME +---- +sendbsq - send BSQ to an external wallet + +SYNOPSIS +-------- +sendbsq + --address= + --amount= + [--tx-fee-rate=] + +DESCRIPTION +----------- +Send BSQ from your Bisq wallet to an external BSQ address. + +OPTIONS +------- +--address + The destination BSQ address for the send transaction. + +--amount + The amount of BSQ to send. + +--tx-fee-rate + An optional transaction fee rate (sats/byte) for the transaction. The user is + responsible for choosing a fee rate that will be accepted by the network in a + reasonable amount of time, and the fee rate must be greater than 0. + +EXAMPLES +-------- +Send 500 BSQ to address Bn3PCQgRwhkrGnaMp1RYwt9tFwL51YELqne with a default transaction fee rate: +$ ./bisq-cli --password=xyz --port=9998 sendbsq --address=Bn3PCQgRwhkrGnaMp1RYwt9tFwL51YELqne --amount=500.00 + +Send 3000 BSQ to address Bn3PCQgRwhkrGnaMp1RYwt9tFwL51YELqne with transaction fee rate of 40 sats/byte: +$ ./bisq-cli --password=xyz --port=9998 sendbsq --address=Bn3PCQgRwhkrGnaMp1RYwt9tFwL51YELqne --amount=3000.00 \ + --tx-fee-rate=40 diff --git a/core/src/main/resources/help/sendbtc-help.txt b/core/src/main/resources/help/sendbtc-help.txt new file mode 100644 index 00000000000..31ad5db0e51 --- /dev/null +++ b/core/src/main/resources/help/sendbtc-help.txt @@ -0,0 +1,51 @@ +sendbtc + +NAME +---- +sendbtc - send BTC to an external wallet + +SYNOPSIS +-------- +sendbtc + --address= + --amount= + [--tx-fee-rate=] + [--memo=<"memo">] + +DESCRIPTION +----------- +Send BTC from your Bisq wallet to an external BTC address. + +OPTIONS +------- +--address + The destination BTC address for the send transaction. + +--amount + The amount of BTC to send. + +--tx-fee-rate + An optional transaction fee rate (sats/byte) for the transaction. The user is + responsible for choosing a fee rate that will be accepted by the network in a + reasonable amount of time, and the fee rate must be greater than 0. + +--memo + An optional memo to be saved with the send btc transaction. + A multi word memo must be enclosed in double quotes. + +EXAMPLES +-------- +Send 0.10 BTC to address bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 with a default +transaction fee rate: +$ ./bisq-cli --password=xyz --port=9998 sendbtc --address=bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 --amount=0.10 + +Send 0.05 BTC to address bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 with a transaction +fee rate of 10 sats/byte: +$ ./bisq-cli --password=xyz --port=9998 sendbtc --address=bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 --amount=0.05 \ + --tx-fee-rate=10 + +Send 0.005 BTC to address bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 with a transaction +fee rate of 40 sats/byte, and save a memo with the send transaction: +$ ./bisq-cli --password=xyz --port=9998 sendbtc --address=bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 --amount=0.005 \ + --tx-fee-rate=40 + --memo="note to self" From dab65e7f78cff0023f180dd72bbbff9fc531a503 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:27:46 -0300 Subject: [PATCH 08/40] Fix typo --- core/src/main/resources/help/getaddressbalance-help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/help/getaddressbalance-help.txt b/core/src/main/resources/help/getaddressbalance-help.txt index ff8149a285a..279c58309dc 100644 --- a/core/src/main/resources/help/getaddressbalance-help.txt +++ b/core/src/main/resources/help/getaddressbalance-help.txt @@ -20,4 +20,4 @@ OPTIONS EXAMPLES -------- -$ ./bisq-cli --password=xyz --port=9998 getaddressbalance -address=bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 +$ ./bisq-cli --password=xyz --port=9998 getaddressbalance --address=bcrt1qygvsqmyt8jyhtp7l3zwqm7s7v3nar6vkc2luz3 From a133b0d7e3c2a5cdf885b2d8ab963e304ed0ae52 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:35:14 -0300 Subject: [PATCH 09/40] Add method help doc --- .../main/resources/help/settxfeerate-help.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 core/src/main/resources/help/settxfeerate-help.txt diff --git a/core/src/main/resources/help/settxfeerate-help.txt b/core/src/main/resources/help/settxfeerate-help.txt new file mode 100644 index 00000000000..557d7ee5c5b --- /dev/null +++ b/core/src/main/resources/help/settxfeerate-help.txt @@ -0,0 +1,19 @@ +settxfeerate + +NAME +---- +settxfeerate - set custom transaction fee rate preference + +SYNOPSIS +-------- +settxfeerate + --tx-fee-rate= + +DESCRIPTION +----------- +Sets the user's custom transaction fee rate preference. + +EXAMPLES +-------- +Set custom transaction fee rate to 25 sats/byte: +$ ./bisq-cli --password=xyz --port=9998 settxfeerate --tx-fee-rate=25 From 9efeee83e3a213c77fa5c3626e1fe591dcc4a748 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:35:43 -0300 Subject: [PATCH 10/40] Explain example --- core/src/main/resources/help/unsettxfeerate-help.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/help/unsettxfeerate-help.txt b/core/src/main/resources/help/unsettxfeerate-help.txt index 36767e6f1f0..d3ec0f96a16 100644 --- a/core/src/main/resources/help/unsettxfeerate-help.txt +++ b/core/src/main/resources/help/unsettxfeerate-help.txt @@ -14,4 +14,5 @@ Unsets (removes) the transaction fee rate user preference. EXAMPLES -------- +Remove the user's custom transaction fee rate preference: $ ./bisq-cli --password=xyz --port=9998 unsettxfeerate From 13d0d3e9f13ddef9a1f2faa42952c7a1e72443bc Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sat, 16 Jan 2021 15:43:59 -0300 Subject: [PATCH 11/40] Add method help doc --- .../resources/help/gettransaction-help.txt | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 core/src/main/resources/help/gettransaction-help.txt diff --git a/core/src/main/resources/help/gettransaction-help.txt b/core/src/main/resources/help/gettransaction-help.txt new file mode 100644 index 00000000000..6b1b7b05cec --- /dev/null +++ b/core/src/main/resources/help/gettransaction-help.txt @@ -0,0 +1,27 @@ +gettransaction + +NAME +---- +gettransaction - get transaction summary + +SYNOPSIS +-------- +gettransaction + --transaction-id= + +DESCRIPTION +----------- +Returns a very brief summary of a BTC transaction created by the Bisq server. + +To see full transaction details, use a bitcoin-core client or an online block explorer. + +OPTIONS +------- +--transaction-id + The ID of the BTC transaction. + +EXAMPLES +-------- +To see the summary of a transaction with ID 282dc2a5755219a49ee9f6d46a31a2cbaec6624beba96548180eccb1f004cdd8: +$ ./bisq-cli --password=xyz --port=9998 gettransaction \ + -transaction-id=282dc2a5755219a49ee9f6d46a31a2cbaec6624beba96548180eccb1f004cdd8 From 44c11922a61f50de0ef3685707e6de72edcfb74e Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sun, 17 Jan 2021 12:58:26 -0300 Subject: [PATCH 12/40] Add method help docs --- .../help/removewalletpassword-help.txt | 19 ++++++++++++++ .../resources/help/setwalletpassword-help.txt | 25 +++++++++++++++++++ .../main/resources/help/unlockwallet-help.txt | 21 ++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 core/src/main/resources/help/removewalletpassword-help.txt create mode 100644 core/src/main/resources/help/setwalletpassword-help.txt create mode 100644 core/src/main/resources/help/unlockwallet-help.txt diff --git a/core/src/main/resources/help/removewalletpassword-help.txt b/core/src/main/resources/help/removewalletpassword-help.txt new file mode 100644 index 00000000000..73b6d311e91 --- /dev/null +++ b/core/src/main/resources/help/removewalletpassword-help.txt @@ -0,0 +1,19 @@ +removewalletpassword + +NAME +---- +removewalletpassword - remove a Bisq wallet's encryption password + +SYNOPSIS +-------- +removewalletpassword + --wallet-password= + --timeout= + +DESCRIPTION +----------- +Remove an encryption password from an encrypted Bisq wallet. + +EXAMPLES +-------- +$ ./bisq-cli --password=xyz --port=9998 removewalletpassword --wallet-password=mypassword diff --git a/core/src/main/resources/help/setwalletpassword-help.txt b/core/src/main/resources/help/setwalletpassword-help.txt new file mode 100644 index 00000000000..da372d9857a --- /dev/null +++ b/core/src/main/resources/help/setwalletpassword-help.txt @@ -0,0 +1,25 @@ +setwalletpassword + +NAME +---- +setwalletpassword - set Bisq wallet password + +SYNOPSIS +-------- +setwalletpassword + --wallet-password= + --new-wallet-password= + +DESCRIPTION +----------- +Encrypts a Bisq wallet with a password. If the optional new wallet password option is +present, a new wallet password replaces the existing password + +EXAMPLES +-------- +Encrypt an unencrypted Bisq wallet with a password: +$ ./bisq-cli --password=xyz --port=9998 setwalletpassword --wallet-password=mypassword + +Set a new password on a Bisq wallet that is already encrypted: +$ ./bisq-cli --password=xyz --port=9998 setwalletpassword --wallet-password=myoldpassword \ + --new-wallet-password=mynewpassword diff --git a/core/src/main/resources/help/unlockwallet-help.txt b/core/src/main/resources/help/unlockwallet-help.txt new file mode 100644 index 00000000000..388117caf25 --- /dev/null +++ b/core/src/main/resources/help/unlockwallet-help.txt @@ -0,0 +1,21 @@ +unlockwallet + +NAME +---- +unlockwallet - unlock an encrypted Bisq wallet + +SYNOPSIS +-------- +unlockwallet + --wallet-password= + --timeout= + +DESCRIPTION +----------- +Unlocks an encrypted Bisq wallet for a specified number of seconds. +The timeout can be manually overridden with the lockwallet command. + +EXAMPLES +-------- +Unlock a wallet encrypted with the wallet-password "mypassword" for 30 seconds: +$ ./bisq-cli --password=xyz --port=9998 unlockwallet --wallet-password=mypassword --timeout=30 From 04657d90547aa5a23d492b9b499df7a580dabc40 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sun, 17 Jan 2021 12:59:54 -0300 Subject: [PATCH 13/40] Explain example --- core/src/main/resources/help/lockwallet-help.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/resources/help/lockwallet-help.txt b/core/src/main/resources/help/lockwallet-help.txt index 6639dcef5ea..58cb5668abd 100644 --- a/core/src/main/resources/help/lockwallet-help.txt +++ b/core/src/main/resources/help/lockwallet-help.txt @@ -14,4 +14,5 @@ Locks an unlocked wallet before an unlockwallet timeout expires. EXAMPLES -------- +Immediately lock an encrypted wallet set to automatically lock in the future: $ ./bisq-cli --password=xyz --port=9998 lockwallet From 8907d6b4a8005c8621ec6527c1207f50ea432ab6 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Sun, 17 Jan 2021 13:05:07 -0300 Subject: [PATCH 14/40] Keep CLI method enum members in alphabetical order --- cli/src/main/java/bisq/cli/Method.java | 44 +++++++++++++------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/cli/src/main/java/bisq/cli/Method.java b/cli/src/main/java/bisq/cli/Method.java index 037468b9bd0..c2490ee1d44 100644 --- a/cli/src/main/java/bisq/cli/Method.java +++ b/cli/src/main/java/bisq/cli/Method.java @@ -21,36 +21,36 @@ * Currently supported api methods. */ public enum Method { - createoffer, canceloffer, - getoffer, - getmyoffer, - getoffers, - getmyoffers, - takeoffer, - gettrade, - confirmpaymentstarted, confirmpaymentreceived, - keepfunds, - withdrawfunds, - getpaymentmethods, - getpaymentacctform, + confirmpaymentstarted, + createoffer, createpaymentacct, - getpaymentaccts, - getversion, - getbalance, getaddressbalance, + getbalance, getfundingaddresses, + getmyoffer, + getmyoffers, + getoffer, + getoffers, + getpaymentacctform, + getpaymentaccts, + getpaymentmethods, + gettrade, + gettransaction, + gettxfeerate, getunusedbsqaddress, + getversion, + keepfunds, + lockwallet, + registerdisputeagent, + removewalletpassword, sendbsq, sendbtc, - gettxfeerate, settxfeerate, - unsettxfeerate, - gettransaction, - lockwallet, - unlockwallet, - removewalletpassword, setwalletpassword, - registerdisputeagent + takeoffer, + unlockwallet, + unsettxfeerate, + withdrawfunds } From 873c661218f9bca973697c6b1621fa4410a1bd0a Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 19 Jan 2021 13:46:55 -0300 Subject: [PATCH 15/40] Add api trade simulation scripts Two regtest trading simulation scripts are contained in this change: - trade-simulation.sh goes through the steps of creating F2F payment accounts for Bob & Alice, and each step of a trade from createoffer to completion. - limit-order-simulation.sh shows one way to trigger creation of an offer when a limit price is reached. Each script prints CLI commands just before they are run. Both scripts depend on functions contained in supporting bash and python3 scripts. Examples: trade-simulation.sh Simulate the entire trade protocol between Bob (taker) & Alice (maker), where Alice buys 0.1 BTC from Bob, paying in Renminbi (CYN). Note the script takes a country code (CN) not a currency code, so the script can create the appropriate country based face to face payment accounts. $ apitest/scripts/trade-simulation.sh -d buy -c cn -m 0.0 -a 0.1 limit-order.sh Create a CAD/BUY 0.1 BTC order at mkt price margin of 0.0% if price falls to or below 47900 CAD. Note the script takes a country code (CA) not a currency code, so the script can create the appropriate country based face to face payment accounts. $ apitest/scripts/limit-order-simulation.sh -l 47900 -d buy -c CA -m 0.0 -a 0.1 Create a USD/SELL 0.1 BTC order at mkt price margin of 0.0% if price rises to or above 37200 USD. $ apitest/scripts/limit-order-simulation.sh -l 37200 -d sell -c US -m 0.0 -a 0.1 --- apitest/scripts/editf2faccountform.py | 28 +++ apitest/scripts/getmktprice.py | 22 +++ apitest/scripts/limit-order-simulation.sh | 115 ++++++++++++ apitest/scripts/trade-simulation-env.sh | 205 ++++++++++++++++++++++ apitest/scripts/trade-simulation-utils.sh | 174 ++++++++++++++++++ apitest/scripts/trade-simulation.sh | 189 ++++++++++++++++++++ 6 files changed, 733 insertions(+) create mode 100644 apitest/scripts/editf2faccountform.py create mode 100644 apitest/scripts/getmktprice.py create mode 100755 apitest/scripts/limit-order-simulation.sh create mode 100755 apitest/scripts/trade-simulation-env.sh create mode 100755 apitest/scripts/trade-simulation-utils.sh create mode 100755 apitest/scripts/trade-simulation.sh diff --git a/apitest/scripts/editf2faccountform.py b/apitest/scripts/editf2faccountform.py new file mode 100644 index 00000000000..f9849a75a3f --- /dev/null +++ b/apitest/scripts/editf2faccountform.py @@ -0,0 +1,28 @@ +import sys, os, json + +# Writes a Bisq json F2F payment account form for the given country_code to the current working directory. + +if len(sys.argv) < 2: + print("usage: editf2faccountform.py country_code") + exit(1) + +country_code = str(sys.argv[1]).upper() +acct_form = { + "_COMMENTS_": [ + "Do not manually edit the paymentMethodId field.", + "Edit the salt field only if you are recreating a payment account on a new installation and wish to preserve the account age." + ], + "paymentMethodId": "F2F", + "accountName": "Face to Face Payment Account", + "city": "Anytown", + "contact": "Me", + "country": country_code, + "extraInfo": "", + "salt": "" +} +target=os.path.dirname(os.path.realpath(__file__)) + '/' + 'f2f-acct.json' +with open (target, 'w') as outfile: + json.dump(acct_form, outfile, indent=2) + outfile.write('\n') + +exit(0) diff --git a/apitest/scripts/getmktprice.py b/apitest/scripts/getmktprice.py new file mode 100644 index 00000000000..e073fa8254a --- /dev/null +++ b/apitest/scripts/getmktprice.py @@ -0,0 +1,22 @@ +import sys, json, requests + +# Returns the current BTC price for the given currency_code from a cleartext price service. + +if len(sys.argv) < 2: + print("usage: getmktprice.py currency_code") + exit(1) + +currency_code = str(sys.argv[1]).upper() + +url = "https://price.bisq.wiz.biz/getAllMarketPrices" +resp = requests.get(url) +if resp.status_code == 200: + for i in resp.json()['data']: + if i['currencyCode'] == currency_code: + print(int(i['price'])) + break +else: + print('Error: Could not get ' + currency_code + ' price.') + exit(1) + +exit(0) diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh new file mode 100755 index 00000000000..219bc8e1e67 --- /dev/null +++ b/apitest/scripts/limit-order-simulation.sh @@ -0,0 +1,115 @@ +#! /bin/bash + +APP_HOME=$(pwd -P) +APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" + +# Source the env and some helper functions. +. "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" +. "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" + +checksetup +parselimitorderopts "$@" + +printdate "Started ${APP_BASE_NAME} with parameters:" +printscriptparams +printbreak + +editpaymentaccountform "$COUNTRY_CODE" +exitoncommandalert $? +cat ${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM} +printbreak + +# Create F2F payment accounts for $COUNTRY_CODE, and get the $CURRENCY_CODE. +printdate "Creating Alice's face to face ${COUNTRY_CODE} payment account." +CMD="${CLI_BASE} --port=${ALICE_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" +printdate "ALICE CLI: ${CMD}" +CMD_OUTPUT=$(createpaymentacct "${CMD}") +exitoncommandalert $? +echo "${CMD_OUTPUT}" +ALICE_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") +exitoncommandalert $? +CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") +exitoncommandalert $? +printdate "ALICE F2F payment-account-id = ${ALICE_ACCT_ID}, currency-code = ${CURRENCY_CODE}." +printbreak + +printdate "Creating Bob's face to face ${COUNTRY_CODE} payment account." +CMD="${CLI_BASE} --port=${BOB_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" +printdate "BOB CLI: ${CMD}" +CMD_OUTPUT=$(createpaymentacct "${CMD}") +exitoncommandalert $? +echo "${CMD_OUTPUT}" +BOB_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") +exitoncommandalert $? +CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") +exitoncommandalert $? +printdate "BOB F2F payment-account-id = ${BOB_ACCT_ID}, currency-code = ${CURRENCY_CODE}." +printbreak + +# Bob & Alice now have matching payment accounts, now loop until the price limit is reached, then create an offer. +if [ "$DIRECTION" = "BUY" ] +then + printdate "Create a BUY / ${CURRENCY_CODE} offer when the market price falls to or below ${LIMIT_PRICE} ${CURRENCY_CODE}." +else + printdate "Create a SELL / ${CURRENCY_CODE} offer when the market price rises to or above ${LIMIT_PRICE} ${CURRENCY_CODE}." +fi + +DONE=0 +while : ; do + if [ "$DONE" -ne 0 ]; then + break + fi + + CURRENT_PRICE=$(getcurrentprice ${CURRENCY_CODE}) + printdate "Current Price: ${CURRENT_PRICE} ${CURRENCY_CODE}" + + if [ "$DIRECTION" = "BUY" ] && [ "$CURRENT_PRICE" -le "$LIMIT_PRICE" ]; then + printdate "Limit price reached." + DONE=1 + break + fi + + if [ "$DIRECTION" = "SELL" ] && [ "$CURRENT_PRICE" -ge "$LIMIT_PRICE" ]; then + printdate "Limit price reached." + DONE=1 + break + fi + + sleep 15 +done + +printdate "ALICE: Creating ${DIRECTION} ${CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}." +CMD="$CLI_BASE --port=${ALICE_PORT} createoffer" +CMD+=" --payment-account=${ALICE_ACCT_ID}" +CMD+=" --direction=${DIRECTION}" +CMD+=" --currency-code=${CURRENCY_CODE}" +CMD+=" --amount=${AMOUNT}" +if [ -z "${MKT_PRICE_MARGIN}" ]; then + CMD+=" --fixed-price=${FIXED_PRICE}" +else + CMD+=" --market-price-margin=${MKT_PRICE_MARGIN}" +fi +CMD+=" --security-deposit=50.0" +CMD+=" --fee-currency=BSQ" +printdate "ALICE CLI: ${CMD}" +OFFER_ID=$(createoffer "${CMD}") +exitoncommandalert $? +printdate "ALICE: Created offer with id: ${OFFER_ID}." +printbreak +sleeptraced 10 + +# Generate some btc blocks. +printdate "Generating btc blocks after publishing Alice's offer." +genbtcblocks 3 3 +printbreak +sleeptraced 5 + +# Show Alice's offer in Bob's CLI. +printdate "BOB: Looking at ${DIRECTION} ${CURRENCY_CODE} offers." +CMD="$CLI_BASE --port=${BOB_PORT} getoffers --direction=${DIRECTION} --currency-code=${CURRENCY_CODE}" +printdate "BOB CLI: ${CMD}" +OFFERS=$($CMD) +exitoncommandalert $? +echo "${OFFERS}" + +exit 0 diff --git a/apitest/scripts/trade-simulation-env.sh b/apitest/scripts/trade-simulation-env.sh new file mode 100755 index 00000000000..51499c58e6d --- /dev/null +++ b/apitest/scripts/trade-simulation-env.sh @@ -0,0 +1,205 @@ +#! /bin/bash + +# This file must be sourced by the main driver. + +export CLI_BASE="./bisq-cli --password=xyz" +export ARBITRATOR_PORT=9997 +export ALICE_PORT=9998 +export BOB_PORT=9999 +export F2F_ACCT_FORM="f2f-acct.json" + +checksetup() { + apitestusage() { + echo "The apitest harness must be running a local bitcoin regtest node, a seednode, arbitration node, and Bob & Alice daemons." + echo "" + echo "From the project's root dir, start all supporting nodes from a terminal:" + echo "./bisq-apitest --apiPassword=xyz --supportingApps=bitcoind,seednode,arbdaemon,alicedaemon,bobdaemon --shutdownAfterTests=false" + echo "" + echo "Register dispute agents in the arbitration daemon after it initializes." + echo "./bisq-cli --password=xyz --port=9997 registerdisputeagent --dispute-agent-type=mediator \ + --registration-key=6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a" + echo "./bisq-cli --password=xyz --port=9997 registerdisputeagent --dispute-agent-type=refundagent \ + --registration-key=6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a" + exit 1; + } + printdate "Checking ${APP_HOME} for some expected directories and files." + if [ -d "${APP_HOME}/apitest" ]; then + printdate "Subproject apitest exists."; + else + printdate "Error: Subproject apitest not found, maybe because you are not running the script from the project root dir." + exit 1 + fi + if [ -f "${APP_HOME}/bisq-cli" ]; then + printdate "The bisq-cli script exists."; + else + printdate "Error: The bisq-cli script not found, maybe because you are not running the script from the project root dir." + exit 1 + fi + printdate "Checking to see local bitcoind is running." + checkbitcoindrunning + printdate "Checking to see bisq servers are running." + if pgrep -f "bisq.seednode.SeedNodeMain" > /dev/null ; then + printdate "The seednode is running on host." + else + printdate "Error: seed is not running on host, exiting." + apitestusage + fi + if pgrep -f "bisq.daemon.app.BisqDaemonMain --appName=bisq-BTC_REGTEST_Arb_dao" > /dev/null ; then + printdate "The arbitration node is running on host." + else + printdate "Error: arbitration node is not running on host, exiting." + apitestusage + fi + if pgrep -f "bisq.daemon.app.BisqDaemonMain --appName=bisq-BTC_REGTEST_Alice_dao" > /dev/null ; then + printdate "Alice's daemon node is running on host." + else + printdate "Error: Alice's daemon node is not running on host, exiting." + apitestusage + fi + if pgrep -f "bisq.daemon.app.BisqDaemonMain --appName=bisq-BTC_REGTEST_Bob_dao" > /dev/null ; then + printdate "Bob's daemon node is running on host." + else + printdate "Error: Bob's daemon node is not running on host, exiting." + apitestusage + fi +} + +parseopts() { + usage() { + echo "Usage: $0 [-d buy|sell] [-c ] [-f || -m ] [-a ]" 1>&2 + exit 1; + } + + local OPTIND o d c f m a + while getopts "d:c:f:m:a:" o; do + case "${o}" in + d) d=$(echo "${OPTARG}" | tr '[:lower:]' '[:upper:]') + ((d == "BUY" || d == "SELL")) || usage + export DIRECTION=${d} + ;; + c) c=$(echo "${OPTARG}"| tr '[:lower:]' '[:upper:]') + export COUNTRY_CODE=${c} + ;; + f) f=${OPTARG} + export FIXED_PRICE=${f} + ;; + m) m=${OPTARG} + export MKT_PRICE_MARGIN=${m} + ;; + a) a=${OPTARG} + export AMOUNT=${a} + ;; + *) usage ;; + esac + done + shift $((OPTIND-1)) + + if [ -z "${d}" ] || [ -z "${c}" ] || [ -z "${a}" ]; then + usage + fi + + if [ -z "${f}" ] && [ -z "${m}" ]; then + usage + fi + + if [ -n "${f}" ] && [ -n "${m}" ]; then + printdate "Must use margin-from-price param (-m) or fixed-price param (-f), not both." + usage + fi + + if [ "$DIRECTION" = "SELL" ] + then + export BOB_ROLE="(taker/buyer)" + export ALICE_ROLE="(maker/seller)" + else + export BOB_ROLE="(taker/seller)" + export ALICE_ROLE="(maker/buyer)" + fi +} + + +parselimitorderopts() { + usage() { + echo "Usage: $0 [-l limit-price] [-d buy|sell] [-c ] [-f || -m ] [-a ]" 1>&2 + exit 1; + } + + local OPTIND o l d c f m a + while getopts "l:d:c:f:m:a:" o; do + case "${o}" in + l) l=${OPTARG} + export LIMIT_PRICE=${l} + ;; + d) d=$(echo "${OPTARG}" | tr '[:lower:]' '[:upper:]') + ((d == "BUY" || d == "SELL")) || usage + export DIRECTION=${d} + ;; + c) c=$(echo "${OPTARG}"| tr '[:lower:]' '[:upper:]') + export COUNTRY_CODE=${c} + ;; + f) f=${OPTARG} + export FIXED_PRICE=${f} + ;; + m) m=${OPTARG} + export MKT_PRICE_MARGIN=${m} + ;; + a) a=${OPTARG} + export AMOUNT=${a} + ;; + *) usage ;; + esac + done + shift $((OPTIND-1)) + + if [ -z "${l}" ]; then + usage + fi + + if [ -z "${d}" ] || [ -z "${c}" ] || [ -z "${a}" ]; then + usage + fi + + if [ -z "${f}" ] && [ -z "${m}" ]; then + usage + fi + + if [ -n "${f}" ] && [ -n "${m}" ]; then + printdate "Must use margin-from-price param (-m) or fixed-price param (-f), not both." + usage + fi +} + +checkbitcoindrunning() { + # There may be a '+' char in the path and we have to escape it for pgrep. + if [[ ${APP_HOME} == *"+"* ]]; then + ESCAPED_APP_HOME=$(escapepluschar "${APP_HOME}") + else + ESCAPED_APP_HOME="${APP_HOME}" + fi + if pgrep -f "bitcoind -datadir=${ESCAPED_APP_HOME}/apitest/build/resources/main/Bitcoin-regtest" > /dev/null ; then + printdate "The regtest bitcoind node is running on host." + else + printdate "Error: regtest bitcoind node is not running on host, exiting." + apitestusage + fi +} + +printscriptparams() { + if [ -n "${LIMIT_PRICE+1}" ]; then + echo " LIMIT_PRICE = ${LIMIT_PRICE}" + fi + + echo " DIRECTION = ${DIRECTION}" + echo " COUNTRY_CODE = ${COUNTRY_CODE}" + echo " FIXED_PRICE = ${FIXED_PRICE}" + echo " MKT_PRICE_MARGIN = ${MKT_PRICE_MARGIN}" + echo " AMOUNT = ${AMOUNT}" + + if [ -n "${BOB_ROLE+1}" ]; then + echo " BOB_ROLE = ${BOB_ROLE}" + fi + + if [ -n "${ALICE_ROLE+1}" ]; then + echo " ALICE_ROLE = ${ALICE_ROLE}" + fi +} diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh new file mode 100755 index 00000000000..0f96f99fe13 --- /dev/null +++ b/apitest/scripts/trade-simulation-utils.sh @@ -0,0 +1,174 @@ +#! /bin/bash + +# This file must be sourced by the main driver. + +. "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" + +printdate() { + echo "[$(date)] $@" +} + +printbreak() { + echo "" + echo "" +} + +printcmd() { + echo -en "$@\n" +} + +sleeptraced() { + PERIOD=$1 + printdate "sleeping for $PERIOD" + sleep "$PERIOD" +} + +commandalert() { + # Used in a script function when it needs to fail early with an error message, & pass the error code to the caller. + # usage: commandalert <$?> + if [ "$1" -ne 0 ] + then + printdate "Error: $2" >&2 + exit $1 + fi +} + +# TODO rename exitonalert ? +exitoncommandalert() { + # Used in a parent script when you need it to fail immediately, with no error message. + # usage: exitoncommandalert <$?> + if [ "$1" -ne 0 ] + then + exit $1 + fi +} + +registerdisputeagents() { + # Silently register dev dispute agents. It's easy to forget. + REG_KEY="6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a" + CMD="${CLI_BASE} --port=${ARBITRATOR_PORT} registerdisputeagent --dispute-agent-type=mediator --registration-key=${REG_KEY}" + SILENT=$($CMD) + commandalert $? "Could not register dev/test mediator." + CMD="${CLI_BASE} --port=${ARBITRATOR_PORT} registerdisputeagent --dispute-agent-type=refundagent --registration-key=${REG_KEY}" + SILENT=$($CMD) + commandalert $? "Could not register dev/test refundagent." + # Do something with $SILENT to keep codacy happy. + echo "$SILENT" > /dev/null +} + +getbtcoreaddress() { + CMD="bitcoin-cli -regtest -rpcport=19443 -rpcuser=apitest -rpcpassword=apitest getnewaddress" + NEW_ADDRESS=$(${CMD}) + echo "${NEW_ADDRESS}" +} + +genbtcblocks() { + NUM_BLOCKS=$1 + SECONDS_BETWEEN_BLOCKS=$2 + ADDR_PARAM="$(getbtcoreaddress)" + CMD_PREFIX="bitcoin-cli -regtest -rpcport=19443 -rpcuser=apitest -rpcpassword=apitest generatetoaddress 1" + # Print the generatetoaddress command with double quoted address param, to make it cut & pastable from the console. + printdate "$CMD_PREFIX \"$ADDR_PARAM\"" + # Now create the full generatetoaddress command to be run now. + CMD="$CMD_PREFIX $ADDR_PARAM" + for i in $(seq -f "%02g" 1 "$NUM_BLOCKS") + do + NEW_BLOCK_HASH=$(genbtcblock "$CMD") + printdate "Block Hash #$i:${NEW_BLOCK_HASH}" + sleep "$SECONDS_BETWEEN_BLOCKS" + done +} + +genbtcblock() { + CMD=$1 + NEW_BLOCK_HASH=$(${CMD} | sed -n '2p') + echo "$NEW_BLOCK_HASH" +} + +escapepluschar() { + STRING=$1 + NEW_STRING=$(echo "${STRING//+/\\+}") + echo "${NEW_STRING}" +} + +printbalances() { + PORT=$1 + printcmd "${CLI_BASE} --port=${PORT} getbalance" + $CLI_BASE --port="$PORT" getbalance +} + +getpaymentaccountmethods() { + CMD=$1 + CMD_OUTPUT=$(${CMD}) + commandalert $? "Could not get payment method ids." + printdate "Payment Method IDs:" + echo "${CMD_OUTPUT}" +} + +getpaymentaccountform() { + CMD=$1 + CMD_OUTPUT=$(${CMD}) + commandalert $? "Could not get new payment account form." + echo "${CMD_OUTPUT}" +} + +editpaymentaccountform() { + FORM_PATH=$1 + CMD="python3 ${APITEST_SCRIPTS_HOME}/editf2faccountform.py $COUNTRY_CODE" + CMD_OUTPUT=$(${CMD}) + commandalert $? "Could not edit payment account form." + printdate "Saved payment account form as ${F2F_ACCT_FORM}." +} + +getnewpaymentacctid() { + CREATE_PAYMENT_ACCT_OUTPUT=$1 + PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p') + ACCT_ID=$(echo -e "$PAYMENT_ACCT_DETAIL" | awk '{print $NF}') + echo "${ACCT_ID}" +} + +getnewpaymentacctcurrency() { + CREATE_PAYMENT_ACCT_OUTPUT=$1 + PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p') + # This is brittle; it requires the account name field to have N words, + # e.g, "Face to Face Payment Account" as defined in editf2faccountform.py. + CURRENCY_CODE=$(echo -e "$PAYMENT_ACCT_DETAIL" | awk '{print $6}') + echo "${CURRENCY_CODE}" +} + +createpaymentacct() { + CMD=$1 + CMD_OUTPUT=$(${CMD}) + commandalert $? "Could not create new payment account." + echo "${CMD_OUTPUT}" +} + +getpaymentaccounts() { + PORT=$1 + printcmd "${CLI_BASE} --port=${PORT} getpaymentaccts" + CMD="$CLI_BASE --port="$PORT" getpaymentaccts" + CMD_OUTPUT=$(${CMD}) + commandalert $? "Could not get payment accounts." + echo "${CMD_OUTPUT}" +} + +createoffer() { + CREATE_OFFER_CMD=$1 + OFFER_DESC=$($CREATE_OFFER_CMD) + + # If the CLI command exited with an error, print the CLI error, and + # return from this function now, passing the error status code to the caller. + commandalert $? "Could not create offer." + + OFFER_DETAIL=$(echo -e "${OFFER_DESC}" | sed -n '2p') + NEW_OFFER_ID=$(echo -e "${OFFER_DETAIL}" | awk '{print $NF}') + echo "${NEW_OFFER_ID}" +} + +getcurrentprice() { + CURRENCY_CODE=$1 + CMD="python3 ${APITEST_SCRIPTS_HOME}/getmktprice.py ${CURRENCY_CODE}" + PRICE=$(${CMD}) + echo "${PRICE}" +} + diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh new file mode 100755 index 00000000000..7c51c0bb29d --- /dev/null +++ b/apitest/scripts/trade-simulation.sh @@ -0,0 +1,189 @@ +#! /bin/bash + +export APP_BASE_NAME=$(basename "$0") +export APP_HOME=$(pwd -P) +export APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" + +# Source the env and some helper functions. +. "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" +. "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" + +checksetup +parseopts "$@" + +printdate "Started ${APP_BASE_NAME} with parameters:" +printscriptparams +printbreak + +registerdisputeagents + +printdate "Alice looks for the ID of the face to face payment account method (Bob will use same payment method)." +CMD="${CLI_BASE} --port=${ALICE_PORT} getpaymentmethods" +printdate "ALICE CLI: ${CMD}" +getpaymentaccountmethods "$CMD" +printbreak + +printdate "Alice uses the F2F payment method id to create a face to face payment account in country ${COUNTRY_CODE}." +CMD="${CLI_BASE} --port=${ALICE_PORT} getpaymentacctform --payment-method-id=F2F" +printdate "ALICE CLI: ${CMD}" +getpaymentaccountform "$CMD" +printbreak + +printdate "Bob & Alice edit their ${COUNTRY_CODE} payment account forms, and renames them to ${F2F_ACCT_FORM}" +editpaymentaccountform "$COUNTRY_CODE" +cat ${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM} + +# Remove the autogenerated json template because we are going to use one created by a python script in the next step. +CMD="rm -v ${APP_HOME}/f2f_*.json" +DELETE_JSON_TEMPLATE=$(${CMD}) +echo "$DELETE_JSON_TEMPLATE" +printbreak + +printdate "Bob and Alice create their face to face ${COUNTRY_CODE} payment accounts." +CMD="${CLI_BASE} --port=${BOB_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" +printdate "BOB CLI: ${CMD}" +CMD_OUTPUT=$(createpaymentacct "${CMD}") +echo "${CMD_OUTPUT}" +BOB_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") +BOB_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") +printdate "BOB F2F payment-account-id = ${BOB_ACCT_ID}, currency-code = ${BOB_ACCT_CURRENCY_CODE}." +printbreak + +CMD="${CLI_BASE} --port=${ALICE_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" +printdate "ALICE CLI: ${CMD}" +CMD_OUTPUT=$(createpaymentacct "${CMD}") +echo "${CMD_OUTPUT}" +ALICE_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}") +ALICE_ACCT_CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}") +printdate "ALICE F2F payment-account-id = ${ALICE_ACCT_ID}, currency-code = ${ALICE_ACCT_CURRENCY_CODE}." +printbreak + +printdate "ALICE ${ALICE_ROLE}: Creating ${DIRECTION} ${ALICE_ACCT_CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}." +CMD="$CLI_BASE --port=${ALICE_PORT} createoffer" +CMD+=" --payment-account=${ALICE_ACCT_ID}" +CMD+=" --direction=${DIRECTION}" +CMD+=" --currency-code=${ALICE_ACCT_CURRENCY_CODE}" +CMD+=" --amount=${AMOUNT}" +if [ -z "${MKT_PRICE_MARGIN}" ]; then + CMD+=" --fixed-price=${FIXED_PRICE}" +else + CMD+=" --market-price-margin=${MKT_PRICE_MARGIN}" +fi +CMD+=" --security-deposit=15.0" +CMD+=" --fee-currency=BSQ" +printdate "ALICE CLI: ${CMD}" +OFFER_ID=$(createoffer "${CMD}") +exitoncommandalert $? +printdate "ALICE ${ALICE_ROLE}: Created offer with id: ${OFFER_ID}." +printbreak +sleeptraced 10 + +# Generate some btc blocks. +printdate "Generating btc blocks after publishing Alice's offer." +genbtcblocks 3 5 +printbreak +sleeptraced 10 + +# List offers. +printdate "BOB ${BOB_ROLE}: Looking at ${DIRECTION} ${BOB_ACCT_CURRENCY_CODE} offers." +CMD="$CLI_BASE --port=${BOB_PORT} getoffers --direction=${DIRECTION} --currency-code=${BOB_ACCT_CURRENCY_CODE}" +printdate "BOB CLI: ${CMD}" +OFFERS=$($CMD) +exitoncommandalert $? +echo "${OFFERS}" +printbreak +sleeptraced 3 + +# Take offer. +printdate "BOB ${BOB_ROLE}: Taking offer ${OFFER_ID} with payment acct ${BOB_ACCT_ID}." +CMD="$CLI_BASE --port=${BOB_PORT} takeoffer --offer-id=${OFFER_ID} --payment-account=${BOB_ACCT_ID} --fee-currency=bsq" +printdate "BOB CLI: ${CMD}" +TRADE=$($CMD) +commandalert $? "Could not take offer." + +echo "${TRADE}" +printbreak +sleeptraced 10 + +# Generating some btc blocks +printdate "Generating btc blocks after Bob takes Alice's offer." +genbtcblocks 3 3 +printbreak +sleeptraced 6 + +# Send payment sent and received messages. +if [ "${DIRECTION}" = "BUY" ] +then + PAYER="ALICE ${ALICE_ROLE}" + PAYER_PORT=${ALICE_PORT} + PAYER_CLI="ALICE CLI" + PAYEE="BOB ${BOB_ROLE}" + PAYEE_PORT=${BOB_PORT} + PAYEE_CLI="BOB CLI" +else + PAYER="BOB ${BOB_ROLE}" + PAYER_PORT=${BOB_PORT} + PAYER_CLI="BOB CLI" + PAYEE="ALICE ${ALICE_ROLE}" + PAYEE_PORT=${ALICE_PORT} + PAYEE_CLI="ALICE CLI" +fi + +# Confirm payment started. +printdate "${PAYER}: Sending fiat payment sent msg." +CMD="$CLI_BASE --port=${PAYER_PORT} confirmpaymentstarted --trade-id=${OFFER_ID}" +printdate "${PAYER_CLI}: ${CMD}" +SENT_MSG=$($CMD) +commandalert $? "Could not send confirmpaymentstarted message." + +printdate "${SENT_MSG}" +printbreak + +sleeptraced 2 +printdate "Generating btc blocks after fiat payment sent msg." +genbtcblocks 3 5 +sleeptraced 2 + +# Confirm payment received. +printdate "${PAYEE}: Sending fiat payment received msg." +CMD="$CLI_BASE --port=${PAYEE_PORT} confirmpaymentreceived --trade-id=${OFFER_ID}" +printdate "${PAYEE_CLI}: ${CMD}" +RCVD_MSG=$($CMD) +commandalert $? "Could not send confirmpaymentreceived message." +printdate "${RCVD_MSG}" +printbreak +sleeptraced 4 + +# Generate some btc blocks +printdate "Generating btc blocks after fiat transfer." +genbtcblocks 3 5 +printbreak +sleeptraced 3 + +# Complete the trade on the seller side. +if [ "${DIRECTION}" = "BUY" ] +then + printdate "BOB ${BOB_ROLE}: Closing trade by keeping funds in Bisq wallet." + CMD="$CLI_BASE --port=${BOB_PORT} keepfunds --trade-id=${OFFER_ID}" + printdate "BOB CLI: ${CMD}" +else + printdate "ALICE (taker): Closing trade by keeping funds in Bisq wallet." + CMD="$CLI_BASE --port=${ALICE_PORT} keepfunds --trade-id=${OFFER_ID}" + printdate "ALICE CLI: ${CMD}" +fi +KEEP_FUNDS_MSG=$($CMD) +commandalert $? "Could close trade with keepfunds command." +printdate "${KEEP_FUNDS_MSG}" +sleeptraced 5 +printbreak + +# Get balances after trade completion. +printdate "Bob & Alice's balances after trade:" +printdate "ALICE CLI:" +printbalances "$ALICE_PORT" +printbreak +printdate "BOB CLI:" +printbalances "$BOB_PORT" +printbreak + +exit 0 From 93c3735f9c0de11354041dec1fce8fac13ec2e94 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 19 Jan 2021 14:38:22 -0300 Subject: [PATCH 16/40] Fix bash bugs & style problems for codacy --- apitest/scripts/getmktprice.py | 2 +- apitest/scripts/limit-order-simulation.sh | 4 ++-- apitest/scripts/trade-simulation-utils.sh | 8 ++++---- apitest/scripts/trade-simulation.sh | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apitest/scripts/getmktprice.py b/apitest/scripts/getmktprice.py index e073fa8254a..a8885df320f 100644 --- a/apitest/scripts/getmktprice.py +++ b/apitest/scripts/getmktprice.py @@ -1,4 +1,4 @@ -import sys, json, requests +import sys, requests # Returns the current BTC price for the given currency_code from a cleartext price service. diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh index 219bc8e1e67..f71e9fc1fe0 100755 --- a/apitest/scripts/limit-order-simulation.sh +++ b/apitest/scripts/limit-order-simulation.sh @@ -16,7 +16,7 @@ printbreak editpaymentaccountform "$COUNTRY_CODE" exitoncommandalert $? -cat ${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM} +cat "${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" printbreak # Create F2F payment accounts for $COUNTRY_CODE, and get the $CURRENCY_CODE. @@ -60,7 +60,7 @@ while : ; do break fi - CURRENT_PRICE=$(getcurrentprice ${CURRENCY_CODE}) + CURRENT_PRICE=$(getcurrentprice "${CURRENCY_CODE}") printdate "Current Price: ${CURRENT_PRICE} ${CURRENCY_CODE}" if [ "$DIRECTION" = "BUY" ] && [ "$CURRENT_PRICE" -le "$LIMIT_PRICE" ]; then diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index 0f96f99fe13..1bb83ff9173 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -29,7 +29,7 @@ commandalert() { if [ "$1" -ne 0 ] then printdate "Error: $2" >&2 - exit $1 + exit "$1" fi } @@ -39,7 +39,7 @@ exitoncommandalert() { # usage: exitoncommandalert <$?> if [ "$1" -ne 0 ] then - exit $1 + exit "$1" fi } @@ -113,7 +113,7 @@ getpaymentaccountform() { } editpaymentaccountform() { - FORM_PATH=$1 + COUNTRY_CODE=$1 CMD="python3 ${APITEST_SCRIPTS_HOME}/editf2faccountform.py $COUNTRY_CODE" CMD_OUTPUT=$(${CMD}) commandalert $? "Could not edit payment account form." @@ -146,7 +146,7 @@ createpaymentacct() { getpaymentaccounts() { PORT=$1 printcmd "${CLI_BASE} --port=${PORT} getpaymentaccts" - CMD="$CLI_BASE --port="$PORT" getpaymentaccts" + CMD="$CLI_BASE --port=$PORT getpaymentaccts" CMD_OUTPUT=$(${CMD}) commandalert $? "Could not get payment accounts." echo "${CMD_OUTPUT}" diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 7c51c0bb29d..39d1df19ca5 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -31,7 +31,7 @@ printbreak printdate "Bob & Alice edit their ${COUNTRY_CODE} payment account forms, and renames them to ${F2F_ACCT_FORM}" editpaymentaccountform "$COUNTRY_CODE" -cat ${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM} +cat "${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" # Remove the autogenerated json template because we are going to use one created by a python script in the next step. CMD="rm -v ${APP_HOME}/f2f_*.json" From 48a326b990393658b24c260883bb173bb5262908 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 19 Jan 2021 15:00:47 -0300 Subject: [PATCH 17/40] Add env requirement and usage comments --- apitest/scripts/limit-order-simulation.sh | 34 ++++++++++++++++++++ apitest/scripts/trade-simulation.sh | 39 +++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh index f71e9fc1fe0..95fc0add63c 100755 --- a/apitest/scripts/limit-order-simulation.sh +++ b/apitest/scripts/limit-order-simulation.sh @@ -1,5 +1,39 @@ #! /bin/bash +# Demonstrates a way to create a limit order (offer) using the API CLI with a local regtest bitcoin node. +# +# A country code argument is used to create a country based face to face payment account for the simulated offer. +# +# Prerequisites: +# +# - Linux or OSX with bash, Java 10, or Java 11-12 (JDK language compatibility 10), and bitcoin-core (v0.19, v0.20). +# +# - Bisq must be fully built with apitest dao setup files installed. +# Build command: `./gradlew clean build :apitest:installDaoSetup` +# +# - All supporting nodes must be run locally, in dev/dao/regtest mode: +# bitcoind, seednode, arbdaemon, alicedaemon, bobdaemon +# +# These should be run using the apitest harness. From the root project dir, run: +# `$ ./bisq-apitest --apiPassword=xyz --supportingApps=bitcoind,seednode,arbdaemon,alicedaemon,bobdaemon --shutdownAfterTests=false` +# +# - Only regtest btc can be bought or sold with the test payment account. +# +# Usage: +# +# This script must be run from the root of the project, e.g.: +# +# `$ apitest/scripts/limit-order-simulation.sh -l 40000 -d buy -c fr -m 3.00 -a 0.125` +# +# Script options: -l -d -c -m - f -a +# +# Example: +# +# Create a sell/eur offer to sell 0.125 btc at a fixed-price of 38,000 euros, using a France face to face +# payment account, when the BTC market price rises to or above 40,000 EUR: +# +# `$ apitest/scripts/limit-order-simulation.sh -l 40000 -d sell -c fr -m 0.00 -a 0.125` + APP_HOME=$(pwd -P) APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 39d1df19ca5..9e10f21ef6f 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -1,5 +1,44 @@ #! /bin/bash +# Runs fiat <-> btc trading scenarios using the API CLI with a local regtest bitcoin node. +# +# A country code argument is used to create a country based face to face payment account for the simulated +# trade, and the maker's face to face payment account's currency code is used when creating the offer. +# +# Prerequisites: +# +# - Linux or OSX with bash, Java 10, or Java 11-12 (JDK language compatibility 10), and bitcoin-core (v0.19, v0.20). +# +# - Bisq must be fully built with apitest dao setup files installed. +# Build command: `./gradlew clean build :apitest:installDaoSetup` +# +# - All supporting nodes must be run locally, in dev/dao/regtest mode: +# bitcoind, seednode, arbdaemon, alicedaemon, bobdaemon +# +# These should be run using the apitest harness. From the root project dir, run: +# `$ ./bisq-apitest --apiPassword=xyz --supportingApps=bitcoind,seednode,arbdaemon,alicedaemon,bobdaemon --shutdownAfterTests=false` +# +# - Only regtest btc can be bought or sold with the test payment account. +# +# Usage: +# +# This script must be run from the root of the project, e.g.: +# +# `$ apitest/scripts/trade-simulation.sh -d buy -c fr -m 3.00 -a 0.125` +# +# Script options: -d -c -m - f -a +# +# Examples: +# +# Create a buy/eur offer to buy 0.125 btc at a mkt-price-margin of 0%, using an Italy face to face payment account: +# +# `$ apitest/scripts/trade-simulation.sh -d buy -c it -m 0.00 -a 0.125` +# +# Create a sell/eur offer to sell 0.125 btc at a fixed-price of 38,000 euros, using a France face to face +# payment account: +# +# `$ apitest/scripts/trade-simulation.sh -d sell -c fr -f 38000 -a 0.125` + export APP_BASE_NAME=$(basename "$0") export APP_HOME=$(pwd -P) export APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" From cf419d2d58d622567b9043f9756beb6807e56101 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Tue, 19 Jan 2021 16:13:21 -0300 Subject: [PATCH 18/40] Make price request frequency configurable Added a -w option to allow user to control the frequency of price requests. The minimum value = 20s, default value = 120s. --- apitest/scripts/limit-order-simulation.sh | 4 ++-- apitest/scripts/trade-simulation-env.sh | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh index 95fc0add63c..8134f36d00e 100755 --- a/apitest/scripts/limit-order-simulation.sh +++ b/apitest/scripts/limit-order-simulation.sh @@ -25,7 +25,7 @@ # # `$ apitest/scripts/limit-order-simulation.sh -l 40000 -d buy -c fr -m 3.00 -a 0.125` # -# Script options: -l -d -c -m - f -a +# Script options: -l -d -c -m - f -a [-w ] # # Example: # @@ -109,7 +109,7 @@ while : ; do break fi - sleep 15 + sleep "$WAIT" done printdate "ALICE: Creating ${DIRECTION} ${CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}." diff --git a/apitest/scripts/trade-simulation-env.sh b/apitest/scripts/trade-simulation-env.sh index 51499c58e6d..64be81029a8 100755 --- a/apitest/scripts/trade-simulation-env.sh +++ b/apitest/scripts/trade-simulation-env.sh @@ -120,12 +120,12 @@ parseopts() { parselimitorderopts() { usage() { - echo "Usage: $0 [-l limit-price] [-d buy|sell] [-c ] [-f || -m ] [-a ]" 1>&2 + echo "Usage: $0 [-l limit-price] [-d buy|sell] [-c ] [-f || -m ] [-a ] [-w ]" 1>&2 exit 1; } - local OPTIND o l d c f m a - while getopts "l:d:c:f:m:a:" o; do + local OPTIND o l d c f m a w + while getopts "l:d:c:f:m:a:w:" o; do case "${o}" in l) l=${OPTARG} export LIMIT_PRICE=${l} @@ -146,6 +146,9 @@ parselimitorderopts() { a) a=${OPTARG} export AMOUNT=${a} ;; + w) w=${OPTARG} + export WAIT=${w} + ;; *) usage ;; esac done @@ -167,6 +170,13 @@ parselimitorderopts() { printdate "Must use margin-from-price param (-m) or fixed-price param (-f), not both." usage fi + + if [ -z "${w}" ]; then + WAIT=120 + elif [ "$w" -lt 20 ]; then + printdate "The -w option is too low, minimum allowed is 20s. Using default 120s." + WAIT=120 + fi } checkbitcoindrunning() { @@ -202,4 +212,8 @@ printscriptparams() { if [ -n "${ALICE_ROLE+1}" ]; then echo " ALICE_ROLE = ${ALICE_ROLE}" fi + + if [ -n "${WAIT+1}" ]; then + echo " WAIT = ${WAIT}" + fi } From 4eabb9804eb979db1c64ee336e74c2ec97b0f70d Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 10:35:53 -0300 Subject: [PATCH 19/40] Fix indentation For suggested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560898873 --- apitest/scripts/trade-simulation.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 9e10f21ef6f..23150c0cc7e 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -202,11 +202,11 @@ sleeptraced 3 # Complete the trade on the seller side. if [ "${DIRECTION}" = "BUY" ] then - printdate "BOB ${BOB_ROLE}: Closing trade by keeping funds in Bisq wallet." + printdate "BOB ${BOB_ROLE}: Closing trade by keeping funds in Bisq wallet." CMD="$CLI_BASE --port=${BOB_PORT} keepfunds --trade-id=${OFFER_ID}" printdate "BOB CLI: ${CMD}" else - printdate "ALICE (taker): Closing trade by keeping funds in Bisq wallet." + printdate "ALICE (taker): Closing trade by keeping funds in Bisq wallet." CMD="$CLI_BASE --port=${ALICE_PORT} keepfunds --trade-id=${OFFER_ID}" printdate "ALICE CLI: ${CMD}" fi From 71ffa0f9979cd22e91c8c6a5e3cca21fa677505b Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 10:41:21 -0300 Subject: [PATCH 20/40] Explain that paid tx fees are forfeited For suggested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560901896 --- core/src/main/resources/help/canceloffer-help.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/resources/help/canceloffer-help.txt b/core/src/main/resources/help/canceloffer-help.txt index 10627ce7045..248656396e3 100644 --- a/core/src/main/resources/help/canceloffer-help.txt +++ b/core/src/main/resources/help/canceloffer-help.txt @@ -11,7 +11,8 @@ canceloffer DESCRIPTION ----------- -Cancel an existing offer. The offer will be removed from other Bisq users' offer views. +Cancel an existing offer. The offer will be removed from other Bisq users' offer views, +and paid transaction fees will be forfeited. OPTIONS ------- From 86758414b75285be39c3a1acf1477f9a66625b07 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 10:45:41 -0300 Subject: [PATCH 21/40] Fix punctuation For suggested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560902858 --- core/src/main/resources/help/getmyoffer-help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/help/getmyoffer-help.txt b/core/src/main/resources/help/getmyoffer-help.txt index 4e93e43f1cd..c8ac347678a 100644 --- a/core/src/main/resources/help/getmyoffer-help.txt +++ b/core/src/main/resources/help/getmyoffer-help.txt @@ -11,7 +11,7 @@ getmyoffer DESCRIPTION ----------- -List one of your existing offer's details. +List one of your existing offers' details. OPTIONS ------- From fce3aab40def19d2a482c58a04507ad569ca3b23 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 10:59:49 -0300 Subject: [PATCH 22/40] Improve description For suggested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560905251 --- core/src/main/resources/help/getoffer-help.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/resources/help/getoffer-help.txt b/core/src/main/resources/help/getoffer-help.txt index 23056674387..8c42e552e11 100644 --- a/core/src/main/resources/help/getoffer-help.txt +++ b/core/src/main/resources/help/getoffer-help.txt @@ -11,8 +11,8 @@ getoffer DESCRIPTION ----------- -List an existing offer's details. The offer cannot be one of your own, and be -available for the taking, or it will not be viewable. +List an existing offer's details. The offer must not be one of your own. +The offer must be available to take with one of your matching payment accounts. OPTIONS ------- From 031b18edfa47d60081e337f48f49398470445ef3 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:02:09 -0300 Subject: [PATCH 23/40] Fix typo For requested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560906396 --- core/src/main/resources/help/keepfunds-help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/help/keepfunds-help.txt b/core/src/main/resources/help/keepfunds-help.txt index b5739744e8b..706ad5f2139 100644 --- a/core/src/main/resources/help/keepfunds-help.txt +++ b/core/src/main/resources/help/keepfunds-help.txt @@ -15,7 +15,7 @@ A BTC buyer completes the final step in the trade protocol by keeping received B Bisq wallet. This step may not seem necessary from the buyer's perspective, but it is necessary for correct transition of a trade's state to CLOSED, within the Bisq server. -The alternative way to close out the trade is to sen the received BTC to an external +The alternative way to close out the trade is to send the received BTC to an external BTC wallet, using the withdrawfunds command. OPTIONS From 11096d5c855f0e7f7866a9850b48594681d13717 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:05:23 -0300 Subject: [PATCH 24/40] Fix tx-fee-rate opt description For requested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560907371 --- core/src/main/resources/help/sendbtc-help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/help/sendbtc-help.txt b/core/src/main/resources/help/sendbtc-help.txt index 31ad5db0e51..4e43ff36c63 100644 --- a/core/src/main/resources/help/sendbtc-help.txt +++ b/core/src/main/resources/help/sendbtc-help.txt @@ -27,7 +27,7 @@ OPTIONS --tx-fee-rate An optional transaction fee rate (sats/byte) for the transaction. The user is responsible for choosing a fee rate that will be accepted by the network in a - reasonable amount of time, and the fee rate must be greater than 0. + reasonable amount of time, and the fee rate must be greater than 1 sat/byte. --memo An optional memo to be saved with the send btc transaction. From 72731e5c0386cecf92e23aa38a57f1c72fb18d3e Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:07:55 -0300 Subject: [PATCH 25/40] Add parens around (sats/byte) --- core/src/main/resources/help/sendbtc-help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/help/sendbtc-help.txt b/core/src/main/resources/help/sendbtc-help.txt index 4e43ff36c63..8cebcaae0d1 100644 --- a/core/src/main/resources/help/sendbtc-help.txt +++ b/core/src/main/resources/help/sendbtc-help.txt @@ -27,7 +27,7 @@ OPTIONS --tx-fee-rate An optional transaction fee rate (sats/byte) for the transaction. The user is responsible for choosing a fee rate that will be accepted by the network in a - reasonable amount of time, and the fee rate must be greater than 1 sat/byte. + reasonable amount of time, and the fee rate must be greater than 1 (sats/byte). --memo An optional memo to be saved with the send btc transaction. From 67eed01d74ca77844cbb65999cf28532128ca3e2 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:12:21 -0300 Subject: [PATCH 26/40] Fix tx-fee-rate opt description For requested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560906913 --- core/src/main/resources/help/sendbsq-help.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/resources/help/sendbsq-help.txt b/core/src/main/resources/help/sendbsq-help.txt index 92a03cea1a6..20ec6ade22f 100644 --- a/core/src/main/resources/help/sendbsq-help.txt +++ b/core/src/main/resources/help/sendbsq-help.txt @@ -26,7 +26,7 @@ OPTIONS --tx-fee-rate An optional transaction fee rate (sats/byte) for the transaction. The user is responsible for choosing a fee rate that will be accepted by the network in a - reasonable amount of time, and the fee rate must be greater than 0. + reasonable amount of time, and the fee rate must be greater than 1 (sats/byte). EXAMPLES -------- From 73c6b3d96b5fee382bb5f7295e2a263621690a11 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:16:54 -0300 Subject: [PATCH 27/40] Fix typo, group mutually exclusive opts around '||' --- apitest/scripts/limit-order-simulation.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh index 8134f36d00e..b065f4cb1ae 100755 --- a/apitest/scripts/limit-order-simulation.sh +++ b/apitest/scripts/limit-order-simulation.sh @@ -25,7 +25,7 @@ # # `$ apitest/scripts/limit-order-simulation.sh -l 40000 -d buy -c fr -m 3.00 -a 0.125` # -# Script options: -l -d -c -m - f -a [-w ] +# Script options: -l -d -c (-m || -f ) -a [-w ] # # Example: # From 6c322d4aae1b273ce81242816d55efc1a1f47ff8 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:20:30 -0300 Subject: [PATCH 28/40] Put $N variable references in double quotes For requested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560938698 --- apitest/scripts/trade-simulation-utils.sh | 30 +++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index 1bb83ff9173..3b613165e07 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -18,7 +18,7 @@ printcmd() { } sleeptraced() { - PERIOD=$1 + PERIOD="$1" printdate "sleeping for $PERIOD" sleep "$PERIOD" } @@ -63,8 +63,8 @@ getbtcoreaddress() { } genbtcblocks() { - NUM_BLOCKS=$1 - SECONDS_BETWEEN_BLOCKS=$2 + NUM_BLOCKS="$1" + SECONDS_BETWEEN_BLOCKS="$2" ADDR_PARAM="$(getbtcoreaddress)" CMD_PREFIX="bitcoin-cli -regtest -rpcport=19443 -rpcuser=apitest -rpcpassword=apitest generatetoaddress 1" # Print the generatetoaddress command with double quoted address param, to make it cut & pastable from the console. @@ -80,25 +80,25 @@ genbtcblocks() { } genbtcblock() { - CMD=$1 + CMD="$1" NEW_BLOCK_HASH=$(${CMD} | sed -n '2p') echo "$NEW_BLOCK_HASH" } escapepluschar() { - STRING=$1 + STRING="$1" NEW_STRING=$(echo "${STRING//+/\\+}") echo "${NEW_STRING}" } printbalances() { - PORT=$1 + PORT="$1" printcmd "${CLI_BASE} --port=${PORT} getbalance" $CLI_BASE --port="$PORT" getbalance } getpaymentaccountmethods() { - CMD=$1 + CMD="$1" CMD_OUTPUT=$(${CMD}) commandalert $? "Could not get payment method ids." printdate "Payment Method IDs:" @@ -106,14 +106,14 @@ getpaymentaccountmethods() { } getpaymentaccountform() { - CMD=$1 + CMD="$1" CMD_OUTPUT=$(${CMD}) commandalert $? "Could not get new payment account form." echo "${CMD_OUTPUT}" } editpaymentaccountform() { - COUNTRY_CODE=$1 + COUNTRY_CODE="$1" CMD="python3 ${APITEST_SCRIPTS_HOME}/editf2faccountform.py $COUNTRY_CODE" CMD_OUTPUT=$(${CMD}) commandalert $? "Could not edit payment account form." @@ -121,14 +121,14 @@ editpaymentaccountform() { } getnewpaymentacctid() { - CREATE_PAYMENT_ACCT_OUTPUT=$1 + CREATE_PAYMENT_ACCT_OUTPUT="$1" PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p') ACCT_ID=$(echo -e "$PAYMENT_ACCT_DETAIL" | awk '{print $NF}') echo "${ACCT_ID}" } getnewpaymentacctcurrency() { - CREATE_PAYMENT_ACCT_OUTPUT=$1 + CREATE_PAYMENT_ACCT_OUTPUT="$1" PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p') # This is brittle; it requires the account name field to have N words, # e.g, "Face to Face Payment Account" as defined in editf2faccountform.py. @@ -137,14 +137,14 @@ getnewpaymentacctcurrency() { } createpaymentacct() { - CMD=$1 + CMD="$1" CMD_OUTPUT=$(${CMD}) commandalert $? "Could not create new payment account." echo "${CMD_OUTPUT}" } getpaymentaccounts() { - PORT=$1 + PORT="$1" printcmd "${CLI_BASE} --port=${PORT} getpaymentaccts" CMD="$CLI_BASE --port=$PORT getpaymentaccts" CMD_OUTPUT=$(${CMD}) @@ -153,7 +153,7 @@ getpaymentaccounts() { } createoffer() { - CREATE_OFFER_CMD=$1 + CREATE_OFFER_CMD="$1" OFFER_DESC=$($CREATE_OFFER_CMD) # If the CLI command exited with an error, print the CLI error, and @@ -166,7 +166,7 @@ createoffer() { } getcurrentprice() { - CURRENCY_CODE=$1 + CURRENCY_CODE="$1" CMD="python3 ${APITEST_SCRIPTS_HOME}/getmktprice.py ${CURRENCY_CODE}" PRICE=$(${CMD}) echo "${PRICE}" From 0c06abdc56b9446aaf00290d521aee344bad857c Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:28:42 -0300 Subject: [PATCH 29/40] Replace shortform '. with longform 'source' For requested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560958418 --- apitest/scripts/limit-order-simulation.sh | 5 ++--- apitest/scripts/trade-simulation-utils.sh | 2 +- apitest/scripts/trade-simulation.sh | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh index b065f4cb1ae..fc3c3de07c4 100755 --- a/apitest/scripts/limit-order-simulation.sh +++ b/apitest/scripts/limit-order-simulation.sh @@ -37,9 +37,8 @@ APP_HOME=$(pwd -P) APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" -# Source the env and some helper functions. -. "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" -. "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" +source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" +source "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" checksetup parselimitorderopts "$@" diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index 3b613165e07..40851b4b41f 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -2,7 +2,7 @@ # This file must be sourced by the main driver. -. "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" +source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" printdate() { echo "[$(date)] $@" diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 23150c0cc7e..068f8abaf58 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -43,9 +43,8 @@ export APP_BASE_NAME=$(basename "$0") export APP_HOME=$(pwd -P) export APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts" -# Source the env and some helper functions. -. "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" -. "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" +source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh" +source "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh" checksetup parseopts "$@" From 8b4938a9eb8f4748c7d40055a46b15ebbdea5dc4 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:36:01 -0300 Subject: [PATCH 30/40] Do not export vars from lowest level child script For requested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560932201 --- apitest/scripts/trade-simulation-env.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apitest/scripts/trade-simulation-env.sh b/apitest/scripts/trade-simulation-env.sh index 64be81029a8..f976a40bb0a 100755 --- a/apitest/scripts/trade-simulation-env.sh +++ b/apitest/scripts/trade-simulation-env.sh @@ -2,11 +2,11 @@ # This file must be sourced by the main driver. -export CLI_BASE="./bisq-cli --password=xyz" -export ARBITRATOR_PORT=9997 -export ALICE_PORT=9998 -export BOB_PORT=9999 -export F2F_ACCT_FORM="f2f-acct.json" +CLI_BASE="./bisq-cli --password=xyz" +ARBITRATOR_PORT=9997 +ALICE_PORT=9998 +BOB_PORT=9999 +F2F_ACCT_FORM="f2f-acct.json" checksetup() { apitestusage() { From cb96f27f1c40e22f3122c9ca50a6d23b59829baa Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 11:52:29 -0300 Subject: [PATCH 31/40] Remove uneeded ${curlies} For requested change https://github.com/bisq-network/bisq/pull/5093#discussion_r560941709 --- apitest/scripts/trade-simulation-utils.sh | 16 ++++++++-------- apitest/scripts/trade-simulation.sh | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index 40851b4b41f..fcbcc304c1a 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -58,7 +58,7 @@ registerdisputeagents() { getbtcoreaddress() { CMD="bitcoin-cli -regtest -rpcport=19443 -rpcuser=apitest -rpcpassword=apitest getnewaddress" - NEW_ADDRESS=$(${CMD}) + NEW_ADDRESS=$($CMD) echo "${NEW_ADDRESS}" } @@ -81,7 +81,7 @@ genbtcblocks() { genbtcblock() { CMD="$1" - NEW_BLOCK_HASH=$(${CMD} | sed -n '2p') + NEW_BLOCK_HASH=$($CMD | sed -n '2p') echo "$NEW_BLOCK_HASH" } @@ -99,7 +99,7 @@ printbalances() { getpaymentaccountmethods() { CMD="$1" - CMD_OUTPUT=$(${CMD}) + CMD_OUTPUT=$($CMD) commandalert $? "Could not get payment method ids." printdate "Payment Method IDs:" echo "${CMD_OUTPUT}" @@ -107,7 +107,7 @@ getpaymentaccountmethods() { getpaymentaccountform() { CMD="$1" - CMD_OUTPUT=$(${CMD}) + CMD_OUTPUT=$($CMD) commandalert $? "Could not get new payment account form." echo "${CMD_OUTPUT}" } @@ -115,7 +115,7 @@ getpaymentaccountform() { editpaymentaccountform() { COUNTRY_CODE="$1" CMD="python3 ${APITEST_SCRIPTS_HOME}/editf2faccountform.py $COUNTRY_CODE" - CMD_OUTPUT=$(${CMD}) + CMD_OUTPUT=$($CMD) commandalert $? "Could not edit payment account form." printdate "Saved payment account form as ${F2F_ACCT_FORM}." } @@ -138,7 +138,7 @@ getnewpaymentacctcurrency() { createpaymentacct() { CMD="$1" - CMD_OUTPUT=$(${CMD}) + CMD_OUTPUT=$($CMD) commandalert $? "Could not create new payment account." echo "${CMD_OUTPUT}" } @@ -147,7 +147,7 @@ getpaymentaccounts() { PORT="$1" printcmd "${CLI_BASE} --port=${PORT} getpaymentaccts" CMD="$CLI_BASE --port=$PORT getpaymentaccts" - CMD_OUTPUT=$(${CMD}) + CMD_OUTPUT=$($CMD) commandalert $? "Could not get payment accounts." echo "${CMD_OUTPUT}" } @@ -168,7 +168,7 @@ createoffer() { getcurrentprice() { CURRENCY_CODE="$1" CMD="python3 ${APITEST_SCRIPTS_HOME}/getmktprice.py ${CURRENCY_CODE}" - PRICE=$(${CMD}) + PRICE=$($CMD) echo "${PRICE}" } diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 068f8abaf58..44fd2af68e2 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -73,8 +73,8 @@ cat "${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}" # Remove the autogenerated json template because we are going to use one created by a python script in the next step. CMD="rm -v ${APP_HOME}/f2f_*.json" -DELETE_JSON_TEMPLATE=$(${CMD}) -echo "$DELETE_JSON_TEMPLATE" +DELETE_JSON_TEMPLATE=$($CMD) +printdate "$DELETE_JSON_TEMPLATE" printbreak printdate "Bob and Alice create their face to face ${COUNTRY_CODE} payment accounts." From 078f010125ce96ff5da9ac63d11349b2536e864f Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 12:03:21 -0300 Subject: [PATCH 32/40] Remove api dev/test log statement This server log output was intended as an aid to api devs, but is no longer needed after the change to posix-sytle method opts with self explanatory labels (replacing the ambiguous positional CLI method opts). --- .../bisq/core/offer/CreateOfferService.java | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/CreateOfferService.java b/core/src/main/java/bisq/core/offer/CreateOfferService.java index 089169bdbea..733eee1a7f9 100644 --- a/core/src/main/java/bisq/core/offer/CreateOfferService.java +++ b/core/src/main/java/bisq/core/offer/CreateOfferService.java @@ -129,26 +129,6 @@ public Offer createAndGetOffer(String offerId, minAmount.value, buyerSecurityDepositAsDouble); - // Log an approximate api CLI 'createoffer' dev/test param list. - log.info("cli's createoffer positional option names: paymentAccountId direction currencyCode amount minAmount" - + " useMarketBasedPrice fixedPrice|marketPriceMargin buyerSecurityDeposit"); - log.info("cli's createoffer positional option values: {} " + - "{} " + - "{} " + - "{} " + - "{} " + - "{} " + - "{} " + - "{}", - paymentAccount.getId(), - direction.name(), - currencyCode, - amount.value, - minAmount.value, - useMarketBasedPrice, - (useMarketBasedPrice ? marketPriceMargin : price.getValue()), - buyerSecurityDepositAsDouble); - long creationTime = new Date().getTime(); NodeAddress makerAddress = p2PService.getAddress(); boolean useMarketBasedPriceValue = useMarketBasedPrice && From 3244db12c45ae5a5864a9e4706c5b97ff3e29d46 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 13:08:52 -0300 Subject: [PATCH 33/40] Print current market price just before offer is created This may help confirm offer.price correctness in periods of BTC price stability. --- apitest/scripts/trade-simulation.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index 44fd2af68e2..dcd138f6bf0 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -97,6 +97,8 @@ printdate "ALICE F2F payment-account-id = ${ALICE_ACCT_ID}, currency-code = ${AL printbreak printdate "ALICE ${ALICE_ROLE}: Creating ${DIRECTION} ${ALICE_ACCT_CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}." +CURRENT_PRICE=$(getcurrentprice "$ALICE_ACCT_CURRENCY_CODE") +printdate "Current Market Price: $CURRENT_PRICE $ALICE_ACCT_CURRENCY_CODE" CMD="$CLI_BASE --port=${ALICE_PORT} createoffer" CMD+=" --payment-account=${ALICE_ACCT_ID}" CMD+=" --direction=${DIRECTION}" From ced422e930548e2411ef108fc86c34e4cabb04e8 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 15:01:16 -0300 Subject: [PATCH 34/40] Add new api CLI method 'getbtcprice' The server impl was there, but it is now needed by the trading sim scripts (CLI) to get the price from the Bisq server instead of the feed. (The server does not request prices more than once a minute.) --- cli/src/main/java/bisq/cli/CliMain.java | 20 +++++++ .../main/java/bisq/cli/CurrencyFormat.java | 5 ++ cli/src/main/java/bisq/cli/Method.java | 1 + .../opts/GetBTCMarketPriceOptionParser.java | 52 +++++++++++++++++++ .../main/resources/help/getbtcprice-help.txt | 30 +++++++++++ 5 files changed, 108 insertions(+) create mode 100644 cli/src/main/java/bisq/cli/opts/GetBTCMarketPriceOptionParser.java create mode 100644 core/src/main/resources/help/getbtcprice-help.txt diff --git a/cli/src/main/java/bisq/cli/CliMain.java b/cli/src/main/java/bisq/cli/CliMain.java index eb9253b3be7..16ba360ea2d 100644 --- a/cli/src/main/java/bisq/cli/CliMain.java +++ b/cli/src/main/java/bisq/cli/CliMain.java @@ -40,6 +40,7 @@ import bisq.proto.grpc.GetVersionRequest; import bisq.proto.grpc.KeepFundsRequest; import bisq.proto.grpc.LockWalletRequest; +import bisq.proto.grpc.MarketPriceRequest; import bisq.proto.grpc.OfferInfo; import bisq.proto.grpc.RegisterDisputeAgentRequest; import bisq.proto.grpc.RemoveWalletPasswordRequest; @@ -75,6 +76,7 @@ import lombok.extern.slf4j.Slf4j; +import static bisq.cli.CurrencyFormat.formatMarketPrice; import static bisq.cli.CurrencyFormat.formatTxFeeRateInfo; import static bisq.cli.CurrencyFormat.toSatoshis; import static bisq.cli.CurrencyFormat.toSecurityDepositAsPct; @@ -98,6 +100,7 @@ import bisq.cli.opts.CreateOfferOptionParser; import bisq.cli.opts.CreatePaymentAcctOptionParser; import bisq.cli.opts.GetAddressBalanceOptionParser; +import bisq.cli.opts.GetBTCMarketPriceOptionParser; import bisq.cli.opts.GetBalanceOptionParser; import bisq.cli.opts.GetOfferOptionParser; import bisq.cli.opts.GetOffersOptionParser; @@ -189,6 +192,7 @@ public static void run(String[] args) { var helpService = grpcStubs.helpService; var offersService = grpcStubs.offersService; var paymentAccountsService = grpcStubs.paymentAccountsService; + var priceService = grpcStubs.priceService; var tradesService = grpcStubs.tradesService; var versionService = grpcStubs.versionService; var walletsService = grpcStubs.walletsService; @@ -243,6 +247,20 @@ public static void run(String[] args) { out.println(formatAddressBalanceTbl(singletonList(reply.getAddressBalanceInfo()))); return; } + case getbtcprice: { + var opts = new GetBTCMarketPriceOptionParser(args).parse(); + if (opts.isForHelp()) { + out.println(getMethodHelp(helpService, method)); + return; + } + var currencyCode = opts.getCurrencyCode(); + var request = MarketPriceRequest.newBuilder() + .setCurrencyCode(currencyCode) + .build(); + var reply = priceService.getMarketPrice(request); + out.println(formatMarketPrice(reply.getPrice())); + return; + } case getfundingaddresses: { if (new SimpleMethodOptionParser(args).parse().isForHelp()) { out.println(getMethodHelp(helpService, method)); @@ -802,6 +820,8 @@ private static void printHelp(OptionParser parser, @SuppressWarnings("SameParame stream.println(); stream.format(rowFormat, getaddressbalance.name(), "--address=", "Get server wallet address balance"); stream.println(); + stream.format(rowFormat, getbtcprice.name(), "--currency-code=", "Get current market btc price"); + stream.println(); stream.format(rowFormat, getfundingaddresses.name(), "", "Get BTC funding addresses"); stream.println(); stream.format(rowFormat, getunusedbsqaddress.name(), "", "Get unused BSQ address"); diff --git a/cli/src/main/java/bisq/cli/CurrencyFormat.java b/cli/src/main/java/bisq/cli/CurrencyFormat.java index c5ea5a497b0..a076c5ce5ae 100644 --- a/cli/src/main/java/bisq/cli/CurrencyFormat.java +++ b/cli/src/main/java/bisq/cli/CurrencyFormat.java @@ -77,6 +77,11 @@ static String formatVolumeRange(long minVolume, long volume) { : formatOfferVolume(volume); } + static String formatMarketPrice(double price) { + NUMBER_FORMAT.setMinimumFractionDigits(4); + return NUMBER_FORMAT.format(price); + } + static String formatOfferPrice(long price) { NUMBER_FORMAT.setMaximumFractionDigits(4); NUMBER_FORMAT.setMinimumFractionDigits(4); diff --git a/cli/src/main/java/bisq/cli/Method.java b/cli/src/main/java/bisq/cli/Method.java index c2490ee1d44..266e95751fa 100644 --- a/cli/src/main/java/bisq/cli/Method.java +++ b/cli/src/main/java/bisq/cli/Method.java @@ -28,6 +28,7 @@ public enum Method { createpaymentacct, getaddressbalance, getbalance, + getbtcprice, getfundingaddresses, getmyoffer, getmyoffers, diff --git a/cli/src/main/java/bisq/cli/opts/GetBTCMarketPriceOptionParser.java b/cli/src/main/java/bisq/cli/opts/GetBTCMarketPriceOptionParser.java new file mode 100644 index 00000000000..c54f65f42e9 --- /dev/null +++ b/cli/src/main/java/bisq/cli/opts/GetBTCMarketPriceOptionParser.java @@ -0,0 +1,52 @@ +/* + * This file is part of Bisq. + * + * Bisq is free software: you can redistribute it and/or modify it + * under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. + * + * Bisq is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + * License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with Bisq. If not, see . + */ + +package bisq.cli.opts; + + +import joptsimple.OptionSpec; + +import static bisq.cli.opts.OptLabel.OPT_CURRENCY_CODE; +import static joptsimple.internal.Strings.EMPTY; + +public class GetBTCMarketPriceOptionParser extends AbstractMethodOptionParser implements MethodOpts { + + final OptionSpec currencyCodeOpt = parser.accepts(OPT_CURRENCY_CODE, "currency-code") + .withRequiredArg() + .defaultsTo(EMPTY); + + public GetBTCMarketPriceOptionParser(String[] args) { + super(args); + } + + public GetBTCMarketPriceOptionParser parse() { + super.parse(); + + // Short circuit opt validation if user just wants help. + if (options.has(helpOpt)) + return this; + + if (!options.has(currencyCodeOpt)) + throw new IllegalArgumentException("no currency code specified"); + + return this; + } + + public String getCurrencyCode() { + return options.valueOf(currencyCodeOpt); + } +} diff --git a/core/src/main/resources/help/getbtcprice-help.txt b/core/src/main/resources/help/getbtcprice-help.txt new file mode 100644 index 00000000000..cd0e79f0278 --- /dev/null +++ b/core/src/main/resources/help/getbtcprice-help.txt @@ -0,0 +1,30 @@ +getbtcprice + +NAME +---- +getbtcprice - get current btc market price + +SYNOPSIS +-------- +getbtcprice + --currency-code= + +DESCRIPTION +----------- +Returns the current market BTC price for the given currency-code. + +OPTIONS +------- + +--currency-code + The three letter code for the fiat currency code, e.g., EUR, USD, BRL, ... + +EXAMPLES +-------- +Get the current BTC market price in Euros: +$ ./bisq-cli --password=xyz --port=9998 getbtcprice --currency-code=eur + +Get the current BTC market price in Brazilian Reais: +$ ./bisq-cli --password=xyz --port=9998 getbtcprice --currency-code=brl + + From 20e16493aa6cdb583bea23dca74fc64ae1a37205 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 15:13:07 -0300 Subject: [PATCH 35/40] Get current mkt price from server, not directly from feed --- apitest/scripts/limit-order-simulation.sh | 17 ++++++++++++++--- apitest/scripts/trade-simulation-utils.sh | 15 ++++++++++----- apitest/scripts/trade-simulation.sh | 17 ++++++++++++++--- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/apitest/scripts/limit-order-simulation.sh b/apitest/scripts/limit-order-simulation.sh index fc3c3de07c4..253deec1a8a 100755 --- a/apitest/scripts/limit-order-simulation.sh +++ b/apitest/scripts/limit-order-simulation.sh @@ -93,8 +93,9 @@ while : ; do break fi - CURRENT_PRICE=$(getcurrentprice "${CURRENCY_CODE}") - printdate "Current Price: ${CURRENT_PRICE} ${CURRENCY_CODE}" + CURRENT_PRICE=$(getcurrentprice "$ALICE_PORT" "$CURRENCY_CODE") + exitoncommandalert $? + printdate "Current Market Price: $CURRENT_PRICE" if [ "$DIRECTION" = "BUY" ] && [ "$CURRENT_PRICE" -le "$LIMIT_PRICE" ]; then printdate "Limit price reached." @@ -129,7 +130,17 @@ OFFER_ID=$(createoffer "${CMD}") exitoncommandalert $? printdate "ALICE: Created offer with id: ${OFFER_ID}." printbreak -sleeptraced 10 +sleeptraced 3 + +# Show Alice's new offer. +printdate "ALICE: Looking at her new ${DIRECTION} ${CURRENCY_CODE} offer." +CMD="$CLI_BASE --port=${ALICE_PORT} getmyoffer --offer-id=${OFFER_ID}" +printdate "ALICE CLI: ${CMD}" +OFFER=$($CMD) +exitoncommandalert $? +echo "${OFFER}" +printbreak +sleeptraced 7 # Generate some btc blocks. printdate "Generating btc blocks after publishing Alice's offer." diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index fcbcc304c1a..18c5d507e2b 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -166,9 +166,14 @@ createoffer() { } getcurrentprice() { - CURRENCY_CODE="$1" - CMD="python3 ${APITEST_SCRIPTS_HOME}/getmktprice.py ${CURRENCY_CODE}" - PRICE=$($CMD) - echo "${PRICE}" + PORT="$1" + CURRENCY_CODE="$2" + CMD="$CLI_BASE --port=$PORT getbtcprice --currency-code=$CURRENCY_CODE" + CMD_OUTPUT=$($CMD) + commandalert $? "Could not get current market $CURRENCY_CODE price." + FLOOR=$(echo $CMD_OUTPUT| cut -d'.' -f 1) + commandalert $? "Could not get the floor of the current market $CURRENCY_CODE price." + INTEGER=$(echo $FLOOR | tr -cd '[[:digit:]]') + commandalert $? "Could not convert the current market $CURRENCY_CODE price string to an integer." + echo "$INTEGER" } - diff --git a/apitest/scripts/trade-simulation.sh b/apitest/scripts/trade-simulation.sh index dcd138f6bf0..3928cbf4471 100755 --- a/apitest/scripts/trade-simulation.sh +++ b/apitest/scripts/trade-simulation.sh @@ -97,8 +97,9 @@ printdate "ALICE F2F payment-account-id = ${ALICE_ACCT_ID}, currency-code = ${AL printbreak printdate "ALICE ${ALICE_ROLE}: Creating ${DIRECTION} ${ALICE_ACCT_CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}." -CURRENT_PRICE=$(getcurrentprice "$ALICE_ACCT_CURRENCY_CODE") -printdate "Current Market Price: $CURRENT_PRICE $ALICE_ACCT_CURRENCY_CODE" +CURRENT_PRICE=$(getcurrentprice "$ALICE_PORT" "$ALICE_ACCT_CURRENCY_CODE") +exitoncommandalert $? +printdate "Current Market Price: $CURRENT_PRICE" CMD="$CLI_BASE --port=${ALICE_PORT} createoffer" CMD+=" --payment-account=${ALICE_ACCT_ID}" CMD+=" --direction=${DIRECTION}" @@ -116,7 +117,17 @@ OFFER_ID=$(createoffer "${CMD}") exitoncommandalert $? printdate "ALICE ${ALICE_ROLE}: Created offer with id: ${OFFER_ID}." printbreak -sleeptraced 10 +sleeptraced 3 + +# Show Alice's new offer. +printdate "ALICE ${ALICE_ROLE}: Looking at her new ${DIRECTION} ${CURRENCY_CODE} offer." +CMD="$CLI_BASE --port=${ALICE_PORT} getmyoffer --offer-id=${OFFER_ID}" +printdate "ALICE CLI: ${CMD}" +OFFER=$($CMD) +exitoncommandalert $? +echo "${OFFER}" +printbreak +sleeptraced 7 # Generate some btc blocks. printdate "Generating btc blocks after publishing Alice's offer." From 7fa61c9a322dcd9d1b9e6d929dc44a79d6599d05 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 15:14:20 -0300 Subject: [PATCH 36/40] Remove deprecated python script --- apitest/scripts/getmktprice.py | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 apitest/scripts/getmktprice.py diff --git a/apitest/scripts/getmktprice.py b/apitest/scripts/getmktprice.py deleted file mode 100644 index a8885df320f..00000000000 --- a/apitest/scripts/getmktprice.py +++ /dev/null @@ -1,22 +0,0 @@ -import sys, requests - -# Returns the current BTC price for the given currency_code from a cleartext price service. - -if len(sys.argv) < 2: - print("usage: getmktprice.py currency_code") - exit(1) - -currency_code = str(sys.argv[1]).upper() - -url = "https://price.bisq.wiz.biz/getAllMarketPrices" -resp = requests.get(url) -if resp.status_code == 200: - for i in resp.json()['data']: - if i['currencyCode'] == currency_code: - print(int(i['price'])) - break -else: - print('Error: Could not get ' + currency_code + ' price.') - exit(1) - -exit(0) From 78d00243687cf2a62f22bd19a5316ec43f139984 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 15:25:22 -0300 Subject: [PATCH 37/40] Re-add exports to make codacy happy --- apitest/scripts/trade-simulation-env.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/apitest/scripts/trade-simulation-env.sh b/apitest/scripts/trade-simulation-env.sh index f976a40bb0a..64be81029a8 100755 --- a/apitest/scripts/trade-simulation-env.sh +++ b/apitest/scripts/trade-simulation-env.sh @@ -2,11 +2,11 @@ # This file must be sourced by the main driver. -CLI_BASE="./bisq-cli --password=xyz" -ARBITRATOR_PORT=9997 -ALICE_PORT=9998 -BOB_PORT=9999 -F2F_ACCT_FORM="f2f-acct.json" +export CLI_BASE="./bisq-cli --password=xyz" +export ARBITRATOR_PORT=9997 +export ALICE_PORT=9998 +export BOB_PORT=9999 +export F2F_ACCT_FORM="f2f-acct.json" checksetup() { apitestusage() { From 184ffd14dbf99db4d9a87241bf878afd36fea46d Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 15:26:36 -0300 Subject: [PATCH 38/40] Enclose $vars in double quotes --- apitest/scripts/trade-simulation-utils.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apitest/scripts/trade-simulation-utils.sh b/apitest/scripts/trade-simulation-utils.sh index 18c5d507e2b..d41ef2b80d2 100755 --- a/apitest/scripts/trade-simulation-utils.sh +++ b/apitest/scripts/trade-simulation-utils.sh @@ -171,9 +171,9 @@ getcurrentprice() { CMD="$CLI_BASE --port=$PORT getbtcprice --currency-code=$CURRENCY_CODE" CMD_OUTPUT=$($CMD) commandalert $? "Could not get current market $CURRENCY_CODE price." - FLOOR=$(echo $CMD_OUTPUT| cut -d'.' -f 1) + FLOOR=$(echo "$CMD_OUTPUT" | cut -d'.' -f 1) commandalert $? "Could not get the floor of the current market $CURRENCY_CODE price." - INTEGER=$(echo $FLOOR | tr -cd '[[:digit:]]') + INTEGER=$(echo "$FLOOR" | tr -cd '[[:digit:]]') commandalert $? "Could not convert the current market $CURRENCY_CODE price string to an integer." echo "$INTEGER" } From d18b2d5a10381dd01da97e7541621eda8c910358 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 17:46:35 -0300 Subject: [PATCH 39/40] Run an async price feed request when CLI needs market price The CLI was receiving stale, cached market prices from the feed service. --- core/src/main/java/bisq/core/api/CoreApi.java | 4 +-- .../java/bisq/core/api/CorePriceService.java | 28 +++++++++++++------ .../bisq/daemon/grpc/GrpcPriceService.java | 10 ++++--- 3 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/bisq/core/api/CoreApi.java b/core/src/main/java/bisq/core/api/CoreApi.java index fb3c8f8a380..caecdfb7b81 100644 --- a/core/src/main/java/bisq/core/api/CoreApi.java +++ b/core/src/main/java/bisq/core/api/CoreApi.java @@ -213,8 +213,8 @@ public String getPaymentAccountForm(String paymentMethodId) { // Prices /////////////////////////////////////////////////////////////////////////////////////////// - public double getMarketPrice(String currencyCode) { - return corePriceService.getMarketPrice(currencyCode); + public void getMarketPrice(String currencyCode, Consumer resultHandler) { + corePriceService.getMarketPrice(currencyCode, resultHandler); } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/core/src/main/java/bisq/core/api/CorePriceService.java b/core/src/main/java/bisq/core/api/CorePriceService.java index 9eb4069dfe9..5c33b8634f5 100644 --- a/core/src/main/java/bisq/core/api/CorePriceService.java +++ b/core/src/main/java/bisq/core/api/CorePriceService.java @@ -17,17 +17,17 @@ package bisq.core.api; -import bisq.core.provider.price.MarketPrice; import bisq.core.provider.price.PriceFeedService; import javax.inject.Inject; import javax.inject.Singleton; +import java.util.function.Consumer; + import lombok.extern.slf4j.Slf4j; import static bisq.common.util.MathUtils.roundDouble; import static java.lang.String.format; -import static java.util.Objects.requireNonNull; @Singleton @Slf4j @@ -40,15 +40,25 @@ public CorePriceService(PriceFeedService priceFeedService) { this.priceFeedService = priceFeedService; } - public double getMarketPrice(String currencyCode) { + public void getMarketPrice(String currencyCode, Consumer resultHandler) { if (!priceFeedService.hasPrices()) throw new IllegalStateException("price feed service has no prices"); - MarketPrice marketPrice = priceFeedService.getMarketPrice(currencyCode.toUpperCase()); - if (requireNonNull(marketPrice).isPriceAvailable()) { - return roundDouble(marketPrice.getPrice(), 4); - } else { - throw new IllegalStateException(format("'%s' price is not available", currencyCode)); - } + priceFeedService.setCurrencyCode(currencyCode.toUpperCase()); + + priceFeedService.requestPriceFeed(price -> { + if (price > 0) { + log.info("{} price feed request returned {}", priceFeedService.getCurrencyCode(), price); + resultHandler.accept(roundDouble(price, 4)); + } else { + throw new IllegalStateException(format("%s price is not available", + priceFeedService.getCurrencyCode())); + } + }, + (errorMessage, throwable) -> { + log.error(errorMessage, throwable); + throw new IllegalStateException(format("%s price feed request failed", + priceFeedService.getCurrencyCode())); + }); } } diff --git a/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java b/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java index c8d20fcf29b..7930b7b300d 100644 --- a/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java +++ b/daemon/src/main/java/bisq/daemon/grpc/GrpcPriceService.java @@ -45,10 +45,12 @@ public GrpcPriceService(CoreApi coreApi, GrpcExceptionHandler exceptionHandler) public void getMarketPrice(MarketPriceRequest req, StreamObserver responseObserver) { try { - double price = coreApi.getMarketPrice(req.getCurrencyCode()); - var reply = MarketPriceReply.newBuilder().setPrice(price).build(); - responseObserver.onNext(reply); - responseObserver.onCompleted(); + coreApi.getMarketPrice(req.getCurrencyCode(), + price -> { + var reply = MarketPriceReply.newBuilder().setPrice(price).build(); + responseObserver.onNext(reply); + responseObserver.onCompleted(); + }); } catch (Throwable cause) { exceptionHandler.handleException(cause, responseObserver); } From b2d8faf2cd93b867c8f447cf2191bf6ddf241fca Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 20 Jan 2021 19:27:35 -0300 Subject: [PATCH 40/40] Log price feed request warnings, do not throw to CLI The price feed service throws PriceRequestExceptions when switching currencies, log those exceptions as warnings in the server and don't pass them up to the CLI. --- .../java/bisq/core/api/CorePriceService.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/bisq/core/api/CorePriceService.java b/core/src/main/java/bisq/core/api/CorePriceService.java index 5c33b8634f5..4553689e98a 100644 --- a/core/src/main/java/bisq/core/api/CorePriceService.java +++ b/core/src/main/java/bisq/core/api/CorePriceService.java @@ -27,6 +27,7 @@ import lombok.extern.slf4j.Slf4j; import static bisq.common.util.MathUtils.roundDouble; +import static bisq.core.locale.CurrencyUtil.isFiatCurrency; import static java.lang.String.format; @Singleton @@ -41,24 +42,28 @@ public CorePriceService(PriceFeedService priceFeedService) { } public void getMarketPrice(String currencyCode, Consumer resultHandler) { + String upperCaseCurrencyCode = currencyCode.toUpperCase(); + + if (!isFiatCurrency(upperCaseCurrencyCode)) + throw new IllegalStateException(format("%s is not a valid currency code", upperCaseCurrencyCode)); + if (!priceFeedService.hasPrices()) throw new IllegalStateException("price feed service has no prices"); - priceFeedService.setCurrencyCode(currencyCode.toUpperCase()); + try { + priceFeedService.setCurrencyCode(upperCaseCurrencyCode); + } catch (Throwable throwable) { + log.warn("Could not set currency code in PriceFeedService", throwable); + } priceFeedService.requestPriceFeed(price -> { if (price > 0) { - log.info("{} price feed request returned {}", priceFeedService.getCurrencyCode(), price); + log.info("{} price feed request returned {}", upperCaseCurrencyCode, price); resultHandler.accept(roundDouble(price, 4)); } else { - throw new IllegalStateException(format("%s price is not available", - priceFeedService.getCurrencyCode())); + throw new IllegalStateException(format("%s price is not available", upperCaseCurrencyCode)); } }, - (errorMessage, throwable) -> { - log.error(errorMessage, throwable); - throw new IllegalStateException(format("%s price feed request failed", - priceFeedService.getCurrencyCode())); - }); + (errorMessage, throwable) -> log.warn(errorMessage, throwable)); } }