connection code to websocket using vb.net

Dear Admin,

I am only need data from tick history for my application, and I am using vb.net but seem that no sample code for connection to your websocket and api code to get tick history with vb.net

anyone can help me with the code, thanks for your assitance before.

Regards,
dhewa

Comments

  • edited April 2016

    Hello @dhewa. You just need to send the correct query using some VB.Net websocket connection. For example using WebSocket4Net you can do this.

    `Public Class Form1

    Private websocket As WebSocket4Net.WebSocket
    Private Sub Button1_Click(sender As Object, ev As EventArgs) Handles Button1.Click
        websocket = New WebSocket4Net.WebSocket("wss://ws.binaryws.com/websockets/v3")
        AddHandler websocket.Opened, Sub(s, e) socketOpened(s, e)
        AddHandler websocket.Error, Sub(s, e) socketError(s, e)
        AddHandler websocket.Closed, Sub(s, e) socketClosed(s, e)
        AddHandler websocket.MessageReceived, Sub(s, e) socketMessage(s, e)
        AddHandler websocket.DataReceived, Sub(s, e) socketDataReceived(s, e)
    
        websocket.Open()
    
    End Sub
    
    Sub socketOpened(s As Object, e As EventArgs)
        websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")
    End Sub
    
    Sub socketClosed(s As Object, e As EventArgs)
    
    End Sub
    
    Sub socketError(s As Object, e As SuperSocket.ClientEngine.ErrorEventArgs)
    
    End Sub
    
    Sub socketMessage(s As Object, e As WebSocket4Net.MessageReceivedEventArgs)
        MsgBox(e.Message)
    End Sub
    
    
    Sub socketDataReceived(ss As Object, e As WebSocket4Net.DataReceivedEventArgs)
    
    End Sub
    

    End Class`

    Regards

  • hello @tarja

    well note for your code, i wll try and revert to you soon, thanks as always..

    regards,

  • HI @tarja...and how we get the string of message from websocket,that we can to manipulate the JSON data..ex: we request websocket.send("{"""tick""":""R_100""}") and get the result in message from websocket.

  • edited February 2018

    Hello, i'm developing vb.net application and i use the same come but i have a problem even if the command connect give me result ok, when i send data i got always you must send data only if websocket is open...
    Could you help me:?

    Private websocket As WebSocket4Net.WebSocket
        Sub Main()
    
            WebSocket = New WebSocket4Net.WebSocket("wss://ws.binaryws.com/websockets/v3")
            AddHandler WebSocket.Opened, Sub(s, e) socketOpened(s, e)
            AddHandler WebSocket.Error, Sub(s, e) socketError(s, e)
            AddHandler WebSocket.Closed, Sub(s, e) socketClosed(s, e)
            AddHandler WebSocket.MessageReceived, Sub(s, e) socketMessage(s, e)
            AddHandler WebSocket.DataReceived, Sub(s, e) socketDataReceived(s, e)
    
            websocket.Open()
            Console.WriteLine(websocket.State)
            websocket.AutoSendPingInterval = 10
            websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")
    
    
        End Sub
    
        Sub socketOpened(s As Object, e As EventArgs)
            websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")
        End Sub
    
        Sub socketClosed(s As Object, e As EventArgs)
    
        End Sub
    
        Sub socketError(s As Object, e As SuperSocket.ClientEngine.ErrorEventArgs)
            MsgBox(e.Exception.ToString
                   )
        End Sub
    
        Sub socketMessage(s As Object, e As WebSocket4Net.MessageReceivedEventArgs)
            MsgBox(e.Message)
        End Sub
    
    
        Sub socketDataReceived(ss As Object, e As WebSocket4Net.DataReceivedEventArgs)
            MsgBox(e.Data)
        End Sub
    
  • All websocket connections need an application ID - you can register here:

    https://developers.binary.com/applications/

    and then pass the ID from the new application as the app_id parameter:

    wss://ws.binaryws.com/websockets/v3?app_id=XXX

    Please see https://developers.binary.com/guide/ for more details.

  • I registered my application and insert the id app but the problem still exist
  • edited September 2017

    @termi_80 in your code you are sending send just after open call

    websocket.Open()
        Console.WriteLine(websocket.State)
        websocket.AutoSendPingInterval = 10
        websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")
    

    it should be inside this sub

    Sub socketOpened(s As Object, e As EventArgs)
        websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")
    End Sub
    

    or inside this

    Sub socketMessage(s As Object, e As WebSocket4Net.MessageReceivedEventArgs)
        MsgBox(e.Message)
    End Sub
    

    if you want to chain

  • Hi guys im new to coding and want to learn how to create my own trading strategy and buttons with VB,Net so i used this code but its not working for me im trying to get the tick chart into some form to analyse the charts and build a frame around it i also want to open trades please advice. i got this till now

    Public Class Form1

    Private websocket As WebSocket4Net.WebSocket
    
    Private Sub Button1_Click(ByVal sender As Object, ByVal ev As EventArgs) Handles Button1.Click
        websocket = New WebSocket4Net.WebSocket("wss://ws.binaryws.com/websockets/v3?app_id=120xxx")
        AddHandler websocket.Opened, Sub(s, e) socketOpened(s, e)
        AddHandler websocket.Error, Sub(s, e) socketError(s, e)
        AddHandler websocket.Closed, Sub(s, e) socketClosed(s, e)
        AddHandler websocket.MessageReceived, Sub(s, e) socketMessage(s, e)
        AddHandler websocket.DataReceived, Sub(s, e) socketDataReceived(s, e)
    
        websocket.Open()
    
    End Sub
    
    Sub socketOpened(ByVal s As Object, ByVal e As EventArgs)
        websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")
    End Sub
    
    Sub socketClosed(ByVal s As Object, ByVal e As EventArgs)
    
    End Sub
    
    Sub socketError(ByVal s As Object, ByVal e As SuperSocket.ClientEngine.ErrorEventArgs)
    
    End Sub
    
    Sub socketMessage(ByVal s As Object, ByVal e As WebSocket4Net.MessageReceivedEventArgs)
        MsgBox(e.Message)
    End Sub
    
    
    Sub socketDataReceived(ByVal ss As Object, ByVal e As WebSocket4Net.DataReceivedEventArgs)
    
    End Sub
    

    End Class

  • @tarja please create example connection code to websocket using vb.net 2010 support with TLS version 1.2
    thanks

Sign In or Register to comment.