-
Notifications
You must be signed in to change notification settings - Fork 74
/
user_stream.go
78 lines (69 loc) · 1.64 KB
/
user_stream.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
78
package binance_connector
import (
"context"
"net/http"
)
// Create Listen Key
type CreateListenKey struct {
c *Client
}
// Do send request
func (s *CreateListenKey) Do(ctx context.Context, opts ...RequestOption) (listenKey string, err error) {
r := &request{
method: http.MethodPost,
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
}
// Keep Alive/Ping User Stream
type PingUserStream struct {
c *Client
listenKey string
}
// ListenKey set listen key
func (s *PingUserStream) ListenKey(listenKey string) *PingUserStream {
s.listenKey = listenKey
return s
}
// Do send request
func (s *PingUserStream) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: http.MethodPut,
endpoint: "/api/v3/userDataStream",
secType: secTypeAPIKey,
}
r.setParam("listenKey", s.listenKey)
_, err = s.c.callAPI(ctx, r, opts...)
return err
}
// CloseUserStream delete listen key
type CloseUserStream struct {
c *Client
listenKey string
}
// ListenKey set listen key
func (s *CloseUserStream) ListenKey(listenKey string) *CloseUserStream {
s.listenKey = listenKey
return s
}
// Do send request
func (s *CloseUserStream) Do(ctx context.Context, opts ...RequestOption) (err error) {
r := &request{
method: http.MethodDelete,
endpoint: "/api/v3/userDataStream",
secType: secTypeAPIKey,
}
r.setParam("listenKey", s.listenKey)
_, err = s.c.callAPI(ctx, r, opts...)
return err
}