-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfutures.go
160 lines (119 loc) · 4.36 KB
/
futures.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package tasty
import (
"fmt"
"net/http"
)
// Returns a set of outright futures given an array of one or more symbols.
func (c *Client) GetFutures(query FuturesQuery) ([]Future, *http.Response, error) {
path := "/instruments/futures"
type instrumentResponse struct {
Data struct {
Futures []Future `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, query, nil, instrumentRes)
if err != nil {
return []Future{}, resp, err
}
return instrumentRes.Data.Futures, resp, nil
}
// Returns an outright future given a symbol.
func (c *Client) GetFuture(symbol string) (Future, *http.Response, error) {
path := fmt.Sprintf("/instruments/futures/%s", symbol)
type instrumentResponse struct {
Future Future `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return Future{}, resp, err
}
return instrumentRes.Future, resp, nil
}
// Returns metadata for all supported future option products.
func (c *Client) GetFutureOptionProducts() ([]FutureOptionProduct, *http.Response, error) {
path := "/instruments/future-option-products"
type instrumentResponse struct {
Data struct {
FutureOptionProducts []FutureOptionProduct `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return []FutureOptionProduct{}, resp, err
}
return instrumentRes.Data.FutureOptionProducts, resp, nil
}
// Get a future option product by exchange and root symbol.
func (c *Client) GetFutureOptionProduct(exchange, rootSymbol string) (FutureOptionProduct, *http.Response, error) {
path := fmt.Sprintf("/instruments/future-option-products/%s/%s", exchange, rootSymbol)
type instrumentResponse struct {
FutureOptionProduct FutureOptionProduct `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return FutureOptionProduct{}, resp, err
}
return instrumentRes.FutureOptionProduct, resp, nil
}
// Returns a set of future option(s) given an array of one or more symbols.
// Uses TW symbology: [./ESZ9 EW4U9 190927P2975].
func (c *Client) GetFutureOptions(query FutureOptionsQuery) ([]FutureOption, *http.Response, error) {
path := "/instruments/future-options"
type instrumentResponse struct {
Data struct {
FutureOptions []FutureOption `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, query, nil, instrumentRes)
if err != nil {
return []FutureOption{}, resp, err
}
return instrumentRes.Data.FutureOptions, resp, nil
}
// Returns a future option given a symbol. Uses TW symbology: ./ESZ9 EW4U9 190927P2975.
func (c *Client) GetFutureOption(symbol string) (FutureOption, *http.Response, error) {
path := fmt.Sprintf("/instruments/future-options/%s", symbol)
type instrumentResponse struct {
FutureOption FutureOption `json:"data"`
Context string `json:"context"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return FutureOption{}, resp, err
}
return instrumentRes.FutureOption, resp, nil
}
// Returns metadata for all supported futures products.
func (c *Client) GetFutureProducts() ([]FutureProduct, *http.Response, error) {
path := "/instruments/future-products"
type instrumentResponse struct {
Data struct {
FutureProducts []FutureProduct `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return []FutureProduct{}, resp, err
}
return instrumentRes.Data.FutureProducts, resp, nil
}
// Get future product from exchange and product code.
func (c *Client) GetFutureProduct(exchange Exchange, productCode string) (FutureProduct, *http.Response, error) {
path := fmt.Sprintf("/instruments/future-products/%s/%s", exchange, productCode)
type instrumentResponse struct {
FutureProduct FutureProduct `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return FutureProduct{}, resp, err
}
return instrumentRes.FutureProduct, resp, nil
}