Bittrex api の最新バージョンを自分用に行っている小さなツールに実装しようとしています。V1.1 について問い合わせがあったことを除いて、ほとんど問題ありません。
For this version, we use a standard HMAC-SHA512 signing. Append apikey and nonce to your request and calculate the HMAC hash and include it under an apisign header. Note: the nonce is not respected right now but will be enforced later.
$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);
それを実装するために、私はこれをしました:
// TODO : add a way to get this from the user
var apiKey = ApiKey;
var apiSecret = ApiSecret;
// var nonce = (int) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; // same as time() in PHP
var encoding = Encoding.UTF8;
var url = @"https://bittrex.com/api/v1.1/account/getbalances?apikey=" + apiKey;
var result = Gethmacsha512(encoding, apiSecret, url);
// some var for the request
var account = new List<AccountCurrencies>();
// sending it to get the response
var request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("apisign:",result);
request.ContentType = "application/json";
var response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
Resp.GetValue(stream, account);
return account;
これは、HTTPHEADER が良くないことを返します。
ご覧のとおり、この Web サイトで見つけたソリューション (Gethmacsha512、php から .Net への時間を取得する方法、その他のヒントとコツ) を使用しましたが、apisign を送信する方法を取得できません。以上....
誰かが私に解決策を教えてくれたり、私が探しているものを教えてくれたり (curl が何かわからないので)、その部分を理解するために勉強できるコード例を少し教えてくれたりしたら、それは素晴らしいでしょう。
編集 :
上記を次のように更新しました。
// TODO : add a way to get this from the user
var apiKey = ApiKey;
var apiSecret = ApiSecret;
var nonce = (int) (DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds; // same as time() in PHP
var encoding = Encoding.UTF8;
var url = @"https://bittrex.com/api/v1.1/account/getbalances?apikey=" + apiKey;
var urlForAuth = url + "&nonce=" + nonce;
var result = Gethmacsha512(encoding, apiSecret, urlForAuth);
// some var for the request
var account = new List<AccountCurrencies>();
// sending it to get the response
var request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("apisign",result);
request.Headers.Add("nonce", nonce.ToString());
request.ContentType = "application/json";
var response = (HttpWebResponse)request.GetResponse();
var stream = response.GetResponseStream();
Resp.GetValue(stream, account);
return account;
上記の問題の原因は「apisign:」でした。「:」は不正な文字であり、「ノンス」を統合しようとしたのは、すべてがコンパイルされている間、「ノンス」が送信されていないために認証が失敗したためです。そのため、URL またはヘッダーに追加しようとしましたが、どちらも失敗します。