简体   繁体   中英

Buying ETH using coinbase API

According to documentation, I should be able to buy ETH using coinbase API (see Place buy order ).

Now, looks like I am getting BTC instead.

private static void placeNonCommitBuy(String paymentMethod) {
    if (sAccountID != null) {
        String url = String.format("https://api.coinbase.com/v2/accounts/%s/buys", sAccountID);

        try {
            JSONObject params = new JSONObject();
            params.put("amount", "0.001");
            params.put("currency", "ETH");
            params.put("payment_method", paymentMethod);
            params.put("agree_btc_amount_varies", true);
            params.put("commit", false);
            params.put("quote", true);

            doPost(url, params, sJustPrint);
        } catch (JSONException ex) {
            Assert.fail();
        }
    }
}

I got that confirmation :

{
  "data": {
    "id": <...snip...>,
    "status": "created",
    "payment_method": {
      "id": <...snip...>,
      "resource": "payment_method",
      "resource_path": <...snip...>
    },
    "transaction": null,
    "user_reference": <...snip...>,
    "created_at": "2018-01-18T01:37:15Z",
    "updated_at": "2018-01-18T01:37:16Z",
    "resource": "buy",
    "resource_path": <...snip...>,
    "fee": {
      "amount": "0.99",
      "currency": "USD"
    },
    "amount": {
      "amount": "0.00008968",
      "currency": "BTC"
    },
    "total": {
      "amount": "2.02",
      "currency": "USD"
    },
    "subtotal": {
      "amount": "1.03",
      "currency": "USD"
    },
    "committed": true,
    "payout_at": "2018-01-18T01:37:14Z",
    "instant": true,
    "requires_completion_step": false
  }
}

In the website, I see that I now have some BTC (about 1 USD worth of it), but not ETH.

Is there a missing / undocumented params I need to use? Or a mistake in my request?

So, looks like the Coinbase API isn't actually taking the currency field into consideration (even if their API documentation mention that and explain what it does).

What happen is that your transaction will take place using whatever currency is associated with the account that was authorized by the user as part of the Oauth process. By default it select BTC; the user has to click that dropdown and pick something else.

So the "fix" is to make sure the user select the proper account.

The real fix is that Coinbase fix their API and return an error if the currency you select isn't authorized (instead of ignoring that field and using the authorized currency without telling anyone).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM