ws

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HeartBeatDuration period for sending ping packet according documentation
	HeartBeatDuration = time.Second * 20
	KeepAliveDuration = time.Second * 60
)
View Source
const (
	HostPerpetualReal     = "wss://stream.bybit.com/v5/public/linear"
	HostPerpetualtTestnet = "wss://stream-testnet.bybit.com/v5/public/linear"
)
View Source
const (
	WSKLine        = "kline"
	WSKPublicTrade = "publicTrade"
	WSKOrderbook   = "orderbook"
	WSDisconnected = "disconnected"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ByBitWS

type ByBitWS struct {
	Ended bool
	// contains filtered or unexported fields
}

func New

func New(config *Configuration) *ByBitWS

func (*ByBitWS) Close

func (b *ByBitWS) Close()

func (*ByBitWS) CloseAndReconnect

func (b *ByBitWS) CloseAndReconnect()

func (*ByBitWS) Emit

func (b *ByBitWS) Emit(event interface{}, arguments ...interface{}) *emission.Emitter

Emit emits an event

func (*ByBitWS) HandlePong added in v0.0.5

func (b *ByBitWS) HandlePong() (err error)

func (*ByBitWS) IsConnected

func (b *ByBitWS) IsConnected() bool

IsConnected returns the WebSocket connection state

func (*ByBitWS) Off

func (b *ByBitWS) Off(event interface{}, listener interface{}) *emission.Emitter

Off removes a listener for an event

func (*ByBitWS) On

func (b *ByBitWS) On(event interface{}, listener interface{}) *emission.Emitter

On adds a listener to a specific event

func (*ByBitWS) Send

func (b *ByBitWS) Send(msg string) error

func (*ByBitWS) SendCmd

func (b *ByBitWS) SendCmd(cmd Cmd) error

func (*ByBitWS) Start

func (b *ByBitWS) Start() error

func (*ByBitWS) StartRAW added in v0.0.5

func (b *ByBitWS) StartRAW(eventCH chan string) chan struct{}

StartRAW gives you a raw ws stream, you need to handle pong events by yourself.

func (*ByBitWS) Subscribe

func (b *ByBitWS) Subscribe(topic, interval, coinPair string)

Topic => `kline`

Interval 1 3 5 15 30 60 120 240 360 720 minute D day W week M month

CoinPair => BTCUSDT

Subscribe subscribes on ws topic to fetch data

func (*ByBitWS) SubscribeToMany added in v0.0.4

func (b *ByBitWS) SubscribeToMany(streams ...string) error

SubscribeToMany

stream examples

"orderbook.1.BTCUSDT"
"publicTrade.BTCUSDT"

func (*ByBitWS) Unsubscribe added in v0.0.5

func (b *ByBitWS) Unsubscribe(topic, interval, coinPair string)

Unsubscribe subscribes on ws topic to fetch data

type Cmd

type Cmd struct {
	Op   string        `json:"op"`
	Args []interface{} `json:"args"`
}

type Configuration

type Configuration struct {
	Addr          string `json:"addr"`
	Proxy         string `json:"proxy"` // http://127.0.0.1:1081
	ApiKey        string `json:"api_key"`
	SecretKey     string `json:"secret_key"`
	AutoReconnect bool   `json:"auto_reconnect"`
	DebugMode     bool   `json:"debug_mode"`
}

TODO make default conf

type KLine

type KLine struct {
	Start     int64   `json:"start"` // 1539918000
	End       int64   `json:"end"`   // 1539918000
	Open      float64 `json:"open,string"`
	High      float64 `json:"high,string"`
	Low       float64 `json:"low,string"`
	Close     float64 `json:"close,string"`
	Volume    float64 `json:"volume,string"`
	Turnover  float64 `json:"turnover,string"` // 0.0013844
	Interval  string  `json:"interval"`        // 1m
	Confirm   bool    `json:"confirm"`
	Timestamp int64   `json:"timestamp"`
}

Jump to

Keyboard shortcuts

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