-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (44 loc) · 1.02 KB
/
main.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
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/jaysonhurd/polygon/pkg/polygon"
"github.com/jaysonhurd/polygon/pkg/rest"
"io"
"net/http"
"os"
)
//TIP <p>To run your code, right-click the code and select <b>Run</b>.</p> <p>Alternatively, click
// the <icon src="AllIcons.Actions.Execute"/> icon in the gutter and select the <b>Run</b> menu item from here.</p>
func main() {
config, err := loadConfig()
if err != nil {
panic(err)
}
fmt.Printf("config: %+v\n", config)
client := &http.Client{
Transport: nil,
CheckRedirect: nil,
Jar: nil,
Timeout: 0,
}
rest := rest.New(client, config)
stock, err := rest.PreviousClose("AAPL")
fmt.Printf(stock)
}
func loadConfig() (c polygon.Config, err error) {
file, err := os.Open("configs/config.json")
if err != nil {
return c, err
}
data, err := io.ReadAll(file)
if err != nil {
return c, err
}
err = json.Unmarshal(data, &c)
if err != nil {
return c, errors.New("unable to unmarshal json config")
}
return c, nil
}