This repo is a fork of the repo which fully supports the integration of Volmex websocket endpoints. See more information here.
go-socket.io is library an implementation of Socket.IO in Golang, which is a realtime application framework.
Current this library supports 1.4 version of the Socket.IO client. It supports room, namespaces and broadcast at now.
Install the package with:
go get github.com/volmexfinance/go-socket.ioImport it with:
import "github.com/volmexfinance/go-socket.io"and use socketio as the package name inside the code.
Please check more examples into folder in project for details. Examples
- Public Websocket Example
-
Private Websocket Example
- Note: You will need to get credentials to get a jwtToken for access. https://docs.volmex.finance/index-data-api#websockets
package main
import (
"context"
"fmt"
socketio "github.com/volmexfinance/go-socket.io"
"github.com/volmexfinance/go-socket.io/engineio"
)
type DataPoint struct {
Symbol string
Price float64
Timestamp int64
}
func main() {
ctx := context.Background()
dataPointsChannel := make(chan *DataPoint)
client, err := socketio.NewClient("ws://ws.volmex.finance", &engineio.Options{})
if err != nil {
return
}
client.OnConnect(func(c socketio.Conn) error {
fmt.Println("Connected")
client.Emit("fetch-indices-messages")
client.OnEvent("indices-messages-stream", func(s socketio.Conn, msg DataPoint) {
dataPointsChannel <- &msg
})
return nil
})
err = client.Connect()
if err != nil {
return
}
for {
select {
case <-ctx.Done():
return
case dataPoint := <-dataPointsChannel:
fmt.Printf("Received data point %s - %f - %d\n", dataPoint.Symbol, dataPoint.Price, dataPoint.Timestamp)
}
}
}
The 3-clause BSD License - see LICENSE for more details