-
Notifications
You must be signed in to change notification settings - Fork 34
/
symbolBookTicker.go
38 lines (35 loc) · 1.3 KB
/
symbolBookTicker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"fmt"
"github.com/dirname/binance/futures/usd/websocket/market"
logger "github.com/dirname/binance/logging"
"github.com/dirname/binance/model"
"time"
)
func main() {
client := futuresusdt.NewUSDFuturesSymbolBookTickerWebsocketClient("btcusdt@bookTicker")
client.SetReadTimerInterval(5 * time.Second)
client.SetReconnectWaitTime(5 * time.Second)
client.SetHandler(func() {
client.Subscribe(123, "btcusdt@bookTicker", "ltcusdt@bookTicker")
client.SetCombined(true, 123)
}, func(response interface{}) {
switch response.(type) {
case futuresusdt.SymbolBookTickerResponse:
logger.Info("SymbolBookTicker: %v", response.(futuresusdt.SymbolBookTickerResponse))
case futuresusdt.SymbolBookTickerCombinedResponse:
logger.Info("SymbolBookTickerCombinedResponse: %v", response.(futuresusdt.SymbolBookTickerCombinedResponse))
case model.WebsocketCommonResponse:
logger.Info("Websocket Response: %v", response.(model.WebsocketCommonResponse))
case model.WebsocketErrorResponse:
logger.Info("Websocket Error Response: %v", response.(model.WebsocketErrorResponse))
default:
logger.Info("Unknown Response: %v", response)
}
})
client.Connect(true)
fmt.Scanln()
client.Unsubscribe(123, "btcusdt@bookTicker", "ltcusdt@bookTicker")
client.Close()
logger.Info("Client closed")
}