Bitcoin Forum
May 18, 2024, 12:47:02 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: VB.Net and Exchange trading APIs  (Read 145 times)
mchurlet (OP)
Newbie
*
Offline Offline

Activity: 5
Merit: 0


View Profile
March 14, 2018, 09:13:30 AM
 #1

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.
Gabrics
Full Member
***
Offline Offline

Activity: 183
Merit: 112

Just digging around


View Profile WWW
March 14, 2018, 03:18:30 PM
 #2

Hi,

.Net is not really handy for Bitcoin Sad

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

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

zool2003
Jr. Member
*
Offline Offline

Activity: 126
Merit: 3

Joe's Signatureless Challenge


View Profile
March 14, 2018, 03:31:45 PM
 #3

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

▬▬▬ I'm part of a movement to help make the forums a better place and free it of spam:▬▬▬
█ █  http://bit.ly/SigFree  █ █
Anti-Cen
Member
**
Offline Offline

Activity: 210
Merit: 26

High fees = low BTC price


View Profile
March 15, 2018, 02:26:32 PM
 #4

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.

 

Mining is CPU-wars and Intel, AMD like it nearly as much as big oil likes miners wasting electricity. Is this what mankind has come too.
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!