<commit_before>#! /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=<PASSWORD> --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`

export APP_BASE_NAME=$(basename "$0")
export APP_HOME=$(pwd -P)
export APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts"

source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh"
source "${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)
printdate "$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<commit_msg>Print current market price just before offer is created<commit_after>#! /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=<PASSWORD> --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`

export APP_BASE_NAME=$(basename "$0")
export APP_HOME=$(pwd -P)
export APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts"

source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh"
source "${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)
printdate "$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}."
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}"
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
{'fraction_non_alphanumeric': 0.13140263669764427, 'fraction_numerical': 0.013183488221309703, 'mean_word_length': 5.274576271186441, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2537256', 'n_tokens_mistral': 3355, 'n_tokens_neox': 3224, 'n_words': 917}