[bisq-network/bisq] Add api trade simulation scripts (#5093)

dmos62 notifications at github.com
Wed Jan 20 14:31:28 CET 2021


@dmos62 commented on this pull request.



> +#
+#  - 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 <limit-price> -d <direction> -c <country-code> -m <mkt-price-margin(%)> - f <fixed-price> -a <amount(btc)> [-w <price-poll-interval(s)>]

`- f <fixed-price>` -> `-f <fixed-price>`

> @@ -0,0 +1,219 @@
+#! /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"

`export` is for putting these variables in child processes' environments, but I don't think these variables are used by child processes in this case. If these variables are only used by other scripts by having this one `source`d, then the `export` prefixes aren't necessary.

> +    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

It's safer to double quote these variable references (`NUM_BLOCKS="$1"`). See https://tldp.org/LDP/abs/html/quotingvar.html It's a quirk of Bash. Applies to other variable references in the PR as well.

> +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})

`${` is inconsistent with some other variable references. It's usually used when you have something like `${var}postifx` (you couldn't do `$varpostfix`). `$($CMD)` should be enough here. Though either is fine, whatever you think is more readable, it's just that it would be nice if the choice were consistent.

> +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}")

These references are a bit more complicated to quote because of nested variable references. Escaping the inner quotes should do the trick: `CMD_OUTPUT="$(createpaymentacct \"${CMD}\")"`. Readability isn't great. Alternatively, at the risk of too much vertical verbosity, you could split the inner part into a new variable: `tmp="createpaymentacct $CMD"`.

> +#    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"
+
+# Source the env and some helper functions.
+. "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh"
+. "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh"

The longform `source` might be preferable to the shortform `.` due to readability. 

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/5093#pullrequestreview-572173650
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20210120/3c49056a/attachment-0001.htm>


More information about the bisq-github mailing list