Rename "buy" to "cost" in portfolio

pull/243/head
Simon Roberts 3 years ago
parent 137d0289f0
commit 6d8a822448
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4

@ -35,12 +35,10 @@ var SupportedPortfolioTableHeaders = []string{
"1y_change",
"percent_holdings",
"last_updated",
"buy_price",
"buy_currency",
// "buy_cost" // holdings * buy_price * conversion??
"cost_price",
"cost",
"profit",
"profit_percent",
"cost",
}
// DefaultPortfolioTableHeaders are the default portfolio table header columns
@ -307,13 +305,12 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
Color: ct.colorscheme.TableRow,
Text: lastUpdated,
})
case "buy_price":
// TODO: finish
text := ct.FormatPrice(coin.BuyPrice)
case "cost_price":
text := fmt.Sprintf("%s %s", coin.BuyCurrency, ct.FormatPrice(coin.BuyPrice))
if ct.State.hidePortfolioBalances {
text = HiddenBalanceChars
}
if coin.BuyPrice == 0.0 {
if coin.BuyPrice == 0.0 || coin.BuyCurrency == "" {
text = ""
}
symbolPadding := 1
@ -327,9 +324,23 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
Color: ct.colorscheme.TableRow,
Text: text,
})
case "buy_currency":
// TODO: finish - merge with buy_price?
text := coin.BuyCurrency
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)
@ -338,7 +349,7 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
LeftMargin: leftMargin,
RightMargin: rightMargin,
LeftAlign: false,
Color: ct.colorscheme.TableRow,
Color: ct.colorscheme.TableColumnPrice,
Text: text,
})
case "profit":
@ -406,34 +417,6 @@ 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.TableColumnPrice,
Text: text,
})
}
}

@ -68,17 +68,14 @@ func (ct *Cointop) Sort(sortBy string, desc bool, list []*Coin, renderHeaders bo
return a.AvailableSupply < b.AvailableSupply
case "last_updated":
return a.LastUpdated < b.LastUpdated
case "buy_price":
case "cost_price":
return a.BuyPrice < b.BuyPrice
case "buy_currency":
return a.BuyCurrency < b.BuyCurrency
case "cost":
return (a.BuyPrice * a.Holdings) < (b.BuyPrice * b.Holdings) // TODO: convert?
case "profit":
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
}

@ -126,15 +126,15 @@ var HeaderColumns = map[string]*HeaderColumn{
Label: "last [u]pdated",
PlainLabel: "last updated",
},
"buy_price": {
Slug: "buy_price",
Label: "buy price",
PlainLabel: "buy price",
"cost_price": {
Slug: "cost_price",
Label: "cost price",
PlainLabel: "cost price",
},
"buy_currency": { // TODO: merge with price?
Slug: "buy_curency",
Label: "bcur",
PlainLabel: "bcur",
"cost": {
Slug: "cost",
Label: "cost[!]",
PlainLabel: "cost",
},
"profit": {
Slug: "profit",
@ -146,11 +146,6 @@ 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