-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathkline_service.go
More file actions
96 lines (76 loc) · 1.71 KB
/
Copy pathkline_service.go
File metadata and controls
96 lines (76 loc) · 1.71 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package bingx
import (
"context"
"encoding/json"
"net/http"
)
type GetKlinesService struct {
c *Client
symbol string
interval Interval
startTime int64
endTime int64
limit int64
}
// Define Kline model
type Kline struct {
Open string `json:"open"`
Close string `json:"close"`
High string `json:"hign"`
Low string `json:"low"`
Volume string `json:"volume"`
Time int64 `json:"time"`
}
func (s *GetKlinesService) Symbol(symbol string) *GetKlinesService {
s.symbol = symbol
return s
}
func (s *GetKlinesService) Interval(interval Interval) *GetKlinesService {
s.interval = interval
return s
}
func (s *GetKlinesService) StartTime(startTime int64) *GetKlinesService {
s.startTime = startTime
return s
}
func (s *GetKlinesService) EndTime(endTime int64) *GetKlinesService {
s.endTime = endTime
return s
}
func (s *GetKlinesService) Limit(limit int64) *GetKlinesService {
s.limit = limit
return s
}
func (s *GetKlinesService) Do(ctx context.Context, opts ...RequestOption) (res []*Kline, err error) {
r := &request{method: http.MethodGet, endpoint: "/openApi/swap/v3/quote/klines"}
if s.symbol != "" {
r.addParam("symbol", s.symbol)
}
if s.interval != "" {
r.addParam("interval", s.interval)
}
if s.startTime != 0 {
r.addParam("startTime", s.startTime)
}
if s.endTime != 0 {
r.addParam("endTime", s.endTime)
}
if s.limit != 0 {
r.addParam("limit", s.limit)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
resp := new(struct {
Code int `json:"code"`
Msg string `json:"msg"`
Data []*Kline `json:"data"`
})
err = json.Unmarshal(data, &resp)
if err != nil {
return nil, err
}
res = resp.Data
return res, nil
}