forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 1
/
user_stream_service.go
77 lines (68 loc) · 1.76 KB
/
user_stream_service.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package binance
import (
"context"
)
// StartUserStreamService create listen key for user stream service
type StartUserStreamService struct {
c *Client
}
// Do send request
func (s *StartUserStreamService) Do(ctx context.Context, opts ...RequestOption) (listenKey string, err error) {
r := &request{
method: "POST",
endpoint: "/api/v3/userDataStream",
secType: secTypeAPIKey,
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return "", err
}
j, err := newJSON(data)
if err != nil {
return "", err
}
listenKey = j.Get("listenKey").MustString()
return listenKey, nil
}
// KeepaliveUserStreamService update listen key
type KeepaliveUserStreamService struct {
c *Client
listenKey string
}
// ListenKey set listen key
func (s *KeepaliveUserStreamService) ListenKey(listenKey string) *KeepaliveUserStreamService {
s.listenKey = listenKey
return s
}
// Do send request
func (s *KeepaliveUserStreamService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "PUT",
endpoint: "/api/v3/userDataStream",
secType: secTypeAPIKey,
}
r.setFormParam("listenKey", s.listenKey)
_, err = s.c.callAPI(ctx, r, opts...)
return err
}
// CloseUserStreamService delete listen key
type CloseUserStreamService struct {
c *Client
listenKey string
}
// ListenKey set listen key
func (s *CloseUserStreamService) ListenKey(listenKey string) *CloseUserStreamService {
s.listenKey = listenKey
return s
}
// Do send request
func (s *CloseUserStreamService) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: "DELETE",
endpoint: "/api/v3/userDataStream",
secType: secTypeAPIKey,
}
r.setFormParam("listenKey", s.listenKey)
_, err = s.c.callAPI(ctx, r, opts...)
return err
}