使用 coinbase API 购买 ETH

Buying ETH using coinbase API

根据文档,我应该可以使用 coinbase API 购买 ETH(参见 Place buy order)。

现在,看来我得到的是 BTC。

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();
        }
    }
}

我得到了确认:

{
  "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
  }
}

在网站上,我看到我现在有一些 BTC(价值约 1 美元),但没有 ETH。

是否有我需要使用的缺失/未记录的参数?或者我的请求有误?

所以,看起来 Coinbase API 实际上并没有考虑 currency 字段(即使他们的 API 文档提到了这一点并解释了它的作用)。

发生的情况是,您的交易将使用与作为 Oauth 流程一部分的用户授权的帐户相关联的任何货币进行。默认情况下它 select BTC;用户必须单击该下拉菜单并选择其他内容。

所以 "fix" 是为了确保用户 select 正确的帐户。

真正的解决方法是 Coinbase 修复了 API 和 return 如果您 select 的货币未被授权的错误(而不是忽略该字段并使用授权的货币不告诉任何人)。