1

我一直在努力让私有 GDAX API 工作。当我执行以下脚本时,我期望一些 JSON 像:

{
    "trade_id": 74,
    "product_id": "BTC-USD",
    "price": "10.00",
    "size": "0.01",
    "order_id": "d50ec984-77a8-460a-b958-66f114b0de9b",
    "created_at": "2014-11-07T22:19:28.578544Z",
    "liquidity": "T",
    "fee": "0.00025",
    "settled": true,
    "side": "buy"
}

这是我(沙盒)帐户上的订单填写列表。但我得到的只是:

{
     "message":"invalid signature"
}

这意味着我的签名格式不正确。我从 GDAX 手册中窃取了有关创建签名的功能,因此有可能这是 PHP 脚本。<?php 回声 '

';

$adjust = 0; $time = time() + $adjust; error_reporting(E_ALL); ini_set('display_errors', 1); $api_base = 'https://api-public.sandbox.gdax.com'; $api_url = '/fills'; // sign function signature($request_path='', $body='', $timestamp=false, $method='GET', $secret) { $body = is_array($body) ? json_encode($body) : $body; $what = $timestamp.$method.$request_path.$body; return base64_encode(hash_hmac("sha256", $what, base64_decode($secret), true)); } $api = 'https://api-public.sandbox.gdax.com'; // sandbox $apikey = '9d9313b25c8d7872178c97cd09d0fa20'; $passphrase = '1k2lpf73rfg'; $secret = 'LJoPmgphrKbw8YWb+e7Wg2tn5RBCHRodkm+NI4Lhae0cu8ump3kVyHmLZdKWCvHPmOi0gvi/bO8nXucHj5TJmg=='; $request_path = $api_base . $api_url; $body = ''; $signature = signature($request_path, $body, $time, 'GET', $secret); //echo 'signature: ' . $signature; /* curl */ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_path); // set the api address curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // store the response in a variable curl_setopt($ch, CURLOPT_HEADER, 1); // return the header //curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE); // transfer info curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36', 'CB-ACCESS-KEY: ' . $apikey, 'CB-ACCESS-SIGN: ' . $signature, 'CB-ACCESS-TIMESTAMP: ' . $time, 'CB-ACCESS-PASSPHRASE: ' . $passphrase )); //$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); //print_r($httpcode); $output = curl_exec($ch); if($output === FALSE){ echo 'cURL ERROR: ' . curl_error($ch); }else{ echo 'successful connection:'; } curl_close($ch); echo $output; print_r(json_decode($output)); echo '</pre>'; ?>
4

0 回答 0