go-bybit-api

module
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

README

go-bybit-api

Go library for using the ByBit's Websocket API

ByBit API Doc

Example
Websocket
package main

import (
	"fmt"
	"log"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/buurzx/go-bybit-api/ws"
)

func main() {
	sigCH := make(chan os.Signal, 1)
	signal.Notify(sigCH, os.Interrupt, syscall.SIGTERM)

	cfg := &ws.Configuration{
		Addr:          ws.HostPerpetualtTestnet,
		AutoReconnect: true,
		DebugMode:     false,
	}

	bbWS := ws.New(cfg)
	bbWS.Subscribe(ws.WSKLine, "1", "BTCUSDT")
	bbWS.On(ws.WSKLine, handleKLine)

	bbWS.Start()

	<-sigCH
	fmt.Println("Shutdown ...")

	bbWS.Close()
	<-time.After(time.Second * 1)
}

func handleKLine(symbol string, data ws.KLine) {
	log.Printf("handleKLine %v/%#v \n", symbol, data)
}

Directories

Path Synopsis
example
api
ws
Package recws provides websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped.
Package recws provides websocket client based on gorilla/websocket that will automatically reconnect if the connection is dropped.

Jump to

Keyboard shortcuts

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