forked from adshao/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
premium_index_kline_service.go
92 lines (84 loc) · 2.17 KB
/
premium_index_kline_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package futures
import (
"context"
"fmt"
"net/http"
)
// PremiumIndexKlinesService list klines
type PremiumIndexKlinesService struct {
c *Client
symbol string
interval string
limit *int
startTime *int64
endTime *int64
}
// Symbol sets symbol
func (piks *PremiumIndexKlinesService) Symbol(symbol string) *PremiumIndexKlinesService {
piks.symbol = symbol
return piks
}
// Interval set interval
func (piks *PremiumIndexKlinesService) Interval(interval string) *PremiumIndexKlinesService {
piks.interval = interval
return piks
}
// Limit set limit
func (piks *PremiumIndexKlinesService) Limit(limit int) *PremiumIndexKlinesService {
piks.limit = &limit
return piks
}
// StartTime set startTime
func (piks *PremiumIndexKlinesService) StartTime(startTime int64) *PremiumIndexKlinesService {
piks.startTime = &startTime
return piks
}
// EndTime set endTime
func (piks *PremiumIndexKlinesService) EndTime(endTime int64) *PremiumIndexKlinesService {
piks.endTime = &endTime
return piks
}
// Do send request
func (piks *PremiumIndexKlinesService) Do(ctx context.Context, opts ...RequestOption) (res []*Kline, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/fapi/v1/premiumIndexKlines",
}
r.setParam("symbol", piks.symbol)
r.setParam("interval", piks.interval)
if piks.limit != nil {
r.setParam("limit", *piks.limit)
}
if piks.startTime != nil {
r.setParam("startTime", *piks.startTime)
}
if piks.endTime != nil {
r.setParam("endTime", *piks.endTime)
}
data, _, err := piks.c.callAPI(ctx, r, opts...)
if err != nil {
return []*Kline{}, err
}
j, err := newJSON(data)
if err != nil {
return []*Kline{}, err
}
num := len(j.MustArray())
res = make([]*Kline, num)
for i := 0; i < num; i++ {
item := j.GetIndex(i)
if len(item.MustArray()) < 11 {
err = fmt.Errorf("invalid kline response")
return []*Kline{}, err
}
res[i] = &Kline{
OpenTime: item.GetIndex(0).MustInt64(),
Open: item.GetIndex(1).MustString(),
High: item.GetIndex(2).MustString(),
Low: item.GetIndex(3).MustString(),
Close: item.GetIndex(4).MustString(),
CloseTime: item.GetIndex(6).MustInt64(),
}
}
return res, nil
}