【问题标题】:Coinbase Exchange API {"message":"Missing product_id"} ERROR even when including product-IDCoinbase Exchange API {"message":"Missing product_id"} 错误,即使包含产品 ID
【发布时间】:2015-05-10 03:15:06
【问题描述】:

我在使用 coinbase 交换 API 时遇到问题。我正在尝试使用一个 cURL PHP 帖子向交易所发布多个卖/买订单。每当我使用下面的代码发布时,我都会收到一个 {"message":"Missing product_id"} 错误,这让我很困惑,因为我显然有产品 ID。我仔细检查了数组输出,JSON 看起来正确。希望大佬能帮忙。是不是很简单?

PHP:(上面我复制粘贴时定义了$btcper和$array变量)

$array2 = array();

for ($i = 0; $i<=$numt; $i+=1) {
$arr = array('size' => $btcper, 'price' => $array[$i], 'side' => 'sell',
'product_id' => 'BTC-USD');
array_push($array2, $arr);

};
echo json_encode($array2)."<br/>";

$output = json_encode($array2);



$key = $tkey;
$secret = $skey;
$passphrase = $passphrase1;

$time = time();
$url = "https://api.gdax.com/orders";

$data = $time."POST"."/orders";


$hashinput = "$data"."$output";

$sign = base64_encode(hash_hmac("sha256", $hashinput, base64_decode($secret), true)); 


$headers = array( 
'CB-ACCESS-KEY: '.$key,
'CB-ACCESS-SIGN: '.$sign,
'CB-ACCESS-TIMESTAMP: '.$time,
'CB-ACCESS-PASSPHRASE: '.$passphrase,
'Content-Type: application/json'
);




static $ch = null;
if (is_null($ch)) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'local server');
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $output);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

$res = curl_exec($ch)."\n"."\n";
echo $res;

$myFile = "idfilesell".date('Y-m-d').".txt";
$fh = fopen($myFile, 'a') or die("can't open file");
fwrite($fh, $res);
fclose($fh);

sleep(1);


}exit;

【问题讨论】:

    标签: php arrays api curl coinbase-api


    【解决方案1】:

    根据this,很遗憾,API 不支持以这种方式发送多个订单。订单规范可以在here找到。

    【讨论】:

      猜你喜欢
      • 2021-07-01
      • 2022-10-07
      • 1970-01-01
      • 1970-01-01
      • 2020-06-12
      • 2017-05-19
      • 2020-03-05
      • 2022-01-04
      • 2015-04-01
      相关资源
      最近更新 更多