【发布时间】:2020-02-11 20:03:48
【问题描述】:
我正在通过一个 Laravel 项目运行这个东西。我已经把头发扯了一段时间了。到目前为止,我所掌握的内容来自 Coinbase Pro API 文档。
$request_path = "/orders";
$body = array('size' => $size, 'price' => $eth_price, 'side' => 'sell', 'product_id' => 'ETH-GBP' );
$body = is_array($body) ? json_encode($body) : $body;
$secret = my secret;
$ch = curl_init("https://api.pro.coinbase.com/time");
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch,CURLOPT_USERAGENT,'CoinbaseProAPI');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch));
curl_close($ch);
$timestamp = $result->epoch;
$timestamp_rounded = intval(ceil($timestamp));
$what = $timestamp_rounded.'POST'.$request_path.$body;
$sig = base64_encode(hash_hmac("sha256", $what, base64_decode($secret), true));
$ch = curl_init("https://api.pro.coinbase.com".$request_path) ;
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true) ;
curl_setopt($ch,CURLOPT_USERAGENT,'CoinbaseProAPI');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'CB-ACCESS-KEY: public_key',
'CB-ACCESS-SIGN: '.$sig,
'CB-ACCESS-PASSPHRASE: passphrase',
'CB-ACCESS-TIMESTAMP: '.$timestamp));
$coinbasepro_response = curl_exec($ch) ;
curl_close($ch) ;
dd($coinbasepro_response);
我收到的响应是无效签名。我很难过,非常感谢任何帮助。
【问题讨论】:
-
您收到的回复表明 Coinbase 拒绝了您的 API 调用。因此,您确实需要向 Coinbase 查询您的通话中哪一部分不正确...
标签: php laravel coinbase-api