При попытке достучатся до api версии 3 на kuna вы могли получать следующую ошибку:
{"messages":["the_tonce_is_invalid"]}
Ниже представлены рарочие примеры на CURL и Guzzle
Пример с использованием CURL:
$public = '';
$secret = '';
$action = 'auth/me';
$nonce = substr((string)time(), 0, 9) . '0000';
$body = "{}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.kuna.io/v3/$action");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"content-type: application/json",
"kun-apikey: " . $public,
"kun-signature: " . hash_hmac("sha384", utf8_encode("/v3/{$action}{$nonce}{$body}"), utf8_encode($secret)),
"kun-nonce: " . $nonce
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$result = curl_exec($ch);
return json_decode($result, true);
Пример на Guzzle
$public = '';
$secret = '';
$action = 'auth/me';
$nonce = time() * 1000;
$body = [];
$bodyToSignature = json_encode($body);
$signature = hash_hmac("sha384", utf8_encode("/v3/{$action}{$nonce}{$bodyToSignature}"), utf8_encode($secret));
$client = new Client();
$url = "https://api.kuna.io/v3/$action";
$result = $client->request('POST', $url, [
'headers' => [
'content-type' => 'application/json',
'kun-apikey' => $public,
'kun-signature' => $signature,
'kun-nonce' => $nonce
],
'json' => $body
]);
return json_decode($result->getBody()->getContents(), true);