ericm / stonks

Stonks is a terminal based stock visualizer and tracker that displays realtime stocks in graph format in a terminal. See how fast your stonks will crash.
https://stonks.icu
GNU General Public License v3.0
548 stars 35 forks source link

panic: decimal division by 0 #11

Closed harleypig closed 4 years ago

harleypig commented 4 years ago
$ stonks -s FSELX
$ stonks
FSELX:
panic: decimal division by 0

goroutine 1 [running]:
github.com/shopspring/decimal.Decimal.QuoRem(0xc0003c7280, 0xc0fffffff1, 0xc0003c7260, 0xfffffff1, 0x10, 0x0, 0x0, 0xc000484b58, 0x1)
        /home/harleypig/go/pkg/mod/github.com/shopspring/decimal@v1.2.0/decimal.go:500 +0x375
github.com/shopspring/decimal.Decimal.DivRound(0xc0003c7280, 0xc0fffffff1, 0xc0003c7260, 0xfffffff1, 0xc000000010, 0xc0fffffff1, 0x282)
        /home/harleypig/go/pkg/mod/github.com/shopspring/decimal@v1.2.0/decimal.go:542 +0x6e
github.com/shopspring/decimal.Decimal.Div(...)
        /home/harleypig/go/pkg/mod/github.com/shopspring/decimal@v1.2.0/decimal.go:487
github.com/ericm/stonks/graph.GenerateGraph(0xc000382000, 0x50, 0xc, 0x0, 0x0, 0x0, 0xc000382000, 0x0)
        /tmp/trizen-harleypig/stonks/src/stonks/graph/graph.go:97 +0xc28
main.main.func1(0xc00015cb00, 0xd0e4f8, 0x0, 0x0)
        /tmp/trizen-harleypig/stonks/src/stonks/main.go:149 +0x906
github.com/spf13/cobra.(*Command).execute(0xc00015cb00, 0xc0001181b0, 0x0, 0x0, 0xc00015cb00, 0xc0001181b0)
        /home/harleypig/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:846 +0x29d
github.com/spf13/cobra.(*Command).ExecuteC(0xc00015cb00, 0xc000130be0, 0x911f80, 0x7)
        /home/harleypig/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
        /home/harleypig/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
main.main()
        /tmp/trizen-harleypig/stonks/src/stonks/main.go:177 +0x70b
ericm commented 4 years ago

It seems the data it's getting from the API is just one bar. Strange

ericm commented 4 years ago

image adding a condition to change to month if only one result is returned seems to fix it

ericm commented 4 years ago

Could you pull master and see if the fix works?

harleypig commented 4 years ago

That works now. Thanks.