binancewebsocket

package module
v0.0.0-...-32cf3dd 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-binance-websocket

Binance websocket client with optimized latency

Optimized latency

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

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

BenchmarkBinanceMessageHandling-6  38260412  946 ns/op  128 B/op  8 allocs/op

Example

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

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

	if err != nil {
		log.Fatalf("failed to connect to binance @depth 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 NewBinanceWs

func NewBinanceWs() *binanceWs

func ResetDepth

func ResetDepth(i interface{}) error

Used by reference countable pool

Types

type Depth

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

func AcquireDepth

func AcquireDepth() *Depth

Method to get new Depth

func (*Depth) Reset

func (d *Depth) Reset()

type RawDepth

type RawDepth struct {
	LastUpdateID int64       `json:"u"`
	Bids         [][2]string `json:"b"`
	Asks         [][2]string `json:"a"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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