Skip to content

Commit

Permalink
Added --extra which gets pre and post data as well
Browse files Browse the repository at this point in the history
  • Loading branch information
ericm committed May 24, 2020
1 parent e53d543 commit f266927
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions api/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion graph/graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
ytd *bool
week *bool
version *bool
extra *bool
theme *string
days *int

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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()
}
Expand Down

0 comments on commit f266927

Please sign in to comment.