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.
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
Imports Newtonsoft.Json.Linq
and the appropriate reference