Skip to content

Commit

Permalink
Allow duplicate-Symbol entries in portfolio again (#222)
Browse files Browse the repository at this point in the history
* Revert PR 138 - no longer needed since PR 219 and prevents duplicate-symbol portfolio
* Rather than creating a PortfolioEntry for EVERY coin, and throwing 99% of them away, just create the PE for our actual portfolio.
  • Loading branch information
lyricnz committed Oct 13, 2021
1 parent e409a0b commit 9fa5006
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions cointop/portfolio.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,25 +556,13 @@ func (ct *Cointop) GetPortfolioSlice() []*Coin {
return sliced
}

OUTER:
for i := range ct.State.allCoins {
coin := ct.State.allCoins[i]
p, isNew := ct.PortfolioEntry(coin)
if isNew {
for _, p := range ct.State.portfolio.Entries {
coinIfc, _ := ct.State.allCoinsSlugMap.Load(p.Coin)
coin, ok := coinIfc.(*Coin)
if !ok {
log.Errorf("Could not find coin %s", p.Coin)
continue
}
// check not already found
updateSlice := -1
for j := range sliced {
if coin.Symbol == sliced[j].Symbol {
if coin.Rank >= sliced[j].Rank {
continue OUTER // skip updates from lower-ranked coins
}
updateSlice = j // update this later
break
}
}

coin.Holdings = p.Holdings
balance := coin.Price * p.Holdings
balancestr := fmt.Sprintf("%.2f", balance)
Expand All @@ -583,12 +571,7 @@ OUTER:
}
balance, _ = strconv.ParseFloat(balancestr, 64)
coin.Balance = balance
if updateSlice == -1 {
sliced = append(sliced, coin)
} else {
sliced[updateSlice] = coin
}

sliced = append(sliced, coin)
}

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

0 comments on commit 9fa5006

Please sign in to comment.