2

Within the Coinbase app one can convert digital currencies (see the image below).

coinbase

But does one convert via the Coinbase or Coinbase Pro API?

Bob van Luijt
  • 7,153
  • 12
  • 58
  • 101

1 Answers1

0

Watching API from coinbase webapp i see what endpoint you need to call:

  1. Have to know base_id of crypto that you want to sell and base_id of crypto want to buy. You can know it by call GET "https://api.coinbase.com/v2/ /assets/prices?base=USD&filter=holdable&resolution=latest" and get from response the "base_id" of your currencies.

  2. Make an order by calling POST "https://api.coinbase.com/v2/trade" with a request body in json like this:

    { 'amount': [amount that you want to convert], 'amount_asset': [currency of amount that you want to convert], 'amount_from': 'input', 'source_asset': ["base_id" of crypto that you want to sell], 'target_asset': ["base_id" of crypto that you want to buy] }

  3. If previous POST "/trade" response code is 201, you have to get the "id" value of response's json and do a commit of your order by calling POST "https://api.coinbase.com/v2/trades/[id of json response of previous https://api.coinbase.com/v2/trade POST"]/commit". If the response code of this POST commit is 201, your exchange is started and if there are not error in coinbase, your conversion is done!

paggio86
  • 21
  • 2