From f266927c42ba8d274ba388b7cb0de926e9ffade0 Mon Sep 17 00:00:00 2001 From: Eric Moynihan Date: Sun, 24 May 2020 16:30:49 +0100 Subject: [PATCH] Added --extra which gets pre and post data as well --- README.md | 1 + api/chart.go | 4 ++-- graph/graph.go | 2 +- main.go | 16 +++++++++++++--- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b26494c..ba193ff 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Usage: Flags: -d, --days int 24 hour period of stocks from X of days ago. + -e, --extra Include extra pre + post time. (Only works for day) -h, --help help for stonks -i, --interval string stonks -i X[m|h] (eg 15m, 5m, 1h, 1d) (default "15m") -n, --name string Optional name for a stonk save diff --git a/api/chart.go b/api/chart.go index c6beb43..10b4eaa 100644 --- a/api/chart.go +++ b/api/chart.go @@ -37,8 +37,8 @@ type Bar struct { } // GetChart returns a Chart -func GetChart(symbol string, interval datetime.Interval, start *datetime.Datetime, end *datetime.Datetime) (*Chart, error) { - q := chart.Get(&chart.Params{Symbol: symbol, Interval: interval, Start: start, End: end, IncludeExt: false}) +func GetChart(symbol string, interval datetime.Interval, start *datetime.Datetime, end *datetime.Datetime, extra bool) (*Chart, error) { + q := chart.Get(&chart.Params{Symbol: symbol, Interval: interval, Start: start, End: end, IncludeExt: extra}) if q.Count() < 7 && interval == datetime.FifteenMins { q = chart.Get(&chart.Params{Symbol: symbol, Interval: datetime.FiveMins, Start: start, End: end, IncludeExt: false}) if q.Count() < 2 { diff --git a/graph/graph.go b/graph/graph.go index 330098c..e049719 100644 --- a/graph/graph.go +++ b/graph/graph.go @@ -203,7 +203,7 @@ incFooter: for i, bar := range chart.Bars { if i%mod == 0 { format := timeFormat - if chart.End.Day != chart.Start.Day { + if chart.End.Day-chart.Start.Day > 1 { format = dayFormat } t := bar.Timestamp.Time().Format(format) diff --git a/main.go b/main.go index a50d9ec..553ebe6 100644 --- a/main.go +++ b/main.go @@ -27,6 +27,7 @@ var ( ytd *bool week *bool version *bool + extra *bool theme *string days *int @@ -80,7 +81,7 @@ func main() { if len(*save) > 0 { saveCmd := strings.ToUpper(*save) - if _, err := api.GetChart(saveCmd, datetime.FifteenMins, nil, nil); err != nil { + if _, err := api.GetChart(saveCmd, datetime.FifteenMins, nil, nil, false); err != nil { fmt.Println(err.Error()) os.Exit(1) } @@ -123,6 +124,10 @@ func main() { if len(args) == 0 { intervalCmd, start, end := parseTimeRange() + extraCmd := false + if end == nil { + extraCmd = *extra + } // Favourites favourites, ok := viper.Get("favourites").(map[string]interface{}) if !ok { @@ -141,7 +146,7 @@ func main() { for _, symbol := range keys { name := favourites[symbol].(string) fmt.Println(name + ":") - chart, err := api.GetChart(strings.ReplaceAll(strings.ToUpper(symbol), "_", "."), intervalCmd, start, end) + chart, err := api.GetChart(strings.ReplaceAll(strings.ToUpper(symbol), "_", "."), intervalCmd, start, end, extraCmd) if err != nil { fmt.Println(err.Error()) continue @@ -153,7 +158,11 @@ func main() { for _, symbol := range args { intervalCmd, start, end := parseTimeRange() - chart, err := api.GetChart(strings.ToUpper(symbol), intervalCmd, start, end) + extraCmd := false + if end == nil { + extraCmd = *extra + } + chart, err := api.GetChart(strings.ToUpper(symbol), intervalCmd, start, end, extraCmd) if err != nil { fmt.Println(err.Error()) os.Exit(1) @@ -173,6 +182,7 @@ func main() { remove = rootCmd.PersistentFlags().StringP("remove", "r", "", "Remove an item from favourites") name = rootCmd.PersistentFlags().StringP("name", "n", "", "Optional name for a stonk save") version = rootCmd.PersistentFlags().BoolP("version", "v", false, "stonks version") + extra = rootCmd.PersistentFlags().BoolP("extra", "e", false, "Include extra pre + post time. (Only works for day)") rootCmd.Execute() }