【问题标题】:Can I do transfer between portfolios with withdraw and deposit APIs? [coinbase-api]我可以使用提款和存款 API 在投资组合之间进行转账吗? [coinbase-api]
【发布时间】:2020-07-27 09:23:14
【问题描述】:

我们不能使用以下 API 在投资组合之间进行转移。

  1. “POST /withdrawals/coinbase-account”(网址:https://api-public.sandbox.pro.coinbase.com/withdrawals/coinbase-account
  2. “POST /deposits/coinbase-account”(网址:https://api-public.sandbox.pro.coinbase.com/deposit/coinbase-account

错误信息如下: ApiError(状态 403 代码=):无效范围 COINBASE args({'data': '{"amount": 0.1, "currency": "BTC", "coinbase_account_id": "4b08d5e5-fe77-4249-b017-301e8890652a"} ', 'headers': {'Content-type': 'application/json', 'CB-ACCESS-KEY': 'XXXXXXXXXXXX', 'CB-ACCESS-SIGN': 'xxxxxxxxxxxxxxxxxxxxxxxxx, 'CB-ACCESS-TIMESTAMP': '1594280190.878908','CB-ACCESS-PASSPHRASE':'xxxxxxxxxxx'},'超时':30.0})

让我们知道这 2 个 API 是否用于投资组合之间的转移。但是,如果 API 没问题,请您在 url 上演示并请求以下 2 个用例的有效负载:

  1. 如果我想从配置文件 A 转移到配置文件 B,使用 A 的 API 密钥(具有转移访问权限)和 A.withdrawals(asset, amount, coinbase_id = B)
  2. 如果我想从配置文件 B 转移到配置文件 A,使用 A 的 API 密钥(具有转移访问权限)和 A.deposits(asset, amount, coinbase_id = B)

特别是,coinbase_id 是代表 profile(potfolio) id 还是 account(asset) id? API如何获取这个id?

【问题讨论】:

  • 这些问题同时包含多个问题,其中一些问题似乎真的需要阅读相关 API 的文档。
  • API 文档似乎没有完全涵盖如何使用withdraw 和 trasnfer API 进行转移。

标签: coinbase-api


【解决方案1】:

这已经是一个很长的话题了,我想你已经找到了答案,但如果没有,对于那些感兴趣的人,你可以使用 /profiles/transfer 路由在你的 Coinbase Pro 投资组合之间转移资金。

只是您必须拥有从“来自”组合创建的具有转移权限的 API 密钥。

例子:

POST /profiles/transfer
{
    "from": "86602c68-306a-4500-ac73-4ce56a91d83c",
    "to": "e87429d3-f0a7-4f28-8dff-8dd93d383de1",
    "currency": "EUR",
    "amount": "100.00"
}

【讨论】:

  • 我创建了一个具有转账权限的 API 密钥,但我无法转账。还有什么我需要知道的吗?
【解决方案2】:

您可以通过先获得 Oauth2 授权来获得帐户 ID。获得后,您可以使用 Coinbase API(非专业版)调用来获取帐户 ID。我不会介绍 Oauth2 调用,因为它们有很好的记录。使用 PHP CURL 的 API 调用如下:

//////////////////////
// IMPORTANT, not covered how to obtain this

// Assuming a variable which contains the Oauth2 access code is passed in 
// with a variable name called 

// $oauth_provided_access_token
// IMPORTANT
//////////////////////

// Obtain Timestamp
$API_VERSION = '2021-02-26';
$timestamp = json_decode(file_get_contents("https://api.coinbase.com/v2/time"), true)["data"]["epoch"];

// Define request
$req = "/v2/user";

// Define full URL, why Coinbase cannot parse this and obtain the request is strange
$url = "https://api.coinbase.com" . $req;

// Obtain API key/Secret (Do not put this in your PHP code, obtain it via environment variables
// Note that the key and secret are not required in this instance
// but many Coinbase API calls will need them

//$key    = $_SERVER["HTTP_MY_COINBASE_API_KEY"];
//$secret = $_SERVER["HTTP_MY_COINBASE_API_SECRET"];

// Set up CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, false );
curl_setopt($ch, CURLOPT_USERAGENT,'CoinbaseAPI');
curl_setopt($ch, CURLOPT_HTTPHEADER 
  , array ( "Authorization: Bearer " . $oauth_provided_access_token
         , "CB-VERSION:" . $API_VERSION
         , "CB-ACCESS-TIMESTAMP:" . $timestamp    
         ) 
  );
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true );

$response = curl_exec($ch); // Actual account info

$info = curl_getinfo($ch); // Get more debugging info

curl_close($ch);

$response_object=json_decode($response);

echo $response_object->{"data")->{"id"}; // User Account ID

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-10
    • 1970-01-01
    • 1970-01-01
    • 2013-10-14
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多