2021-01-19 17:46:55 +01:00
|
|
|
#! /bin/bash
|
|
|
|
|
2021-01-19 19:00:47 +01:00
|
|
|
# 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:
|
|
|
|
#
|
2021-04-19 17:35:13 +02:00
|
|
|
# - Linux or OSX with bash, Java 10, or Java 11-12 (JDK language compatibility 10), and bitcoin-core (v0.19, v0.20, or v0.21).
|
2021-01-19 19:00:47 +01:00
|
|
|
#
|
|
|
|
# - 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 <direction> -c <country-code> -m <mkt-price-margin(%)> - f <fixed-price> -a <amount(btc)>
|
|
|
|
#
|
|
|
|
# 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`
|
|
|
|
|
2021-01-19 17:46:55 +01:00
|
|
|
export APP_BASE_NAME=$(basename "$0")
|
|
|
|
export APP_HOME=$(pwd -P)
|
2021-01-25 16:30:59 +01:00
|
|
|
export APITEST_SCRIPTS_HOME="$APP_HOME/apitest/scripts"
|
2021-01-19 17:46:55 +01:00
|
|
|
|
2021-01-25 16:30:59 +01:00
|
|
|
source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh"
|
|
|
|
source "$APITEST_SCRIPTS_HOME/trade-simulation-utils.sh"
|
2021-01-19 17:46:55 +01:00
|
|
|
|
|
|
|
checksetup
|
|
|
|
parseopts "$@"
|
|
|
|
|
2021-01-25 16:30:59 +01:00
|
|
|
printdate "Started $APP_BASE_NAME with parameters:"
|
2021-01-19 17:46:55 +01:00
|
|
|
printscriptparams
|
|
|
|
printbreak
|
|
|
|
|
|
|
|
registerdisputeagents
|
|
|
|
|
2021-01-28 23:33:21 +01:00
|
|
|
# Demonstrate how to create a country based, face to face account.
|
|
|
|
showcreatepaymentacctsteps "Alice" "$ALICE_PORT"
|
2021-01-19 17:46:55 +01:00
|
|
|
|
2021-01-28 23:33:21 +01:00
|
|
|
CMD="$CLI_BASE --port=$ALICE_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM"
|
2021-01-25 16:30:59 +01:00
|
|
|
printdate "ALICE CLI: $CMD"
|
2021-01-28 23:33:21 +01:00
|
|
|
CMD_OUTPUT=$(createpaymentacct "$CMD")
|
|
|
|
echo "$CMD_OUTPUT"
|
2021-01-19 17:46:55 +01:00
|
|
|
printbreak
|
2021-01-28 23:33:21 +01:00
|
|
|
export ALICE_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT")
|
|
|
|
export CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT")
|
|
|
|
printdate "Alice's F2F payment-account-id: $ALICE_ACCT_ID, currency-code: $CURRENCY_CODE"
|
|
|
|
exitoncommandalert $?
|
2021-01-19 17:46:55 +01:00
|
|
|
printbreak
|
|
|
|
|
2021-01-28 23:33:21 +01:00
|
|
|
printdate "Bob creates his F2F payment account."
|
2021-01-25 16:30:59 +01:00
|
|
|
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"
|
2021-01-19 17:46:55 +01:00
|
|
|
printbreak
|
2021-01-28 23:33:21 +01:00
|
|
|
export BOB_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT")
|
|
|
|
export CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT")
|
|
|
|
printdate "Bob's F2F payment-account-id: $BOB_ACCT_ID, currency-code: $CURRENCY_CODE"
|
|
|
|
exitoncommandalert $?
|
2021-01-19 17:46:55 +01:00
|
|
|
printbreak
|
|
|
|
|
2021-01-28 23:33:21 +01:00
|
|
|
# Alice creates an offer.
|
|
|
|
printdate "ALICE $ALICE_ROLE: Creating $DIRECTION $CURRENCY_CODE offer with payment acct $ALICE_ACCT_ID."
|
|
|
|
CURRENT_PRICE=$(getcurrentprice "$ALICE_PORT" "$CURRENCY_CODE")
|
2021-01-20 19:13:07 +01:00
|
|
|
exitoncommandalert $?
|
|
|
|
printdate "Current Market Price: $CURRENT_PRICE"
|
2021-01-28 23:56:15 +01:00
|
|
|
CMD=$(gencreateoffercommand "$ALICE_PORT" "$ALICE_ACCT_ID")
|
2021-01-25 16:30:59 +01:00
|
|
|
printdate "ALICE CLI: $CMD"
|
|
|
|
OFFER_ID=$(createoffer "$CMD")
|
2021-01-19 17:46:55 +01:00
|
|
|
exitoncommandalert $?
|
2021-01-25 16:30:59 +01:00
|
|
|
printdate "ALICE $ALICE_ROLE: Created offer with id: $OFFER_ID."
|
2021-01-19 17:46:55 +01:00
|
|
|
printbreak
|
2021-01-20 19:13:07 +01:00
|
|
|
sleeptraced 3
|
|
|
|
|
|
|
|
# Show Alice's new offer.
|
2021-01-25 16:30:59 +01:00
|
|
|
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"
|
2021-01-20 19:13:07 +01:00
|
|
|
OFFER=$($CMD)
|
|
|
|
exitoncommandalert $?
|
2021-01-25 16:30:59 +01:00
|
|
|
echo "$OFFER"
|
2021-01-20 19:13:07 +01:00
|
|
|
printbreak
|
2021-01-29 22:04:02 +01:00
|
|
|
sleeptraced 3
|
2021-01-19 17:46:55 +01:00
|
|
|
|
|
|
|
# Generate some btc blocks.
|
|
|
|
printdate "Generating btc blocks after publishing Alice's offer."
|
2021-01-29 22:04:02 +01:00
|
|
|
genbtcblocks 3 1
|
2021-01-19 17:46:55 +01:00
|
|
|
printbreak
|
|
|
|
|
2021-01-28 23:33:21 +01:00
|
|
|
# Go through the trade protocol.
|
|
|
|
executetrade
|
2021-01-19 17:46:55 +01:00
|
|
|
exitoncommandalert $?
|
|
|
|
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
|