【问题标题】:Buying ETH using coinbase API使用 coinbase API 购买 ETH
【发布时间】:2018-06-27 17:07:46
【问题描述】:

根据文档,我应该可以使用 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。

我需要使用缺少/未记录的参数吗?还是我的请求有误?

【问题讨论】:

  • 你试过params.put("amount", "0.001 ETH");吗?
  • @AdamKipnis 好主意,但不起作用:(

标签: ethereum coinbase-api


【解决方案1】:

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

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

所以“修复”是确保用户选择正确的帐户。

真正的解决方法是 Coinbase 修复他们的 API,如果您选择的货币未经授权,则返回错误(而不是忽略该字段并使用授权货币而不告诉任何人)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-03-25
    • 1970-01-01
    • 1970-01-01
    • 2011-12-14
    • 2023-04-01
    • 2013-06-11
    • 1970-01-01
    • 2018-04-22
    相关资源
    最近更新 更多