-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
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
Added a -w option to allow user to control the frequency of price requests. The minimum value = 20s, default value = 120s.
There was a problem hiding this 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.
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}") |
There was a problem hiding this comment.
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"
.
There was a problem hiding this comment.
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}")
?
There was a problem hiding this comment.
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
For suggested change bisq-network#5093 (comment)
For suggested change bisq-network#5093 (comment)
For suggested change bisq-network#5093 (comment)
For suggested change bisq-network#5093 (comment)
For requested change bisq-network#5093 (comment)
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.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
Force travis build (jar download problem). |
The CLI was receiving stale, cached market prices from the feed service.
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.
Note on commit b2d8faf: This fixes a bug in the core api that was throwing the
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK
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 fromcreateoffer
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
andpython3
scripts.#5084 should be merged before this one.