[英]Bash curl sign hmac
我正在嘗試使用Bittrex API。 提供的唯一示例如下。 我什至不知道這是什么語言。 我正在嘗試用bash復制它。 完整的API詳細信息位於https://bittrex.com/Home/Api
$apikey='xxx';
$apisecret='xxx';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);
我嘗試了幾件事,但這是我嘗試過的最新嘗試。
#Bash
apikey="mykey"
secret="mysecret"
nonce=`date +%s`
uri="https://bittrex.com/api/v1.1/market/getopenorders?apikey=$apikey&nonce=$nonce"
apisig=`echo -n "$uri" | openssl dgst -sha512 -hmac "$secret"`
curl -sG https://bittrex.com/api/v1.1/market/getopenorders?nonce="$nonce"&apikey="$apikey"&apisig="$apisig"
我收到“ {“成功”:false,“消息”:“ APIKEY_NOT_PROVIDED”,“結果”:空}“
您缺少的是:
&
查詢字符串 因此,對我有用的代碼是:
#!/bin/bash
apikey="mykey"
secret="mysecret"
nonce=`date +%s`
uri="https://bittrex.com/api/v1.1/market/getopenorders?apikey=$apikey&nonce=$nonce"
apisig=`printf %s "$uri" | openssl dgst -sha512 -hmac "$secret"| sed 's/^.*= //'`
curl -sG $uri --header "apisign: $apisig"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.