Use the highest-rank coin to calculate PortfolioSlice

pull/143/head
Simon Roberts 3 years ago
parent a34417ad61
commit b078dbd2f6

@ -537,9 +537,14 @@ OUTER:
continue continue
} }
// check not already found // check not already found
updateSlice := -1
for j := range sliced { for j := range sliced {
if coin.Symbol == sliced[j].Symbol { if coin.Symbol == sliced[j].Symbol {
continue OUTER if coin.Rank >= sliced[j].Rank {
continue OUTER // skip updates from lower-ranked coins
}
updateSlice = j // update this later
break
} }
} }
@ -551,7 +556,12 @@ OUTER:
} }
balance, _ = strconv.ParseFloat(balancestr, 64) balance, _ = strconv.ParseFloat(balancestr, 64)
coin.Balance = balance coin.Balance = balance
sliced = append(sliced, coin) if updateSlice == -1 {
sliced = append(sliced, coin)
} else {
sliced[updateSlice] = coin
}
} }
sort.Slice(sliced, func(i, j int) bool { sort.Slice(sliced, func(i, j int) bool {

Loading…
Cancel
Save