Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: mchurlet on March 14, 2018, 09:13:30 AM



Title: VB.Net and Exchange trading APIs
Post by: mchurlet on March 14, 2018, 09:13:30 AM
Hello
I am looking for VB.Net documentation and code examples for using Exchange trading APIs. I found something in C but not in VB.Net.
I wish I could read the info from my account and place trades.


Title: Re: VB.Net and Exchange trading APIs
Post by: Gabrics on March 14, 2018, 03:18:30 PM
Hi,

.Net is not really handy for Bitcoin :(

Most of the exchanges as far as I checked some kind of JSON interface. Simple HTTP from that.

Example
https://www.bitstamp.net/api/



Title: Re: VB.Net and Exchange trading APIs
Post by: zool2003 on March 14, 2018, 03:31:45 PM
Hello
I am looking for VB.Net documentation and code examples for using Exchange trading APIs. I found something in C but not in VB.Net.
I wish I could read the info from my account and place trades.

Code:
    Public Sub coinprice()
        Try
            Dim request As HttpWebRequest
            Dim response As HttpWebResponse = Nothing
            Dim reader As StreamReader
            ServicePointManager.Expect100Continue = True
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

            request = DirectCast(WebRequest.Create("https://stocks.exchange/api2/ticker"), HttpWebRequest)

            response = DirectCast(request.GetResponse(), HttpWebResponse)
            reader = New StreamReader(response.GetResponseStream())

            Dim rawresp As String
            rawresp = reader.ReadToEnd()

            Dim array As JArray = JArray.Parse(rawresp)

            For Each item As JObject In array
                Dim name As String = If(item("market_name") Is Nothing, "", item("market_name").ToString())
                Dim email As String = If(item("last") Is Nothing, "", item("last").ToString())
                If name = "SUM_BTC" Then
                    Console.WriteLine("Name: " & name)
                    Console.WriteLine("Email: " & email)
                    coinpriceLabel.Text = email & " BTC"
                End If

            Next
        Catch ex As Exception
            Console.WriteLine(ex)
            coinpriceLabel.Text = "Too Many Connections"
        End Try
    End Sub

This works for me. The initial code was on stack exchange I think and I did some alterations myself. Its not finished so don't punish me for it looking hacky.

It also deals with too many connection attempts through an exception.

You will need to add this

Code:
Imports Newtonsoft.Json.Linq

and the appropriate reference


Title: Re: VB.Net and Exchange trading APIs
Post by: Anti-Cen on March 15, 2018, 02:26:32 PM
Nothing wrong with using VB for the API's and it uses the same p-code as .NET C# but in
general it's easier to find C# example code than VB code.

I tend to use raw sockets instead of HttpWebRequest mainly because in multil-threaded  programs the
web-requests seems to block and using more than a few connections does nothing to speed things
up unless you go raw.