forked from Gerifield/gobitpanda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpriceticks.go
45 lines (36 loc) · 1.01 KB
/
priceticks.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
package gobitpanda
import (
"errors"
"fmt"
"time"
)
// GetPriceTicksByCode gets price ticks for specific market for interval of maximum of 4 hours. Sorted by latest first
func (c *Client) GetPriceTicksByCode(instrumentCode string, from time.Time, to time.Time) (*[]PriceTick, error) {
priceTicks := &[]PriceTick{}
if instrumentCode == "" {
return nil, errors.New("instrumentCode can not be empty")
}
var params string
if !from.IsZero() {
if params == "" {
params += "?from=" + from.UTC().Format(time.RFC3339)
} else {
params += "&from=" + from.UTC().Format(time.RFC3339)
}
}
if !to.IsZero() {
if params == "" {
params += "?to=" + to.UTC().Format(time.RFC3339)
} else {
params += "&to=" + to.UTC().Format(time.RFC3339)
}
}
req, err := c.NewRequest("GET", fmt.Sprintf("%s%s%s%s", c.APIBase, "/v1/price-ticks/", instrumentCode, params), nil)
if err != nil {
return priceTicks, err
}
if err = c.Send(req, priceTicks); err != nil {
return priceTicks, err
}
return priceTicks, nil
}