Hi guys i'm trying to build a GUI for BTER in VBNET.
I'm using the following functions to get info on available fundsPrivate Function StringToSHA512(ByVal content As String) As String
Dim M5 As New SHA512Managed
Dim bytestring() As Byte = Encoding.UTF8.GetBytes(content)
bytestring = M5.ComputeHash(bytestring)
Dim signer As String = Nothing
For Each bt As Byte In bytestring
signer &= bt.ToString("x2")
Next
Return signer
End Function
Private Function GetUnixTimestamp(ByVal currDate As DateTime) As double
'create Timespan by subtracting the value provided from the Unix Epoch
Dim span As TimeSpan = (currDate - New DateTime(2012, 1, 1, 0, 0, 0, 0).ToLocalTime())
'return the total seconds (which is a UNIX timestamp)
Return span.TotalSeconds
End Function
Private Function response(ByVal postdata As String) As String
Dim postReq As HttpWebRequest
Try
postReq = DirectCast(WebRequest.Create("
https://bter.com/api/1/private/getfunds"), HttpWebRequest)
Dim keyer As String = LCase("85XXXC8-9CXD-4X0-8X4A-95XXXXXX515") 'your key goes here
Dim secret As String = "f87f4XXXXXb956bcfdXXXXXe19e9120XXXXXX6c8a" 'your secret goes here
Dim KeyByte() As Byte = Encoding.ASCII.GetBytes(secret)
Dim HMAcSha As New HMACSHA512(Encoding.ASCII.GetBytes(secret))
Dim messagebyte() As Byte = Encoding.ASCII.GetBytes(postdata)
Dim hashmessage() As Byte = HMAcSha.ComputeHash(messagebyte)
Dim Sign As String = BitConverter.ToString(hashmessage)
Sign = Sign.Replace("-", "")
postReq.Method = "POST"
postReq.KeepAlive = False
postReq.Headers.Add("Key", keyer)
postReq.Headers.Add("Sign", LCase(Sign))
postReq.ContentType = "application/x-www-form-urlencoded"
postReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv:1.9.2.3) Gecko/20100401 Firefox/4.0 (.NET CLR 3.5.30729)"
postReq.ContentLength = messagebyte.Length
Dim postreqstream As Stream = postReq.GetRequestStream()
postreqstream.Write(messagebyte, 0, messagebyte.Length)
postreqstream.Dispose()
Dim PostRes As HttpWebResponse = DirectCast(postReq.GetResponse(), HttpWebResponse)
Dim postreqreader As New StreamReader(PostRes.GetResponseStream())
response = postreqreader.ReadToEnd.Replace(Chr(34), Chr(39))
postreqreader.Dispose()
PostRes.Close()
Catch ex As Exception
response = ""
End Try
End Function
When i call the above function "response"TextBox1.Text = response("nonce=" & GetUnixTimestamp(Now))
It prints {'result':'false','message':'Error: invalid data'}What am i doing wrong?
You can find documentation for the above API here https://bter.com/api#trade
At the bootom of the page there is a PHP example
Tyvm