質問編集履歴
1
<c#コーディングして試した結果>以下を記述。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,7 +10,77 @@
|
|
10
10
|
https://stackoverflow.com/questions/58121942/bittrex-v3-api-invalid-signature-response#
|
11
11
|
https://stackoverflow-com.translate.goog/questions/66565295/bittrex-api-v3-invalid-api-key?_x_tr_sl=auto&_x_tr_tl=ja&_x_tr_hl=ja
|
12
12
|
|
13
|
+
<c#コーディングして試した結果>
|
14
|
+
/balances呼出し時、/orders呼出し時ともにmessage,StatusCode: 401, ReasonPhrase: 'Unauthorized'のエラーが発生してしまってます。
|
15
|
+
※以下に記載している理由のことから、「Content-Hash」を算出する部分が間違ってると認識しており、「Content-Hash」を算出するためのC#記述方法が知りたいです。
|
16
|
+
|
17
|
+
<Bittrex公式記載のJavascriptのサンプル>
|
18
|
+
var contentHash = CryptoJS.SHA512(JSON.stringify(requestBody)).toString(CryptoJS.enc.Hex);
|
19
|
+
|
20
|
+
/balance時(body部が無い場合の値)※Bittrex公式記載
|
21
|
+
→Content-Hash:cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e
|
22
|
+
|
23
|
+
<c#コーディングは以下のように記述>
|
24
|
+
/balances呼出し時のparamaters:{}
|
25
|
+
→Content-Hash:64d24560970ca14d349bea0e7d2526d4754bf3283568ab4dd602bd79eb454dc3657d5bb6f9a30c90ea98d9600ebd0fb45d582f4cae3f8e3c50b0e8fb18059892
|
26
|
+
※上記値が、公式発表時のContent-Hashの値と異なるため「contentHash」の算出コードC#が間違っていると判断してます。
|
27
|
+
|
28
|
+
/orders呼出し時のparamaters:
|
29
|
+
{
|
13
|
-
|
30
|
+
"marketsymbol": "1ECO-USDT",
|
31
|
+
"direction": "BUY",
|
32
|
+
"type": "LIMIT",
|
33
|
+
"quantity": "100",
|
34
|
+
"limit": "0.03",
|
35
|
+
"timeInforce": "GOOD_TIL_CANCELLED"
|
36
|
+
}
|
37
|
+
→Content-Hash:1bd7be9ba072b26c11489c1b07e486b70790076d070e066bdf4e1c47a7cc0de42f82b075f29792fcf30d03be74d3a2a1ec05f90139a8614c4bb99b942f9ae870
|
38
|
+
|
14
|
-
|
39
|
+
<Content-Hashを算出するための呼び出し側>
|
40
|
+
BittrexAuthenticationProvider provider = new BittrexAuthenticationProvider(new ApiCredentials(_apiKey, _apiSecret));
|
41
|
+
string jsonContentHash = provider.retContentHash(paramaters);
|
15
42
|
|
16
43
|
|
44
|
+
<Content-Hash算出ロジック>
|
45
|
+
※https://github.com/JKorf/Bittrex.Net/blob/master/Bittrex.Net/BittrexAuthenticationProvider.csを参照して記述
|
46
|
+
public class BittrexAuthenticationProvider : AuthenticationProvider
|
47
|
+
{
|
48
|
+
private readonly HMACSHA512 encryptorHmac;
|
49
|
+
private readonly SHA512 encryptor;
|
50
|
+
private readonly object locker;
|
51
|
+
|
52
|
+
public string retContentHash(Dictionary<string, object> parameters)
|
53
|
+
{
|
54
|
+
string jsonContent;
|
55
|
+
if (parameters.Any() && parameters.First().Key == string.Empty)
|
56
|
+
jsonContent = JsonConvert.SerializeObject(parameters.First().Value);
|
57
|
+
else
|
58
|
+
jsonContent = JsonConvert.SerializeObject(parameters.OrderBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value));
|
59
|
+
jsonContent = ByteToString(encryptor.ComputeHash(Encoding.UTF8.GetBytes(jsonContent))).ToLower(CultureInfo.InvariantCulture);
|
60
|
+
return jsonContent;
|
61
|
+
}
|
62
|
+
|
63
|
+
public string retSign(string sign)
|
64
|
+
{
|
65
|
+
sign = ByteToString(encryptorHmac.ComputeHash(Encoding.UTF8.GetBytes(sign)));
|
66
|
+
return sign;
|
67
|
+
}
|
68
|
+
|
69
|
+
public BittrexAuthenticationProvider(ApiCredentials credentials) : base(credentials)
|
70
|
+
{
|
71
|
+
if (credentials.Secret == null)
|
72
|
+
throw new ArgumentException("ApiKey/Secret needed");
|
73
|
+
|
74
|
+
locker = new object();
|
75
|
+
encryptorHmac = new HMACSHA512(Encoding.ASCII.GetBytes(credentials.Secret.GetString()));
|
76
|
+
encryptor = SHA512.Create();
|
77
|
+
}
|
78
|
+
public override string Sign(string toSign)
|
79
|
+
{
|
80
|
+
lock (locker)
|
81
|
+
return BitConverter.ToString(encryptorHmac.ComputeHash(Encoding.ASCII.GetBytes(toSign))).Replace("-", string.Empty);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|