-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption_chains.go
120 lines (91 loc) · 3.58 KB
/
option_chains.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
package tasty
import (
"fmt"
"net/http"
"net/url"
)
// Returns a futures option chain given a futures product code, i.e. ES.
func (c *Client) GetFuturesOptionChains(productCode string) ([]FutureOption, *http.Response, error) {
path := fmt.Sprintf("/futures-option-chains/%s", productCode)
type instrumentResponse struct {
Data struct {
FutureOptions []FutureOption `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return []FutureOption{}, resp, err
}
return instrumentRes.Data.FutureOptions, resp, nil
}
// Returns a futures option chain given a futures product code in a nested form to minimize
// redundant processing.
func (c *Client) GetNestedFuturesOptionChains(productCode string) (NestedFuturesOptionChains, *http.Response, error) {
path := fmt.Sprintf("/futures-option-chains/%s/nested", productCode)
type instrumentResponse struct {
Chains NestedFuturesOptionChains `json:"data"`
}
instrumentRes := new(instrumentResponse)
resp, err := c.request(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return NestedFuturesOptionChains{}, resp, err
}
return instrumentRes.Chains, resp, nil
}
// Returns an option chain given an underlying symbol, i.e. AAPL.
func (c *Client) GetEquityOptionChains(symbol string) ([]EquityOption, *http.Response, error) {
// url escape required for instances where "/" exists in symbol i.e. BRK/B
symbol = url.PathEscape(symbol)
path := fmt.Sprintf("/option-chains/%s", symbol)
type instrumentResponse struct {
Data struct {
EquityOptions []EquityOption `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
// customRequest required for instances where "/" exists in symbol i.e. BRK/B
resp, err := c.customRequest(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return []EquityOption{}, resp, err
}
return instrumentRes.Data.EquityOptions, resp, nil
}
// Returns an option chain given an underlying symbol,
// i.e. AAPL in a nested form to minimize redundant processing.
func (c *Client) GetNestedEquityOptionChains(symbol string) ([]NestedOptionChains, *http.Response, error) {
// url escape required for instances where "/" exists in symbol i.e. BRK/B
symbol = url.PathEscape(symbol)
path := fmt.Sprintf("/option-chains/%s/nested", symbol)
type instrumentResponse struct {
Data struct {
Chains []NestedOptionChains `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
// customRequest required for instances where "/" exists in symbol i.e. BRK/B
resp, err := c.customRequest(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return []NestedOptionChains{}, resp, err
}
return instrumentRes.Data.Chains, resp, nil
}
// Returns an option chain given an underlying symbol,
// i.e. AAPL in a compact form to minimize content size.
func (c *Client) GetCompactEquityOptionChains(symbol string) ([]CompactOptionChains, *http.Response, error) {
// url escape required for instances where "/" exists in symbol i.e. BRK/B
symbol = url.PathEscape(symbol)
path := fmt.Sprintf("/option-chains/%s/compact", symbol)
type instrumentResponse struct {
Data struct {
Chains []CompactOptionChains `json:"items"`
} `json:"data"`
}
instrumentRes := new(instrumentResponse)
// customRequest required for instances where "/" exists in symbol i.e. BRK/B
resp, err := c.customRequest(http.MethodGet, path, nil, nil, instrumentRes)
if err != nil {
return []CompactOptionChains{}, resp, err
}
return instrumentRes.Data.Chains, resp, nil
}