I am having an issue with the coinbase exchange API. I am trying to post multiple sell/buy orders to the exchange using one cURL PHP post. Whenever I use the code below to post I get a {"message":"Missing product_id"} error which confuses me because I clearly have the product-id. I have double check the array output and the JSON looks correct. Hope you guy can help. Is it something simple?
PHP: ($btcper and $array variables are defined above when I coped and pasted)
$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;