-
Notifications
You must be signed in to change notification settings - Fork 3
/
data_apis.go
93 lines (79 loc) · 1.71 KB
/
data_apis.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
package goiex
import (
"net/http"
"net/url"
"time"
)
// DataAPI struct to interface with DataAPI endpoints
type DataAPI struct {
iex
}
// DataPoint struct
type DataPoint struct {
Key string `json:"key"`
Weight int `json:"weight"`
Description string `json:"description"`
LastUpdated time.Time `json:"lastUpdated"`
}
// NewDataAPI return new DataAPI
func NewDataAPI(
token, version string,
base *url.URL,
httpClient *http.Client,
options ...IEXOption,
) *DataAPI {
apiurl, err := url.Parse("")
if err != nil {
panic(err)
}
da := &DataAPI{
iex: iex{
token: token,
version: version,
url: base,
apiurl: apiurl,
client: httpClient,
},
}
for _, option := range options {
err := option(&da.iex)
if err != nil {
return nil
}
}
return da
}
// Token return token string
func (d *DataAPI) Token() string {
return d.token
}
// Version return version string
func (d *DataAPI) Version() string {
return d.version
}
// URL return URL base
func (d *DataAPI) URL() *url.URL {
return d.url
}
// APIURL return APIURL
func (d *DataAPI) APIURL() *url.URL {
return d.apiurl
}
// Client return HTTP client
func (d *DataAPI) Client() *http.Client {
return d.client
}
// Retry return Retry struct that implements Retryer
func (d *DataAPI) Retry() *Retry {
return d.iex.Retry
}
// DataPoints GET /data-points/{symbol}
func (d *DataAPI) DataPoints(symbol string) (datapoints []*DataPoint, err error) {
err = get(d, &datapoints, "data-points/"+symbol, nil)
return
}
// DataPoint GET /data-points/{symbol}/{datapoint}
func (d *DataAPI) DataPoint(symbol, datapoint string) (ifc interface{}, err error) {
err = get(d, &ifc, "data-points/"+symbol+"/"+datapoint, nil)
return
}