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

Implement simplest possible trading script #4257

Closed
15 tasks done
ghubstan opened this issue May 14, 2020 · 14 comments
Closed
15 tasks done

Implement simplest possible trading script #4257

ghubstan opened this issue May 14, 2020 · 14 comments

Comments

@ghubstan
Copy link
Member

ghubstan commented May 14, 2020

After implementing rpc wallet protection methods (ISSUE 4214 + PR 4214), we need a minimum set of endpoints to enable trading from the gRPC API, and a bats script for test / demo purposes.

The goal of the set of PRs that will accompany this issue is to allow a user to perform all of the following functions with the gRPC API (the UI should not be needed for any setup).

  • Get Funding Addresses

    Method Signature: getfundingaddresses

    Show existing unused BTC addresses in the wallet.
    If there are no unused addresses in the wallet, the server will create one.

    Analog to bitcoin-cli method getnewaddress

  • Get Address Balance

    Method Signature: getaddressbalance address

    Show BTC balance for given address in the wallet, with number of confirmations of the most recent transaction included. (TODO Show list of txIds included as well?)

    Analog to bitcoin-cli method listreceivedbyaddress

  • Fund a BTC wallet

    No new method is needed to fund a wallet. User sends BTC from an external wallet to a Bisq "Fund your wallet" address, then awaits confirmations.

    Use Case:
    * User finds an unused funding address by calling getfundingaddresses.
    * User sends BTC via bitcoin-cli sendtoaddress "addr" amt.
    * User polls status of the funding TX by calling getaddressbalance address and/or getbalance.

  • Create a Payment Account

    Method Signature: createpaymentacct acct-name paymentmethod acct-number currency

    (The different payment methods will have different attributes, the above signature is specific to PerfectMoney)

    In the interest in keeping it simple at this stage, the 1st impl can only create a "PerfectMoney dummy" account, mimicking the default payment method created by the UI when running Bisq in regtest / dev mode with the DAO setup used to test every new release.

  • Get Payment Accounts

    Method Signature: getpaymentaccts

    Show list of all payment methods created by the user in the UI or createpaymentacct. The returned id is a required parameter of the createoffer method.

  • Get Existing Offers

    Method Signature: getoffers buy | sell, currency

    Output would display same info as UI's Offer Book, plus a unique identifier to be used in
    a takeoffer method.

  • Create Offer

    Method Signature: createoffer buy|sell [TBD]

    BUY Offer Parameters: payment-method amt currency pct-from-mkt-price min-amt [pct-sec-deposit]

    SELL Offer Parameters: payment-method amt currency pct-from-mkt-price min-amt [pct-sec-deposit]

    Note: there may be differences in the non-unique BUY/SELL offer params shown above (todo).

  • Take Offer

    Method Signature: takeoffer offer-id

    Taker must have a matching payment-method associated with selected offer.

    Funding source defaults to Bisq wallet.
    Fee currency defaults to BTC.
    (Support for displaying BSQ balance and paying trade fee with BSQ not in scope.)

  • Get Offer Status

    Method Signature: getofferstatus offer-id

    Displays status of offer, including trade protocol steps that have and have not been completed.

    Offer creators & takers will see different offer status information, but both will see the same
    initial state:

    WAITING_FOR_BLOCKCHAIN_CONFIRMATION (of deposit fees)

    Offer States seen by Takers:

    START_PAYMENT
    WAITING_FOR_PAYMENT_ARRIVAL

    Offer States seen by Creators:

    WAITING_FOR_PAYMENT
    PAYMENT_RECEIVED

    Note: there may be some states unique to SELL offer creators/takers and BUY offer creators/takers.

    Creators and takers will also see the same final status:

    COMPLETED (can move funds)

  • Start Payment

    Method Signature: paymentstarted offer-id

    Called by BTC buyers after submitting a payment.

  • Payment Received

    Method Signature: paymentreceived offer-id

    Called by BTC sellers after receiving a payment.

  • Cancel Offer

    Method Signature: canceloffer offer-id

    Allow user to cancel an existing offer that has not passed the START_PAYMENT stage of the trade protocol.

  • Move BTC from completed trades to Bisq BTC wallet

    Method Signature: movefunds

    Move BTC funds and trade fees to Bisq wallet after a successful trade completion.

  • Withdraw BTC to an external wallet

    Method Signature: withdrawfunds "addr"

    Withdraw BTC from Bisq wallet to external BTC address

  • BATS test script(s) to test and demo end-to-end functionality

@ghubstan
Copy link
Member Author

@cbeams, These method names are not well thought out, and I'll work on improving them.

I will also stub out some of the new endpoints in branch rpc-wallet-protection+scratch, or a new branch based on master, if you merge PR 4214 before you go no break.

Have a good long break.

@cbeams
Copy link
Member

cbeams commented May 18, 2020

Thanks, @ghubstan. Please see my comments about this in the video I just posted at keybase://chat/bisq#grpc-api/657

@cbeams cbeams added this to In progress in Ship Bisq Daemon and API May 18, 2020
@ghubstan
Copy link
Member Author

ghubstan commented May 18, 2020

Please see my comments about this in the video I just posted at keybase://chat/bisq#grpc-api/657

@cbeams , You may have already turned into a pumpkin, but here's my feedback regarding the video.

I'm OK with switching from a gRPC to REST API if that's what will be needed to get Bisq into mynode, and I know how to work with SpringWeb & REST. I also agree with what you said about a switch to REST != wasted efforts. Thanks for the head's up.

I'll study the :daemon readiness problem, and work on the this issue while you're away -- keeping in mind what you talked about in the recording.

ghubstan added a commit to ghubstan/bisq that referenced this issue Jun 13, 2020
This addresses task #1 in issue bisq-network#4257.

This new gRPC WalletService method displays the BTC wallet's list of
receiving addresses.  The balance and number of confirmations
for the most recent transaction is displayed to the right of each
address.  Instead of returning a gRPC data structure to the client,
the service method returns a formatted String.

If the BTC wallet has no unused addresses, one will be created and
included in the returned list, and it can be used to fund the wallet.

The new method required injection of the BtcWalletService into CoreWalletsService,
and the usual boilerplate changes to grpc.proto, CliMain, and GrpcWalletService.

Some of the next PRs (for bisq-network#4257) will require some common functionality within
CoreWalletsService, so these additional changes were included:

  * a private, class level formatSatoshis function
  * a public getNumConfirmationsForMostRecentTransaction method
  * a public getAddressBalance method
  * a private getAddressEntry method

A unit test that verifies a successful return status was added to cli/test.sh.
ghubstan added a commit to ghubstan/bisq that referenced this issue Jun 14, 2020
This addresses task 2 in issue 4257
	bisq-network#4257

This new gRPC Wallet service method displays the balance and number
of confimirmations of the most recent transaction for the given BTC
wallet address.

The new method required the usual boilerplate changes to grpc.proto,
CliMain, and GrpcWalletService.

Two unit tests to check error msgs was added to cli/test.sh.
ghubstan added a commit to ghubstan/bisq that referenced this issue Jun 15, 2020
This addresses task 4 in issue 4257.
    bisq-network#4257

This PR should be reviewed/merged after PR 4304.
    bisq-network#4304

This new gRPC Wallet service method creates a dummy PerfectMoney
payment account for the given name, number and fiat currency code,
as part of the required "simplest possible trading API" (for demo).
An implementation supporting all payment methods is not in the
scope.

Changes specific to the new rpc method implementation follow:

* New createpaymentacct method + help text was added to CliMain.
  Help text formatting was also changed to make room for larger
  method names and argument lists.

* The PaymentAccount proto service def was renamed PaymentAccounts
  to avoid a name collision, and the new rpc CreatePaymentAccount
  was made part of the newly named PaymentAccounts service def.

* New GrpcPaymentAccountsService (gRPC boilerplate) and
  CorePaymentAccountsService (method implementations) classes were
  added.

* The gRPC GetPaymentAccountsService stub was moved from GrpcServer
  to the new GrpcPaymentAccountsService class, and
  GrpcPaymentAccountsService is injected into GrpcServer.

* A new createpaymentacct unit test was added to the bats test
  suite (checks for successful return status code).

Maybe bit out of scope, some small changes were made towards making
sure the entire API is defined in CoreApi, which is used as a
pass-through object to the new CorePaymentAccountsService.  In the
next PR, similar refactoring will be done to make CoreApi the
pass-through object for all of the existing CoreWalletsService
methods.  (CoreWalletsService will be injected into CoreApi.)
In the future, all Grpc*Service implementations will call core
services through CoreApi, for the sake of consistency.
ghubstan added a commit to ghubstan/bisq that referenced this issue Jun 15, 2020
This addresses task 4 in issue 4257.
    bisq-network#4257

This PR should be reviewed/merged after PR 4304.
    bisq-network#4304

This new gRPC PaymentAccounts service method creates a dummy
PerfectMoney payment account for the given name, number and fiat
currency code, as part of the required "simplest possible trading
API" (for demo).   An implementation supporting all payment
methods is not in the scope.

Changes specific to the new rpc method implementation follow:

* New createpaymentacct method + help text was added to CliMain.
  Help text formatting was also changed to make room for larger
  method names and argument lists.

* The PaymentAccount proto service def was renamed PaymentAccounts
  to avoid a name collision, and the new rpc CreatePaymentAccount
  was made part of the newly named PaymentAccounts service def.

* New GrpcPaymentAccountsService (gRPC boilerplate) and
  CorePaymentAccountsService (method implementations) classes were
  added.

* The gRPC GetPaymentAccountsService stub was moved from GrpcServer
  to the new GrpcPaymentAccountsService class, and
  GrpcPaymentAccountsService is injected into GrpcServer.

* A new createpaymentacct unit test was added to the bats test
  suite (checks for successful return status code).

Maybe bit out of scope, some small changes were made towards making
sure the entire API is defined in CoreApi, which is used as a
pass-through object to the new CorePaymentAccountsService.  In the
next PR, similar refactoring will be done to make CoreApi the
pass-through object for all of the existing CoreWalletsService
methods.  (CoreWalletsService will be injected into CoreApi.)
In the future, all Grpc*Service implementations will call core
services through CoreApi, for the sake of consistency.
ghubstan added a commit to ghubstan/bisq that referenced this issue Jun 15, 2020
This addresses task 4 in issue 4257.
    bisq-network#4257

This PR should be reviewed/merged after PR 4304.
    bisq-network#4304

This new gRPC PaymentAccounts service method creates a dummy
PerfectMoney payment account for the given name, number and fiat
currency code, as part of the required "simplest possible trading
API" (for demo).   An implementation supporting all payment
methods is not in the scope.

Changes specific to the new rpc method implementation follow:

* New createpaymentacct method + help text was added to CliMain.
  Help text formatting was also changed to make room for larger
  method names and argument lists.

* The PaymentAccount proto service def was renamed PaymentAccounts
  to avoid a name collision, and the new rpc CreatePaymentAccount
  was made part of the newly named PaymentAccounts service def.

* New GrpcPaymentAccountsService (gRPC boilerplate) and
  CorePaymentAccountsService (method implementations) classes were
  added.

* The gRPC GetPaymentAccountsService stub was moved from GrpcServer
  to the new GrpcPaymentAccountsService class, and
  GrpcPaymentAccountsService is injected into GrpcServer.

* A new createpaymentacct unit test was added to the bats test
  suite (checks for successful return status code).

Maybe bit out of scope, some small changes were made towards making
sure the entire API is defined in CoreApi, which is used as a
pass-through object to the new CorePaymentAccountsService.  In the
next PR, similar refactoring will be done to make CoreApi the
pass-through object for all of the existing CoreWalletsService
methods.  (CoreWalletsService will be injected into CoreApi.)
In the future, all Grpc*Service implementations will call core
services through CoreApi, for the sake of consistency.
@dmos62
Copy link
Contributor

dmos62 commented Jun 16, 2020

Can we consider not using Bitcoin Core's convention for API naming withoutanyspacesorcapitalization? It's a pain to read and to write too, because it's hard to spot a typo. I suggest using_snake_case_which_means_putting_underscores_where_spaces_would_be.

Before someone suggests CamelCase, while it would be just like writing Java, I would be against it, because its space economy leads to some awkward reading as well: LikeWhenThereIsAShortWordInTheName.

@cbeams
Copy link
Member

cbeams commented Jun 18, 2020

I'd recommend holding off on such a change until closer to an initial release, and to think really carefully about it. The reason for mimicking Bitcoin Core is not because all lower case is necessarily best, but because it is perhaps most familiar to people in this space, and more likely to "feel right" to someone working with Bitcoin Core a lot. If we were to follow more general *nix command line utility conventions, I'd recommend kebab case, e.g. the way many unix utilities are named, e.g. gpg-agent, ssh-agent, ssh-add and the way multi-word git subcommands are named, e.g. git update-index. This approach gets verbose, though, particularly when we have get/set/remove names like set-wallet-password. In any case (pun intended!), I would not recommend using camel case / mixed case / pascal case, because they smell like Java. The CLI should not telegraph the preferences and conventions of the underlying programming language; it should be designed to fit well and feel right in a *nix environment / Bitcoin protocol stack environment. Likewise, if we went with snake case, it would feel perhaps more Python-esque than *nix-native.

Note that it could also be (not now, later) that we choose to go with a more sophisticated approach to the cli involving subcommands, e.g. bisq-cli order create, bisq-cli wallet unlock, bisq-cli wallet show, similar to the way, again, that the Git CLI is designed, (git remote add <url>, git remote show origin, etc).

So again, my 2 sats are to just hold off for now and let the continuing implementation inform the final design. Make this change once, later, when we're more confident about it, ideally with some real world users having tried things out and given some feedback. HTH.

ghubstan added a commit to ghubstan/bisq that referenced this issue Jun 19, 2020
This addresses task 5 in issue 4257
	bisq-network#4257

This new gRPC PaymentAccounts service method displays the user's
saved payment accounts.

A unit test to check a successful return status code was added
to cli/test.sh.

This PR should be reviewed/merged after PR 4322.
	bisq-network#4322
eigentsmis pushed a commit to eigentsmis/bisq that referenced this issue Jun 26, 2020
This addresses task bisq-network#1 in issue bisq-network#4257.

This new gRPC WalletService method displays the BTC wallet's list of
receiving addresses.  The balance and number of confirmations
for the most recent transaction is displayed to the right of each
address.  Instead of returning a gRPC data structure to the client,
the service method returns a formatted String.

If the BTC wallet has no unused addresses, one will be created and
included in the returned list, and it can be used to fund the wallet.

The new method required injection of the BtcWalletService into CoreWalletsService,
and the usual boilerplate changes to grpc.proto, CliMain, and GrpcWalletService.

Some of the next PRs (for bisq-network#4257) will require some common functionality within
CoreWalletsService, so these additional changes were included:

  * a private, class level formatSatoshis function
  * a public getNumConfirmationsForMostRecentTransaction method
  * a public getAddressBalance method
  * a private getAddressEntry method

A unit test that verifies a successful return status was added to cli/test.sh.
eigentsmis pushed a commit to eigentsmis/bisq that referenced this issue Jun 26, 2020
This addresses task 2 in issue 4257
	bisq-network#4257

This new gRPC Wallet service method displays the balance and number
of confimirmations of the most recent transaction for the given BTC
wallet address.

The new method required the usual boilerplate changes to grpc.proto,
CliMain, and GrpcWalletService.

Two unit tests to check error msgs was added to cli/test.sh.
eigentsmis pushed a commit to eigentsmis/bisq that referenced this issue Jun 26, 2020
This addresses task 4 in issue 4257.
    bisq-network#4257

This PR should be reviewed/merged after PR 4304.
    bisq-network#4304

This new gRPC PaymentAccounts service method creates a dummy
PerfectMoney payment account for the given name, number and fiat
currency code, as part of the required "simplest possible trading
API" (for demo).   An implementation supporting all payment
methods is not in the scope.

Changes specific to the new rpc method implementation follow:

* New createpaymentacct method + help text was added to CliMain.
  Help text formatting was also changed to make room for larger
  method names and argument lists.

* The PaymentAccount proto service def was renamed PaymentAccounts
  to avoid a name collision, and the new rpc CreatePaymentAccount
  was made part of the newly named PaymentAccounts service def.

* New GrpcPaymentAccountsService (gRPC boilerplate) and
  CorePaymentAccountsService (method implementations) classes were
  added.

* The gRPC GetPaymentAccountsService stub was moved from GrpcServer
  to the new GrpcPaymentAccountsService class, and
  GrpcPaymentAccountsService is injected into GrpcServer.

* A new createpaymentacct unit test was added to the bats test
  suite (checks for successful return status code).

Maybe bit out of scope, some small changes were made towards making
sure the entire API is defined in CoreApi, which is used as a
pass-through object to the new CorePaymentAccountsService.  In the
next PR, similar refactoring will be done to make CoreApi the
pass-through object for all of the existing CoreWalletsService
methods.  (CoreWalletsService will be injected into CoreApi.)
In the future, all Grpc*Service implementations will call core
services through CoreApi, for the sake of consistency.
eigentsmis pushed a commit to eigentsmis/bisq that referenced this issue Jun 26, 2020
This addresses task 5 in issue 4257
	bisq-network#4257

This new gRPC PaymentAccounts service method displays the user's
saved payment accounts.

A unit test to check a successful return status code was added
to cli/test.sh.

This PR should be reviewed/merged after PR 4322.
	bisq-network#4322
@ghubstan
Copy link
Member Author

ghubstan commented Jul 1, 2020

Suggestions on improving the format of cli output were made in issue 4348.

@ghubstan ghubstan changed the title [WIP] Implement simplest possible trading script Implement simplest possible trading script Dec 27, 2020
@ghubstan
Copy link
Member Author

All functionality required for a simplest possible trading script was merged in PRs before and including #4966. Work on scripts is in progress.

@ghubstan ghubstan changed the title Implement simplest possible trading script [WIP] Implement simplest possible trading script Dec 27, 2020
ghubstan added a commit to ghubstan/bisq that referenced this issue Dec 31, 2020
This is a work in progress, but when done, will resovle issue
bisq-network#4257.
@ghubstan
Copy link
Member Author

Issue will be closed when #5093 is merged.

@ghubstan ghubstan changed the title [WIP] Implement simplest possible trading script Implement simplest possible trading script Jan 20, 2021
Ship Bisq Daemon and API automation moved this from In progress to Done Jan 21, 2021
@Kixunil
Copy link

Kixunil commented Jan 21, 2021

Hey, great to see this merged. Quick question: would it be possible to write an alternative UI using this API? I'm mainly interested in having UI running on desktop detached from backend running on server, not changing the contents of the UI.

@ghubstan
Copy link
Member Author

Hey, great to see this merged. Quick question: would it be possible to write an alternative UI using this API? I'm mainly interested in having UI running on desktop detached from backend running on server, not changing the contents of the UI.

I can't say absolutely not, but it would be weird. The api does not yet support all features of the Bisq desktop, and the api's server only works with the gRPC CLI. (You can build scripts that run the CLI, see the regtest trading simulation scripts in apitest.)

If there is good adoption of the api after a louder release -- and it is stable, works and scales -- there is a good chance the back-end will be modified to serve RESTful HTTP 1.1 clients. When and if that happens would be the time start building alternative UIs.

@Kixunil
Copy link

Kixunil commented Jan 21, 2021

Thanks for the answer! This is not urgent and I'm not concerned with gRPC vs REST - anything would work for me. Having all required APIs and a headless server is more important.

@ghubstan
Copy link
Member Author

there is a good chance the back-end will be modified to serve RESTful HTTP 1.1 clients.

I meant to say REST clients "too". But there will have to be consensus among devs about how. It will be awhile...

@Kixunil
Copy link

Kixunil commented Jan 22, 2021

AFAIK REST can be auto-generated from gRPC spec (I believe LND does this), not sure about the details, so that way shouldn't be too difficult. Anyway, no rush, a few months is completely fine for me.

If my priorities change there's a good chance I will contribute to it myself, will let you know if it happens.

@ghubstan
Copy link
Member Author

AFAIK REST can be auto-generated from gRPC spec

Here is an experiment I did with a reverse proxy https://github.com/ghubstan/bisq-grpc-gateway.
But this is more than a few months away, even if the team agrees to do it this way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

4 participants