/
user_stream_service.go
67 lines (57 loc) · 1.69 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
package delivery
import (
"context"
"github.com/crypto-zero/go-binance/v2/common"
)
// StartUserStreamService create listen key for user stream service
type StartUserStreamService struct {
c *Client
}
// Do send request
func (s *StartUserStreamService) Do(ctx context.Context, opts ...common.RequestOption) (listenKey string, err error) {
r := common.NewPostRequestSigned("/dapi/v1/listenKey")
data, err := s.c.CallAPIBytes(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 ...common.RequestOption) (err error) {
r := common.NewPutRequestSigned("/dapi/v1/listenKey")
r.SetForm("listenKey", s.listenKey)
_, err = s.c.CallAPIBytes(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 ...common.RequestOption) (err error) {
r := common.NewDeleteRequestSigned("/dapi/v1/listenKey")
r.SetForm("listenKey", s.listenKey)
_, err = s.c.CallAPIBytes(ctx, r, opts...)
return err
}