Bitcoin Forum
May 26, 2024, 02:49:38 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: [VBNET] Need help with BTER API (0.5 BTC bounty)  (Read 5132 times)
LeChatNoir (OP)
Hero Member
*****
Offline Offline

Activity: 699
Merit: 501


Coinpanion.io - Copy Successful Crypto Traders


View Profile WWW
June 07, 2013, 12:15:49 PM
Last edit: June 14, 2013, 03:22:15 PM by LeChatNoir
 #1

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




Coinpanion.io - Copy Successful Crypto Traders
rolloffacliffpleaseanddie
Newbie
*
Offline Offline

Activity: 14
Merit: 0


View Profile
June 07, 2013, 02:40:24 PM
 #2

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?
LeChatNoir (OP)
Hero Member
*****
Offline Offline

Activity: 699
Merit: 501


Coinpanion.io - Copy Successful Crypto Traders


View Profile WWW
June 07, 2013, 03:24:15 PM
 #3

graphical user interface

Coinpanion.io - Copy Successful Crypto Traders
Alexander The Great
Newbie
*
Offline Offline

Activity: 28
Merit: 0



View Profile
June 07, 2013, 03:30:09 PM
 #4

Im not sure
LeChatNoir (OP)
Hero Member
*****
Offline Offline

Activity: 699
Merit: 501


Coinpanion.io - Copy Successful Crypto Traders


View Profile WWW
June 07, 2013, 05:14:23 PM
 #5

anyone?

Coinpanion.io - Copy Successful Crypto Traders
Alexander The Great
Newbie
*
Offline Offline

Activity: 28
Merit: 0



View Profile
June 07, 2013, 05:49:42 PM
 #6

PM me if you need help
LeChatNoir (OP)
Hero Member
*****
Offline Offline

Activity: 699
Merit: 501


Coinpanion.io - Copy Successful Crypto Traders


View Profile WWW
June 14, 2013, 03:23:55 PM
 #7

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.

Coinpanion.io - Copy Successful Crypto Traders
hsharrison
Newbie
*
Offline Offline

Activity: 25
Merit: 0


View Profile
June 29, 2013, 10:57:43 PM
 #8

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
Rogue5pawn
Newbie
*
Offline Offline

Activity: 26
Merit: 0


View Profile
November 02, 2013, 08: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
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!