forked from ccxt/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsocket_orderbook.go
31 lines (26 loc) · 1013 Bytes
/
websocket_orderbook.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
package binance
import (
"fmt"
"strings"
"github.com/shopspring/decimal"
)
// WsPartialBookDepthHandler handle websocket depth event
type WsPartialBookDepthHandler func(event *WsPartialBookDepthEvent)
// WsPartialBookDepthServe serve websocket depth handler with a symbol.
// Valid <levels> are 5, 10, or 20.
func WsPartialBookDepthServe(symbol string, handler WsPartialBookDepthHandler, levels int, closed *bool) (done chan interface{}, err error) {
endpoint := fmt.Sprintf("%s/%s@depth%d", baseURL, strings.ToLower(symbol), levels)
cfg := newWsConfig(endpoint)
wsHandler := func(message []byte) {
handler(parseWsPartialBookDepthEvent(message, levels))
}
done = make(chan interface{}, 2)
err = wsServeMax(cfg, wsHandler, done, closed)
return
}
// WsPartialBookDepthEvent define websocket depth event
type WsPartialBookDepthEvent struct {
LastUpdateId int64 `json:"lastUpdateId"`
Bids [][2]decimal.Decimal `json:"bids"`
Asks [][2]decimal.Decimal `json:"asks"`
}