Author

Topic: [VBNET] Need help with BTER API (0.5 BTC bounty) (Read 5132 times)

newbie
Activity: 26
Merit: 0
November 02, 2013, 04:05:02 AM
#9
Hopefully that Bounty is Still open. This works in Visual Studios 2010 Ultimate. You can refer to the BTCe API stuff for more details. I just deleted the Functions and replaced the "random" definition:

Code:
Imports System.Net
Imports System.Text
Imports System.IO
Imports System.Security.Cryptography

Public Class Form1

    Private Sub Form1_Load_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LstType.Items.Add("buy")
        LstType.Items.Add("sell")
        LstPair.Items.Add("ltc_usd")
        LstPair.Items.Add("ltc_btc")
        LstPair.Items.Add("btc_usd")
        lstmeth.Items.Add("Trade")
        lstmeth.Items.Add("getinfo")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim postData As String

        Dim postReq As HttpWebRequest = DirectCast(WebRequest.Create("https://www.cryptsy.com/api"), HttpWebRequest)
        Dim randomn As String
        Dim keyer As String = LCase("YourKey") 'your key goes here
        Dim secret As String = "YourSecretKey" 'your secret goes here
        randomn = CLng(DateTime.UtcNow.Subtract(New DateTime(1970, 1, 1)).TotalSeconds)
        postData = "method=" & lstmeth.SelectedItem & "&nonce=" & randomn

        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.Close()
        Dim postresponse As HttpWebResponse

        postresponse = DirectCast(postReq.GetResponse(), HttpWebResponse)

        Dim postreqreader As New StreamReader(postresponse.GetResponseStream())

        Dim thepage As String = postreqreader.ReadToEnd
        thepage = thepage.Replace(Chr(34), Chr(39))

        MsgBox(thepage)


    End Sub

End Class

And just in case :-P
BTC: 1pJJjL7CsujpmBTkhwjoDDEkhDCKt9nna
newbie
Activity: 25
Merit: 0
I just stumbled on your post... and you've probably figured this out by now. But if not: I don't know VB.NET but if you can interface with Python perhaps my solution will be of use.

https://github.com/hsharrison/bter-api
hero member
Activity: 699
Merit: 501
Coinpanion.io - Copy Successful Crypto Traders
I'm still stucked with this problem so i decided to give 0.5 BTC bounty to the first one who show me how to send an order to BTER via API in VB.NET.
newbie
Activity: 28
Merit: 0
PM me if you need help
hero member
Activity: 699
Merit: 501
Coinpanion.io - Copy Successful Crypto Traders
anyone?
newbie
Activity: 28
Merit: 0
Im not sure
hero member
Activity: 699
Merit: 501
Coinpanion.io - Copy Successful Crypto Traders
graphical user interface
newbie
Activity: 14
Merit: 0
Hi guys i'm trying to build a GUI for BTER in VBNET.
I'm using the following functions to get info on available funds


Private 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





Whats a GUI?
hero member
Activity: 699
Merit: 501
Coinpanion.io - Copy Successful Crypto Traders
Hi guys i'm trying to build a GUI for BTER in VBNET.
I'm using the following functions to get info on available funds


Private 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



Jump to: