Bitcoin Forum

Other => Beginners & Help => Topic started by: binaryblue on July 10, 2011, 06:44:43 PM



Title: Need VB.NET help with Mt Gox API
Post by: binaryblue on July 10, 2011, 06:44:43 PM
Hi Bitcoin Forum. 

I'm writing a program that needs to grab info from the Mt. Gox API.  However, I can't even get the public info (Ticker Data, Market Depth, etc.).  I've tried using (with no success):

Code:
Dim wc As new System.Net.WebClient
wc.DownloadString(New Uri("http://mtgox.com/code/data/ticker.php"))


Below is from a different thread outside the newbies section on this site:  The person was able to get the public info though. 
Code:
    Function PostWebpageData(ByVal url As String, ByVal Data As String) As String
        If My.Computer.Network.IsAvailable Then
            Dim Client As New Net.WebClient

            Return (Client.UploadString(url, Data))
        Else
            MsgBox("Unable to acess the internet")
        End If

    End Function

In fact, when I go to http://mtgox.com/code/data/ticker.php (http://mtgox.com/code/data/ticker.php) in firefox, I get a prompt to download the PHP page, which does have info in it. 

Can anybody show me the code needed to get the public data from Mt. Gox's API?


Title: Re: Need VB.NET help with Mt Gox API
Post by: runlinux on July 10, 2011, 07:01:27 PM
i have a working bot and getting the public API was easy.

let me post a few snippets for you:

Code:
        html = ""

        myURL = "http://mtgox.com/code/data/ticker.php"

        winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
        winHttpReq.setTimeouts(60000, 60000, 60000, 60000)
        winHttpReq.Open("GET", myURL, False)
        winHttpReq.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

        On Error Resume Next
        winHttpReq.Send()

        html = winHttpReq.responseText

From there, you can parse the html and get what you need from it.

and for getting your own personal stuff:

Code:
Sub getBalance()
        'Get Balance???
        Dim postString As String
        Dim postArray() As Byte

        html = ""
        postString = "name=" & username & "&pass=" & password
        postArray = System.Text.Encoding.GetEncoding(1252).GetBytes(postString)

        myURL = "https://mtgox.com/code/getFunds.php"
        winHttpReq = CreateObject("WinHttp.WinHttpRequest.5.1")
        winHttpReq.setTimeouts(60000, 60000, 60000, 60000)
        winHttpReq.Open("POST", myURL, False)
        winHttpReq.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")

        On Error Resume Next
        winHttpReq.Send(postArray)

        html = winHttpReq.responseText

    End Sub

same thing, just parse the html and you can see if it works or not.


Title: Re: Need VB.NET help with Mt Gox API
Post by: binaryblue on July 10, 2011, 07:16:28 PM
Thanks runlinux!  Just what I needed.


Title: Re: Need VB.NET help with Mt Gox API
Post by: runlinux on July 10, 2011, 07:19:05 PM
glad i could help. I was scratching my head for a few weeks trying to get the posting of data working.

now, write a bot and rule the world!