github.com/volmexfinance/go-socket.io


License
BSD-3-Clause
Install
go get github.com/volmexfinance/go-socket.io

Documentation

go-socket.io

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.

Badges

Build Status GoDoc License Release Go Report Card

Contents

Install

Install the package with:

go get github.com/volmexfinance/go-socket.io

Import it with:

import "github.com/volmexfinance/go-socket.io"

and use socketio as the package name inside the code.

Example

Please check more examples into folder in project for details. Examples

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)
		}
	}

}

License

The 3-clause BSD License - see LICENSE for more details