diff --git a/cmd/root.go b/cmd/root.go index 2936bd1..b649eeb 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,13 +14,14 @@ import ( ) var ( + Version string = "v3.1.4" configPath string dep c.Dependencies ctx c.Context options cli.Options err error rootCmd = &cobra.Command{ - Version: "v3.1.3", + Version: Version, Use: "ticker", Short: "Terminal stock ticker and stock gain/loss tracker", Args: cli.Validate(&ctx, &options, &err), diff --git a/internal/position/position.go b/internal/position/position.go index 68aab6b..2499a03 100644 --- a/internal/position/position.go +++ b/internal/position/position.go @@ -100,6 +100,10 @@ func GetSymbols(symbols []string, aggregatedLots map[string]AggregatedLot) []str func GetPositions(ctx c.Context, aggregatedLots map[string]AggregatedLot) func([]Quote) (map[string]Position, PositionSummary) { return func(quotes []Quote) (map[string]Position, PositionSummary) { + if len(aggregatedLots) <= 0 { + return map[string]Position{}, PositionSummary{} + } + positionsReduced := (gubrak. From(quotes). Reduce(func(acc positionAcc, quote Quote) positionAcc { diff --git a/internal/position/position_test.go b/internal/position/position_test.go index 0c5ff25..8cfaf1e 100644 --- a/internal/position/position_test.go +++ b/internal/position/position_test.go @@ -151,5 +151,26 @@ var _ = Describe("Position", func() { })) Expect(outputPositionSummary).To(Equal(expectedPositionSummary)) }) + + When("no aggregated lots are set", func() { + It("should return an empty positions and position summary", func() { + inputAggregatedLots := map[string]AggregatedLot{} + inputQuotes := []Quote{ + { + ResponseQuote: ResponseQuote{ + Symbol: "ARKW", + RegularMarketPreviousClose: 100, + }, + Price: 120.0, + Change: 20.0, + }, + } + inputCtx := c.Context{} + outputPositions, outputPositionSummary := GetPositions(inputCtx, inputAggregatedLots)(inputQuotes) + expectedPositionSummary := PositionSummary{} + Expect(outputPositions).To(Equal(map[string]Position{})) + Expect(outputPositionSummary).To(Equal(expectedPositionSummary)) + }) + }) }) })