Tôi đang cố gắng viết ứng dụng đơn giản cho bản thân mình và khi tôi cố gắng gọi phương thức getInfo tôi luôn nhận được thông báo lỗi. Khóa, ký hiệu, phương thức hoặc nonce không chính xác. Tôi đã tìm thấy một số ví dụ nhưng tôi vẫn không thể tìm thấy lỗi trong mã của mình. Bất cứ ai có thể giúp tôi với nó?Các vấn đề về tapi của YoBit với sự xác thực
Mã hoạt động tốt cho hitbtc. Tôi biết yobit có một chút khác biệt nhưng tôi nghĩ tôi đã chứa đựng điều đó.
Mã của tôi:
Protected Shared Function readStrings(signatureheader As String, host As String, pathandQuery As String, post As String, secret As String, hasher As System.Security.Cryptography.HMAC, otherHeaders As Tuple(Of String, String)()) As String
'apikey=98998BEEB8796455044F02E4864984F4
'secret=44b7659167ffc38bb34fa35b5c816cf5
hasher.Key = exchanges.getBytes(secret)
Dim url = host + pathandQuery ' url = "https://yobit.net/tapi/"
Dim wc = New CookieAwareWebClient()
Dim sigHash2 = ""
If post = "" Then
sigHash2 = CalculateSignature2(pathandQuery, hasher)
Else
'post = "method=getInfo&nonce=636431012620"
sigHash2 = CalculateSignature2(post, hasher) 'sighash2= "ece0a3c4af0c68dedb1f840d0aef0fd5fb9fc5e808105c4e6590aa39f4643679af5da52b97d595cd2277642eb27b8a357793082007abe1a3bab8de8df24f80d2"
End If
wc.Headers.Add(signatureheader, sigHash2) ' SignatureHeader ="Sign"
Dim response = ""
For Each oh In otherHeaders ' otherHeaders =(0) {(Key, 98998BEEB8796455044F02E4864984F4)} System.Tuple(Of String, String)
wc.Headers.Add(oh.Item1, oh.Item2)
Next
'- wc.Headers {Sign: ece0a3c4af0c68dedb1f840d0aef0fd5fb9fc5e808105c4e6590aa39f4643679af5da52b97d595cd2277642eb27b8a357793082007abe1a3bab8de8df24f80d2 Key: 98998BEEB8796455044F02E4864984F4 } System.Net.WebHeaderCollection
'url = "https://yobit.net/tapi/"
'post = "method=getInfo&nonce=636431012620"
If post = "" Then
response = wc.DownloadString(url)
Else
response = wc.UploadString(url, post) 'response = response "{"success":0,"error":"invalid key, sign, method or nonce"}" String
End If
Return response
End Function
Mã này đã được thử nghiệm thành công cho hitbtc.
Vì vậy, phần mã hóa là chính xác. Tôi đặt nó ở đây anyway cho đầy đủ
Protected Shared Function CalculateSignature2(text As String, hasher As System.Security.Cryptography.HMAC) As String
Dim siginhash = hasher.ComputeHash(exchanges.getBytes(text))
Dim sighash = exchanges.getString(siginhash)
Return sighash
End Function
Vì vậy,
để kiểm tra sự tỉnh táo
Mã này hoạt động
Public Overrides Sub readbalances()
Dim response = readStrings("X-Signature", "https://api.hitbtc.com", "/api/1/trading/balance?nonce=" + exchanges.getNonce().ToString + "&apikey=" + _apiKey, "", _secret, New System.Security.Cryptography.HMACSHA512(), {})
End Sub
Với điều yobit là khác nhau. Tôi đã sử dụng bài thay vì nhận được. Tôi phải thêm nhiều tiêu đề hơn. Tuy nhiên, tôi nghĩ rằng tôi đã cố định điều đó.
Nó không hoạt động.
Chức năng python cho API yobit là điều này tôi chỉ cần dịch đó để vb.net mà tôi nghĩ là tôi đã làm một cách trung thực
API Call Authentication in Python (Working PHP example)
Tôi nghĩ rằng sai lầm là quanh đây
request_url = "https://yobit.net/tapi";
request_body = "method=TradeHistory&pair=ltc_btc&nonce=123";
signature = hmac_sha512(request_body,yobit_secret);
http_headers = {
"Content-Type":"application/x-www-form-urlencoded",
"Key":yobit_public_key,
"Sign":signature
}
response = http_post_request(request_url,request_body,http_headers);
result = json_decode(response.text);
Có những thứ mà tôi đã sao chép là method = getInfo & nonce = 636431012620 là những gì tôi đưa vào bài đăng.
Điều đó có vẻ đúng.
Tôi không nghĩ rằng bạn thêm phương thức trên URL. Bạn nên sử dụng lệnh post. –
Cảm ơn bạn đã trả lời. Bạn đúng rồi. Vấn đề là với yêu cầu sai. Tôi đã tìm được giải pháp – Alex