forked from ccxt/go-binance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunding_rate_history.go
82 lines (73 loc) · 1.86 KB
/
funding_rate_history.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
package futures
import (
"context"
"encoding/json"
"net/http"
"github.com/adshao/go-binance/v2/common"
)
// FundingRateHistoryService gets funding rate history
type FundingRateHistoryService struct {
c *Client
symbol *string
startTime *int64
endTime *int64
limit *int
}
// Symbol set symbol
func (s *FundingRateHistoryService) Symbol(symbol string) *FundingRateHistoryService {
s.symbol = &symbol
return s
}
// StartTime set startTime
func (s *FundingRateHistoryService) StartTime(startTime int64) *FundingRateHistoryService {
s.startTime = &startTime
return s
}
// EndTime set startTime
func (s *FundingRateHistoryService) EndTime(endTime int64) *FundingRateHistoryService {
s.endTime = &endTime
return s
}
// Limit set limit
func (s *FundingRateHistoryService) Limit(limit int) *FundingRateHistoryService {
s.limit = &limit
return s
}
// Do send request
func (s *FundingRateHistoryService) Do(ctx context.Context, opts ...RequestOption) (res []*FundingRateHistory, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/fapi/v1/fundingRate",
secType: secTypeNone,
}
if s.symbol != nil {
r.setParam("symbol", *s.symbol)
}
if s.startTime != nil {
r.setParam("startTime", *s.startTime)
}
if s.endTime != nil {
r.setParam("endTime", *s.endTime)
}
if s.limit != nil {
r.setParam("limit", *s.limit)
}
data, _, err := s.c.callAPI(ctx, r, opts...)
data = common.ToJSONList(data)
if err != nil {
return []*FundingRateHistory{}, err
}
res = make([]*FundingRateHistory, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return []*FundingRateHistory{}, err
}
return res, nil
}
// FundingRateHistory defines funding rate history data
type FundingRateHistory struct {
Symbol string `json:"symbol"`
FundingTime int64 `json:"fundingTime"`
FundingRate string `json:"fundingRate"`
MarkPrice string `json:"markPrice"`
}