gatewebsocket

package module
v0.0.0-...-2d150f1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2020 License: MIT Imports: 6 Imported by: 0

README

Build Status

go-gate-websocket

Gate.io websocket client with optimized latency by leveraging object pool and fast json deserializer

Optimized latency

Leveraging fast json deserializer and object pool for good base performance (i5 6-core): ~700 ns/op or ~1.4M op/s

$ go test --bench=. --benchtime 30s --benchmem

BenchmarkGateMessageHandling-6   	50664753	       707 ns/op	      72 B/op	       9 allocs/op

Example

import (
	. "github.com/alexey-ernest/go-gate-websocket"
	"log"
)

func main() {
	ws := NewGateWs()
	messages := make(chan *Depth, 10)
	err, _ := ws.SubscribeDepth("BTC_USDT", func (d *Depth) {
		messages <- d
	})

	if err != nil {
		log.Fatalf("failed to connect to gate websocket")
	}

	for m := range messages {
		log.Printf("%+v\n", m.RawDepth)
		m.DecrementReferenceCount() // return object back to the object pool
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGateWs

func NewGateWs() *gateWs

func ResetDepth

func ResetDepth(i interface{}) error

Used by reference countable pool

Types

type Depth

type Depth struct {
	pool.ReferenceCounter `json:"-"`
	RawDepth
}

pooled depth message

func AcquireDepth

func AcquireDepth() *Depth

Method to get new Depth

func (*Depth) Reset

func (d *Depth) Reset()

type RawDepth

type RawDepth struct {
	Clean bool
	Bids  [][2]string
	Asks  [][2]string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL