/
notify_book_ticker.go
60 lines (52 loc) · 1.24 KB
/
notify_book_ticker.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
58
59
60
package swap
import (
"fmt"
"strings"
"github.com/tidwall/gjson"
)
type (
BookTickerChannel struct {
symbol string
}
BookTickerNotify struct {
Event string `json:"e"`
UpdateID int64 `json:"u"`
PushTime int64 `json:"E"`
MatchTime int64 `json:"T"`
Symbol string `json:"s"`
Bid1Price string `json:"b"`
Bid1Amount string `json:"B"`
Ask1Price string `json:"a"`
Ask1Amount string `json:"A"`
}
)
func NewBookTickerChannel(sym string) *BookTickerChannel {
return &BookTickerChannel{
symbol: strings.ToLower(sym),
}
}
func (btc *BookTickerChannel) String() string {
return fmt.Sprintf("%s@bookTicker", btc.symbol)
}
func ParseBookTickerNotify(g *gjson.Result) *BookTickerNotify {
event := g.Get("e").String()
UpdateID := g.Get("u").Int()
pushTime := g.Get("E").Int()
matchTime := g.Get("T").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()
return &BookTickerNotify{
Event: event,
UpdateID: UpdateID,
PushTime: pushTime,
MatchTime: matchTime,
Symbol: symbol,
Bid1Price: bid1Price,
Bid1Amount: bid1Amount,
Ask1Price: ask1Price,
Ask1Amount: ask1Amount,
}
}