Skip to content
This repository was archived by the owner on Dec 16, 2025. It is now read-only.

Commit b078dbd

Browse files
committed
Use the highest-rank coin to calculate PortfolioSlice
1 parent a34417a commit b078dbd

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

cointop/portfolio.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,14 @@ OUTER:
537537
continue
538538
}
539539
// check not already found
540+
updateSlice := -1
540541
for j := range sliced {
541542
if coin.Symbol == sliced[j].Symbol {
542-
continue OUTER
543+
if coin.Rank >= sliced[j].Rank {
544+
continue OUTER // skip updates from lower-ranked coins
545+
}
546+
updateSlice = j // update this later
547+
break
543548
}
544549
}
545550

@@ -551,7 +556,12 @@ OUTER:
551556
}
552557
balance, _ = strconv.ParseFloat(balancestr, 64)
553558
coin.Balance = balance
554-
sliced = append(sliced, coin)
559+
if updateSlice == -1 {
560+
sliced = append(sliced, coin)
561+
} else {
562+
sliced[updateSlice] = coin
563+
}
564+
555565
}
556566

557567
sort.Slice(sliced, func(i, j int) bool {

0 commit comments

Comments
 (0)