-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (43 loc) · 938 Bytes
/
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
package main
import (
"flag"
"fmt"
"os"
"time"
"github.com/sklarsa/yahoofin"
)
func main() {
tickerPtr := flag.String("ticker", "", "Ticker to pull prices for")
startDatePtr := flag.String("startDate", "", "Start date [YYYY-MM-DD]")
endDatePtr := flag.String("endDate", "", "End date [YYYY-MM-DD]")
flag.Parse()
if *tickerPtr == "" {
fmt.Println("Must provide a ticker")
flag.Usage()
os.Exit(1)
}
const dateFmt = "2006-01-02"
startDate, err := time.Parse(dateFmt, *startDatePtr)
if err != nil {
fmt.Println(err)
flag.Usage()
os.Exit(1)
}
endDate, err := time.Parse(dateFmt, *endDatePtr)
if err != nil {
fmt.Println(err)
flag.Usage()
os.Exit(1)
}
client, err := yahoofin.NewClient()
if err != nil {
panic(err)
}
resp, err := client.GetSecurityDataString(*tickerPtr, startDate, endDate, yahoofin.History)
if err != nil {
fmt.Println(err)
os.Exit(1)
} else {
fmt.Println(resp)
}
}