- This project guideline from binance spot
- Important
this project not released
go get github.com/NattapornTee22816/binance-connector-golang
document binance general info
import "github.com/NattapornTee22816/binance-connector-golang/spot"
Testnet
client := spot.NewTestnetAPI(<api-key>, <api-secret>)
Basic
client := spot.NewBasicAPI(<api-key>, <api-secret>)
Advance
client := spot.NewAPI( <api-key>, <api-secret>, url, timeout, // 0 is infinite proxies, logLevel, ctx, )
document Binance Websocket
- websocket auto reconnect when any error
- can use multiple handler on subscription
New Websocket
ws, err := websocket.NewWsStream() if err != nil { panic(err) }
Example for kline stream
create stream type
kline stream is<symbol>@kline_<interval>
streams := make([]string, 0) stream, _ := NewKlineStreamType(symbol, interval) streams = append(streams, stream)
Subscribe streams
subscription must have handler for do something
can have multiple handler on subscription
on next subscribe can not send handlerExample handler
func handlerLogData(steam string, data *KlineStream, err error) { // stream is ```<symbol>@kline_<interval>``` do something }
func handlerOtherProcess(steam string, data *KlineStream, err error) { // stream is ```<symbol>@kline_<interval>``` do something }
err = ws.SubscribeKlineStreams(streams, handlerLogData, handlerOtherProcess) if err != nil { panic(err) }
on receive stream data will call handler step by step
Example from above:
has 2 handler
1.call handlerLogData
2.call handlerOtherProcessNote:
when has error and cannot process next handler, Please set that error to err for stop next handler# Stop Websocket
ws.Shutdown()