Skip to content

Commit

Permalink
Allow removing all points for a chart for recently splitting stocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
btmura committed Oct 31, 2020
1 parent 08eb6e8 commit 65a19e3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/iextool/iextool.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func getAPIData(ctx context.Context, client *iex.Client, symbols []string) {
}

func clearCacheData(ctx context.Context, cache chartCache, symbols []string, token string) {
numPoints := pick("Pick how many points to clear", 10, 25, 50).(int)
numPoints := pick("Pick how many points to clear", "10", "25", "50", "All").(string)

for i := range symbols {
key := iex.ChartCacheKey{
Expand All @@ -195,11 +195,22 @@ func clearCacheData(ctx context.Context, cache chartCache, symbols []string, tok

chartPoints := val.Chart.ChartPoints
if len(chartPoints) != 0 {
trimIndex := len(chartPoints) - numPoints
if trimIndex < 0 {
trimIndex = 0
switch {
case numPoints == "All":
chartPoints = nil

default:
n, err := strconv.Atoi(numPoints)
if err != nil {
fmt.Println(err)
return
}
trimIndex := len(chartPoints) - n
if trimIndex < 0 {
trimIndex = 0
}
chartPoints = chartPoints[:trimIndex]
}
chartPoints = chartPoints[:trimIndex]
}

val = &iex.ChartCacheValue{
Expand Down

0 comments on commit 65a19e3

Please sign in to comment.