Add cost column. Improve formatting.

pull/243/head
Simon Roberts 3 years ago
parent 90187d88b5
commit 41431d51f4
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -40,6 +40,7 @@ var SupportedPortfolioTableHeaders = []string{
// "buy_cost" // holdings * buy_price * conversion??
"profit",
"profit_percent",
"cost",
}
// DefaultPortfolioTableHeaders are the default portfolio table header columns
@ -342,18 +343,26 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
})
case "profit":
text := ""
colorProfit := ct.colorscheme.TableColumnChange
if coin.BuyPrice > 0 && coin.BuyCurrency != "" {
costPrice, err := ct.Convert(coin.BuyCurrency, ct.State.currencyConversion, coin.BuyPrice)
if err == nil {
profit := (coin.Price - costPrice) * coin.Holdings
text = humanize.FixedMonetaryf(profit, 2)
if profit > 0 {
colorProfit = ct.colorscheme.TableColumnChangeUp
} else if profit < 0 {
colorProfit = ct.colorscheme.TableColumnChangeDown
}
} else {
text = "?"
}
}
if ct.State.hidePortfolioBalances {
text = HiddenBalanceChars
colorProfit = ct.colorscheme.TableColumnChange
}
symbolPadding := 1
ct.SetTableColumnWidth(header, utf8.RuneCountInString(text)+symbolPadding)
ct.SetTableColumnAlignLeft(header, false)
@ -362,7 +371,7 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
LeftMargin: leftMargin,
RightMargin: rightMargin,
LeftAlign: false,
Color: ct.colorscheme.TableRow,
Color: colorProfit,
Text: text,
})
case "profit_percent":
@ -376,11 +385,14 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
colorProfit := ct.colorscheme.TableColumnChange
if profitPercent > 0 {
colorProfit = ct.colorscheme.TableColumnChangeUp
}
if profitPercent < 0 {
} else if profitPercent < 0 {
colorProfit = ct.colorscheme.TableColumnChangeDown
}
text := fmt.Sprintf("%.2f%%", profitPercent)
if ct.State.hidePortfolioBalances {
text = HiddenBalanceChars
colorProfit = ct.colorscheme.TableColumnChange
}
if coin.BuyPrice == 0.0 {
text = ""
}
@ -394,6 +406,34 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
Color: colorProfit,
Text: text,
})
case "cost":
cost := 0.0
if coin.BuyPrice > 0 && coin.BuyCurrency != "" {
costPrice, err := ct.Convert(coin.BuyCurrency, ct.State.currencyConversion, coin.BuyPrice)
if err == nil {
cost = costPrice * coin.Holdings
}
}
// text := ct.FormatPrice(cost)
text := humanize.FixedMonetaryf(cost, 2)
if ct.State.hidePortfolioBalances {
text = HiddenBalanceChars
}
if coin.BuyPrice == 0.0 {
text = ""
}
symbolPadding := 1
ct.SetTableColumnWidth(header, utf8.RuneCountInString(text)+symbolPadding)
ct.SetTableColumnAlignLeft(header, false)
rowCells = append(rowCells,
&table.RowCell{
LeftMargin: leftMargin,
RightMargin: rightMargin,
LeftAlign: false,
Color: ct.colorscheme.TableRow,
Text: text,
})
}
}

@ -76,6 +76,9 @@ func (ct *Cointop) Sort(sortBy string, desc bool, list []*Coin, renderHeaders bo
return (a.Price - a.BuyPrice) < (b.Price - b.BuyPrice)
case "profit_percent":
return (a.Price - a.BuyPrice) < (b.Price - b.BuyPrice)
case "cost":
// TODO: convert?
return (a.BuyPrice * a.Holdings) < (b.BuyPrice * b.Holdings)
default:
return a.Rank < b.Rank
}

@ -146,6 +146,11 @@ var HeaderColumns = map[string]*HeaderColumn{
Label: "PNL%",
PlainLabel: "PNL%",
},
"cost": {
Slug: "cost",
Label: "cost",
PlainLabel: "cost",
},
}
// GetLabel fetch the label to use for the heading (depends on configuration)

Loading…
Cancel
Save