forked from go-numb/go-ftx
/
candles.go
53 lines (43 loc) · 1.41 KB
/
candles.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
package markets
import (
"fmt"
"net/http"
"time"
"github.com/google/go-querystring/query"
)
// query
// ?resolution={resolution}&limit={limit}&start_time={start_time}&end_time={end_time}
type RequestForCandles struct {
ProductCode string `url:"-"`
// Resolution is sec length, window length in seconds. options: 15, 60(1m), 300(5m), 900(15m), 3600(60m), 14400(4h), 86400(1D)
Resolution int `url:"resolution"`
Limit int `url:"limit,omitempty"`
Start int64 `url:"start_time,omitempty"`
End int64 `url:"end_time,omitempty"`
}
type ResponseForCandles []Candle
type Candle struct {
Close float64 `json:"close"`
High float64 `json:"high"`
Low float64 `json:"low"`
Open float64 `json:"open"`
Volume float64 `json:"volume"`
StartTime time.Time `json:"startTime"`
}
func (req *RequestForCandles) Path() string {
return fmt.Sprintf("/markets/%s/candles", req.ProductCode)
}
func (req *RequestForCandles) Method() string {
return http.MethodGet
}
func (req *RequestForCandles) Query() string {
values, _ := query.Values(req)
return values.Encode()
}
func (req *RequestForCandles) Payload() []byte {
return nil
}
// Sort by timestamp
func (a ResponseForCandles) Len() int { return len(a) }
func (a ResponseForCandles) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ResponseForCandles) Less(i, j int) bool { return a[i].StartTime.Before( a[j].StartTime)}