/
unsubscribe.go
48 lines (41 loc) · 1.06 KB
/
unsubscribe.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
package binance
import (
"context"
"encoding/json"
)
type UnsubscribeReq struct {
Method string `json:"method,omitempty"`
Params []interface{} `json:"params,omitempty"`
ID int64 `json:"id,omitempty"`
}
type UnsubscribeResp struct {
Result []string `json:"result,omitempty"`
ID int64 `json:"id,omitempty"`
Code int `json:"code,omitempty"`
Msg int `json:"msg,omitempty"`
}
type UnsubscribeService struct {
req SubscribeReq
C *Client
}
func (sub *UnsubscribeService) Subscribe(x string) {
sub.req.Params = append(sub.req.Params, x)
}
func (sub *UnsubscribeService) Do(ctx context.Context, ID uint) error {
sub.req.Method = "UNSUBSCRIBE"
sub.C.RpcId = sub.C.RpcId + 1
data, err := json.Marshal(sub.req)
if err != nil {
return err
}
sub.C.Send(data, sub.C.RpcId, sub)
return nil
}
func (s *UnsubscribeService) Unmarshal(data []byte) (interface{}, error) {
var ret UnsubscribeResp
if err := json.Unmarshal(data, &ret); err != nil {
return nil, err
}
delete(s.C.unpack, ret.ID)
return &BinanceBody{Body: &ret}, nil
}