Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add api trade simulation scripts #5093

Merged
merged 41 commits into from
Jan 21, 2021

Conversation

ghubstan
Copy link
Contributor

Two regtest trading simulation scripts are contained in this change:

  • trade-simulation.sh goes through the steps of creating country based F2F payment accounts for Bob & Alice, plus each step of a trade from createoffer to completion.

  • limit-order-simulation.sh shows a way to trigger creation of an offer when a limit price is reached.

Each script prints CLI commands and output as they are run, providing a basic tutorial for some of the api's features.

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

Both scripts depend on functions contained in supporting bash and python3 scripts.

#5084 should be merged before this one.

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
@ghubstan ghubstan changed the title [WIP] Add api trade simulation scripts Add api trade simulation scripts Jan 19, 2021
@ghubstan ghubstan marked this pull request as ready for review January 19, 2021 18:02
Added a -w option to  allow user to control the frequency of price requests.
The minimum value = 20s, default value = 120s.
Copy link
Member

@sqrrm sqrrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor changes.

I ran the scripts and I find the resulting orders strange, the price doesn't seem to correlate to the price feed, would like to understand what's happening there.

apitest/scripts/trade-simulation.sh Outdated Show resolved Hide resolved
apitest/scripts/trade-simulation.sh Outdated Show resolved Hide resolved
core/src/main/resources/help/canceloffer-help.txt Outdated Show resolved Hide resolved
core/src/main/resources/help/getmyoffer-help.txt Outdated Show resolved Hide resolved
core/src/main/resources/help/getoffer-help.txt Outdated Show resolved Hide resolved
core/src/main/resources/help/keepfunds-help.txt Outdated Show resolved Hide resolved
core/src/main/resources/help/sendbsq-help.txt Outdated Show resolved Hide resolved
core/src/main/resources/help/sendbtc-help.txt Outdated Show resolved Hide resolved
apitest/scripts/limit-order-simulation.sh Outdated Show resolved Hide resolved
apitest/scripts/trade-simulation-env.sh Show resolved Hide resolved
apitest/scripts/trade-simulation-utils.sh Outdated Show resolved Hide resolved
apitest/scripts/trade-simulation-utils.sh Outdated Show resolved Hide resolved
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}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you tell me why I need to make this change? It is working.
What is wrong with CMD_OUTPUT=$(createpaymentacct "${CMD}")?

Copy link
Contributor

@dmos62 dmos62 Jan 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the same variable referece quoting issue I refer to in other comments. It prevents reinterpretation of some special characters, prevents word splitting. See examples here: https://tldp.org/LDP/abs/html/quotingvar.html

apitest/scripts/trade-simulation.sh Outdated Show resolved Hide resolved
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.)
sqrrm
sqrrm previously approved these changes Jan 20, 2021
Copy link
Member

@sqrrm sqrrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

sqrrm
sqrrm previously approved these changes Jan 20, 2021
Copy link
Member

@sqrrm sqrrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@ghubstan
Copy link
Contributor Author

Force travis build (jar download problem).

@ghubstan ghubstan closed this Jan 20, 2021
@ghubstan ghubstan reopened this Jan 20, 2021
The CLI was receiving stale, cached market prices from the feed service.
@ghubstan ghubstan changed the title Add api trade simulation scripts [WIP] Add api trade simulation scripts Jan 20, 2021
@ghubstan ghubstan marked this pull request as draft January 20, 2021 21:40
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.
@ghubstan
Copy link
Contributor Author

Note on commit b2d8faf: This fixes a bug in the core api that was throwing the PriceRequestException exception below to the CLI when switching currencies, despite a price being available.

PriceFeedService: Exception at applyPriceToConsumer for currency CNY. priceProvider=https://price.bisq.wiz.biz/. Exception=java.lang.IllegalStateException: Stream is already completed, no further calls are allowed 
Jan-20 20:27:01.254 [BisqDaemonMain] WARN  b.c.a.CorePriceService: Exception at applyPriceToConsumer for currency CNY. priceProvider=https://price.bisq.wiz.biz/. Exception=java.lang.IllegalStateException: Stream is already completed, no further calls are allowed bisq.core.provider.price.PriceRequestException: Exception at applyPriceToConsumer for currency CNY. priceProvider=https://price.bisq.wiz.biz/. Exception=java.lang.IllegalStateException: Stream is already completed, no further calls are allowed
	at bisq.core.provider.price.PriceFeedService.applyPriceToConsumer(PriceFeedService.java:387)
	at bisq.core.provider.price.PriceFeedService.lambda$request$0(PriceFeedService.java:174)
	at bisq.core.provider.price.PriceFeedService$1.lambda$onSuccess$0(PriceFeedService.java:417)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

@ghubstan ghubstan changed the title [WIP] Add api trade simulation scripts Add api trade simulation scripts Jan 20, 2021
@ghubstan ghubstan marked this pull request as ready for review January 20, 2021 22:37
Copy link
Member

@sqrrm sqrrm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@ripcurlx ripcurlx merged commit 570d6a8 into bisq-network:master Jan 21, 2021
@ghubstan ghubstan deleted the 02-trading-scripts branch January 21, 2021 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants