/
ws_bookticker.go
57 lines (47 loc) · 1.14 KB
/
ws_bookticker.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package spot
import (
"fmt"
"strings"
"github.com/NadiaSama/ccexgo/exchange"
"github.com/tidwall/gjson"
)
type (
// BookTickerNotify binance spot bookticker notify
BookTickerNotify struct {
UpdateID int64 `json:"u"`
Symbol string `json:"s"`
Bid1Price string `json:"b"`
Bid1Amount string `json:"B"`
Ask1Price string `json:"a"`
Ask1Amount string `json:"A"`
}
// BookTickerChannel xxx@bookTicker channel
BookTickerChannel struct {
symbol string
}
)
func NewTickerChannel(symbol string) exchange.Channel {
return &BookTickerChannel{
symbol: strings.ToLower(symbol),
}
}
func (tc *BookTickerChannel) String() string {
return fmt.Sprintf("%s@bookTicker", tc.symbol)
}
func ParseBookTickerNotify(g *gjson.Result) *BookTickerNotify {
updateID := g.Get("u").Int()
symbol := g.Get("s").String()
bid1Price := g.Get("b").String()
bid1Amount := g.Get("B").String()
ask1Price := g.Get("a").String()
ask1Amount := g.Get("A").String()
tn := &BookTickerNotify{
UpdateID: updateID,
Symbol: symbol,
Bid1Price: bid1Price,
Bid1Amount: bid1Amount,
Ask1Price: ask1Price,
Ask1Amount: ask1Amount,
}
return tn
}