-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstruments.go
71 lines (53 loc) · 1.74 KB
/
instruments.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
package tasty
import (
"fmt"
"net/http"
)
// Retrieve all quantity decimal precisions.
func (c *Client) GetQuantityDecimalPrecisions() ([]QuantityDecimalPrecision, *http.Response, error) {
path := "/instruments/quantity-decimal-precisions"
type instrumentResponse struct {
Data struct {
QuantityDecimalPrecisions []QuantityDecimalPrecision `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return []QuantityDecimalPrecision{}, resp, err
}
return instrumentRes.Data.QuantityDecimalPrecisions, resp, nil
}
// Returns a set of warrant definitions that can be filtered by parameters.
func (c *Client) GetWarrants(symbols []string) ([]Warrant, *http.Response, error) {
path := "/instruments/warrants"
type instrumentResponse struct {
Data struct {
Warrants []Warrant `json:"items"`
} `json:"data"`
}
type symbolsQuery struct {
// Symbols is the list of symbols
Symbols []string `url:"symbol[]"`
}
query := symbolsQuery{Symbols: symbols}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, query, nil, instrumentRes)
if err != nil {
return []Warrant{}, resp, err
}
return instrumentRes.Data.Warrants, resp, nil
}
// Returns a single warrant definition for the provided symbol.
func (c *Client) GetWarrant(symbol string) (Warrant, *http.Response, error) {
path := fmt.Sprintf("/instruments/warrants/%s", symbol)
type instrumentResponse struct {
Warrant Warrant `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return Warrant{}, resp, err
}
return instrumentRes.Warrant, resp, nil
}