簡體   English   中英

重擊卷曲跡象hmac

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM