forked from go-numb/go-ftx
/
rates.go
50 lines (38 loc) · 1.23 KB
/
rates.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
package futures
import (
"net/http"
"time"
"github.com/google/go-querystring/query"
)
type RequestForRates struct {
ProductCode string `url:"future,omitempty"`
Start int64 `url:"start_time,omitempty"`
End int64 `url:"end_time,omitempty"`
}
type ResponseForRates []Rate
type ByDate []Rate
func (a ByDate) Len() int { return len(a) }
func (a ByDate) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ByDate) Less(i, j int) bool { return a[i].Time.Before(a[j].Time) }
type Rate struct {
Future string `json:"future"`
Rate float64 `json:"rate"`
Time time.Time `json:"time"`
}
// Example : https://ftx.com/api/funding_rates?future=DEFI-PERP&start_time=1597687200&end_time=1597773600
func (req *RequestForRates) Path() string {
return "/funding_rates"
}
func (req *RequestForRates) Method() string {
return http.MethodGet
}
func (req *RequestForRates) Query() string {
value, _ := query.Values(req)
return value.Encode()
}
func (req *RequestForRates) Payload() []byte {
return nil
}
func (a ResponseForRates) Len() int { return len(a) }
func (a ResponseForRates) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ResponseForRates) Less(i, j int) bool { return a[i].Rate < a[j].Rate }