YoBit tapi问题与recetincation

问题描述:

我想为自己写简单的应用程序,当我尝试拨打 getInfo方法我总是得到一个错误到响应。密钥,符号,方法或随机数不正确。我找到了一些例子,但我仍然无法在代码中发现错误。任何人都可以帮助我吗?YoBit tapi问题与recetincation

代码正常工作 for hitbtc。我知道yobit有点不同,但我认为我已经适应了这一点。

我的代码:

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 

的代码已经成功地测试了hitbtc。

所以加密部分是正确的。我把它放在这里,无论如何,完整性

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 

所以,

的完整性检查

此代码的工作

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 

随着yobit的东西是不同的。我必须使用帖子而不是get。我得添加更多的标题。不过,我认为我已经解决了这个问题。

它不起作用。

为yobit API的Python函数是这样我只需要翻译,要vb.net我想我已经做得非常圆满

API Call Authentication in Python (Working PHP example)

我认为错误是在这里

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); 

有我所复制的东西是方法= getInfo & nonce = 636431012620这是我发布的内容。

所以这似乎是正确的。

+0

我不认为你的URL添加方法之一。你应该使用post命令。 –

+0

谢谢你的回答。你是对的。问题是错误的请求。我已经找到了解决方案 – Alex

看起来像是有效的。

我只需要改变现时所以,它的0至2^31

因此,这是错误

post = "method=getInfo&nonce=636431012620 

乱数应该不会那么大。在最应该是

此外,虽然没有记录,我必须补充

内容类型头的一个。这是最终的解决方案

Dim nonce = exchanges.getNonce().ToString 
    Dim content = hashObject("", nonce, "method=getInfo&nonce=") 
    Dim sighash = computeSig(content) 
    Dim result = CookieAwareWebClient.downloadString1("https://yobit.net/tapi/", content, {New Tuple(Of String, String)("Key", _apiKey), New Tuple(Of String, String)("Sign", sighash), New Tuple(Of String, String)("Content-Type", "application/x-www-form-urlencoded")}) 

所以我说New Tuple(Of String, String)("Content-Type", "application/x-www-form-urlencoded")作为标题

Protected Overridable Function computeSig(content As String) As String 
    Dim hasher = New System.Security.Cryptography.HMACSHA512(System.Text.Encoding.UTF8.GetBytes(_secret)) 
    Return CalculateSignature2(content, hasher) 
End Function 

Public Shared Function CalculateSignature2(content As String, hasher As System.Security.Cryptography.HMAC) As String 
    Dim siginhash = hasher.ComputeHash(System.Text.Encoding.UTF8.GetBytes(content)) 
    Dim sighash = exchanges.getString(siginhash) 'convert bytes to string 
    Return sighash 
End Function 

Public Shared Function downloadString1(url As String, post As String, otherHeaders As Tuple(Of String, String)()) As String 
    Dim wc = New CookieAwareWebClient() 
    For Each oh In otherHeaders 
     wc.Headers.Add(oh.Item1, oh.Item2) 
    Next 

    Dim response = String.Empty 

    Try 
     If post = "" Then 
      response = wc.DownloadString(url) 
     Else 
      response = wc.UploadString(url, post) 
     End If 
    Catch ex As Exception 
     Dim a = 1 
    End Try 

    Return response 
End Function