我无法弄清楚Kraken API输入的位置。我使用https://api.kraken.com/0/private/AddOrder作为起点。输入包括:pair = XBTUSD,type = buy,ordertype = limit等。我是一个API菜鸟,我意识到这不是一个典型的方法,但我非常感谢任何指导。
我已成功将API用于检索帐户余额等其他内容。只是不确定输入的位置。我无法从这里的文档https://www.kraken.com/help/api中找到它。我想使用特定的购买订单作为学习示例。即购买0.003 BTC,对XBTUSD,限制5000美元......
相关的代码 -
function buyKraken () {
var path = "/0/private/AddOrder";
var nonce = new Date () * 1000;
var postdata = "nonce=" + nonce;
var signature = getKrakenSignature (path, postdata, nonce);
var url = 'https://api.kraken.com' + path;
var options = {
method: 'post',
headers: {
'API-Key': "###########",
'API-Sign': signature
},
payload: postdata
};
var response = UrlFetchApp.fetch (url, options);
Logger.log(response);
;
}
答案 0 :(得分:0)
请参阅Github的kraken api项目并转到示例部分。
你需要的部分是这个,它是所有代码的一部分,请不要复制和粘贴
function QueryPrivate($method, array $request = array())
{
if(!isset($request['nonce'])) {
// generate a 64 bit nonce using a timestamp at microsecond resolution
// string functions are used to avoid problems on 32 bit systems
$nonce = explode(' ', microtime());
$request['nonce'] = $nonce[1] . str_pad(substr($nonce[0], 2, 6), 6, '0');
}
// build the POST data string
$postdata = http_build_query($request, '', '&');
// set API key and sign the message
$path = '/' . $this->version . '/private/' . $method;
$sign = hash_hmac('sha512', $path . hash('sha256', $request['nonce'] . $postdata, true), base64_decode($this->secret), true);
$headers = array(
'API-Key: ' . $this->key, // "your key",
'API-Sign: ' . base64_encode($sign)//your signature
);
// make request
curl_setopt($this->curl, CURLOPT_URL, $this->url . $path);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($this->curl, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($this->curl);
if($result===false)
throw new KrakenAPIException('CURL error: ' . curl_error($this->curl));
// decode results
$result = json_decode($result, true);
if(!is_array($result))
throw new KrakenAPIException('JSON decode error');
return $result;
}
// Add a standard order: buy €300 worth of BTC at market at 2013-08-12T09:27:22+0000
$res = QueryPrivate('AddOrder', array(
'pair' => 'XBTCZEUR',
'type' => 'buy',
'ordertype' => 'market',
'oflags' => 'viqc',
'volume' => '300',
'starttm' => '1376299642'
));
print_r($res);
答案 1 :(得分:0)
对于可能会来寻找答案的新人,我使用了一个小的功能:
function getKrakenSignature (path, postdata, krakenSecretKey, nonce) {
var sha256obj = new jsSHA ("SHA-256", "BYTES");
sha256obj.update (nonce + postdata);
var hash_digest = sha256obj.getHash ("BYTES");
var sha512obj = new jsSHA ("SHA-512", "BYTES");
sha512obj.setHMACKey (krakenSecretKey, "B64");
sha512obj.update (path);
sha512obj.update (hash_digest);
return sha512obj.getHMAC ("B64");
}
我使用了此存储库中的jsSHA函数:https://github.com/Caligatio/jsSHA 您只需要在Google脚本中创建一个新文件,然后复制/粘贴此文件的原始文件即可: https://raw.githubusercontent.com/Caligatio/jsSHA/master/src/sha.js