-
Notifications
You must be signed in to change notification settings - Fork 1
/
aastocks.go
51 lines (44 loc) · 904 Bytes
/
aastocks.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
package aastocks
import (
"net/http"
"time"
)
// Quote of AAStocks data
type Quote struct {
Symbol string
Name string
Price float64
Price52WLow float64
Price52WHigh float64
Yield float64
PeRatio float64
PbRatio float64
Lots int
Eps float64
UpdateTime time.Time
client *http.Client
}
// Get quote from AAStocks with symbol
func Get(symbol string, opts ...Option) (*Quote, error) {
q := &Quote{
Symbol: symbol,
client: defaultClient(),
}
for _, opt := range opts {
opt(q)
}
return q, q.details()
}
func defaultClient() *http.Client {
t := &transport{r: http.DefaultTransport}
return &http.Client{
Transport: t,
}
}
type transport struct {
r http.RoundTripper
}
func (t *transport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Add("Referer", req.URL.String())
return t.r.RoundTrip(req)
}