Skip to content

Commit

Permalink
fix: total change percent miscalculation
Browse files Browse the repository at this point in the history
  • Loading branch information
achannarasappa committed Mar 7, 2021
1 parent 005b930 commit 254cb01
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/position/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,14 @@ func GetPositions(ctx c.Context, aggregatedLots map[string]AggregatedLot) func([

positionsReduced := getPositionsReduced(ctx, aggregatedLots, quotes)

change := positionsReduced.positionSummaryBase.value - positionsReduced.positionSummaryBase.cost

positionSummary := PositionSummary{
Value: positionsReduced.positionSummaryBase.value,
Cost: positionsReduced.positionSummaryBase.cost,
Change: positionsReduced.positionSummaryBase.value - positionsReduced.positionSummaryBase.cost,
DayChange: positionsReduced.positionSummaryBase.dayChange,
ChangePercent: (positionsReduced.positionSummaryBase.value / positionsReduced.positionSummaryBase.cost) * 100,
ChangePercent: (change / positionsReduced.positionSummaryBase.cost) * 100,
DayChangePercent: (positionsReduced.positionSummaryBase.dayChange / positionsReduced.positionSummaryBase.value) * 100,
}

Expand Down
2 changes: 1 addition & 1 deletion internal/position/position_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ var _ = Describe("Position", func() {
Cost: 4000,
Change: 1450,
DayChange: 625,
ChangePercent: 136.25,
ChangePercent: 36.25,
DayChangePercent: 11.46788990825688,
}
Expect(outputPositions["ARKW"]).To(Equal(Position{
Expand Down

0 comments on commit 254cb01

Please sign in to comment.