|
|
|
@ -26,7 +26,9 @@ var DefaultPortfolioTableHeaders = []string{
|
|
|
|
|
"price",
|
|
|
|
|
"holdings",
|
|
|
|
|
"balance",
|
|
|
|
|
"1h_change",
|
|
|
|
|
"24h_change",
|
|
|
|
|
"7d_change",
|
|
|
|
|
"percent_holdings",
|
|
|
|
|
"last_updated",
|
|
|
|
|
}
|
|
|
|
@ -68,13 +70,27 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
colorbalance := ct.colorscheme.TableColumnPrice
|
|
|
|
|
color1h := ct.colorscheme.TableColumnChange
|
|
|
|
|
color24h := ct.colorscheme.TableColumnChange
|
|
|
|
|
color7d := ct.colorscheme.TableColumnChange
|
|
|
|
|
if coin.PercentChange1H > 0 {
|
|
|
|
|
color1h = ct.colorscheme.TableColumnChangeUp
|
|
|
|
|
}
|
|
|
|
|
if coin.PercentChange1H < 0 {
|
|
|
|
|
color1h = ct.colorscheme.TableColumnChangeDown
|
|
|
|
|
}
|
|
|
|
|
if coin.PercentChange24H > 0 {
|
|
|
|
|
color24h = ct.colorscheme.TableColumnChangeUp
|
|
|
|
|
}
|
|
|
|
|
if coin.PercentChange24H < 0 {
|
|
|
|
|
color24h = ct.colorscheme.TableColumnChangeDown
|
|
|
|
|
}
|
|
|
|
|
if coin.PercentChange7D > 0 {
|
|
|
|
|
color7d = ct.colorscheme.TableColumnChangeUp
|
|
|
|
|
}
|
|
|
|
|
if coin.PercentChange7D < 0 {
|
|
|
|
|
color7d = ct.colorscheme.TableColumnChangeDown
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
percentHoldings := (coin.Balance / total) * 1e2
|
|
|
|
|
if math.IsNaN(percentHoldings) {
|
|
|
|
@ -83,71 +99,112 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
|
|
|
|
|
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
|
|
|
|
|
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
|
|
|
|
|
|
|
|
|
|
t.AddRowCells(
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 0,
|
|
|
|
|
Width: 6,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.Default,
|
|
|
|
|
Text: rank,
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 22,
|
|
|
|
|
LeftAlign: true,
|
|
|
|
|
Color: namecolor,
|
|
|
|
|
Text: name,
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 6,
|
|
|
|
|
LeftAlign: true,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: symbol,
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 14,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: humanize.Commaf(coin.Price),
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 16,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: strconv.FormatFloat(coin.Holdings, 'f', -1, 64),
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 16,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: colorbalance,
|
|
|
|
|
Text: humanize.Commaf(coin.Balance),
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 10,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: color24h,
|
|
|
|
|
Text: fmt.Sprintf("%.2f%%", coin.PercentChange24H),
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 14,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: fmt.Sprintf("%.2f%%", percentHoldings),
|
|
|
|
|
},
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 18,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: lastUpdated,
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
headers := ct.GetPortfolioTableHeaders()
|
|
|
|
|
var rowCells []*table.RowCell
|
|
|
|
|
for _, header := range headers {
|
|
|
|
|
switch header {
|
|
|
|
|
case "rank":
|
|
|
|
|
rowCells = append(rowCells, &table.RowCell{
|
|
|
|
|
LeftMargin: 0,
|
|
|
|
|
Width: 6,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.Default,
|
|
|
|
|
Text: rank,
|
|
|
|
|
})
|
|
|
|
|
case "name":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 22,
|
|
|
|
|
LeftAlign: true,
|
|
|
|
|
Color: namecolor,
|
|
|
|
|
Text: name,
|
|
|
|
|
})
|
|
|
|
|
case "symbol":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 6,
|
|
|
|
|
LeftAlign: true,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: symbol,
|
|
|
|
|
})
|
|
|
|
|
case "price":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 14,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: humanize.Commaf(coin.Price),
|
|
|
|
|
})
|
|
|
|
|
case "holdings":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 16,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: strconv.FormatFloat(coin.Holdings, 'f', -1, 64),
|
|
|
|
|
})
|
|
|
|
|
case "balance":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 16,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: colorbalance,
|
|
|
|
|
Text: humanize.Commaf(coin.Balance),
|
|
|
|
|
})
|
|
|
|
|
case "1h_change":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 10,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: color1h,
|
|
|
|
|
Text: fmt.Sprintf("%.2f%%", coin.PercentChange1H),
|
|
|
|
|
})
|
|
|
|
|
case "24h_change":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 10,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: color24h,
|
|
|
|
|
Text: fmt.Sprintf("%.2f%%", coin.PercentChange24H),
|
|
|
|
|
})
|
|
|
|
|
case "7d_change":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 10,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: color7d,
|
|
|
|
|
Text: fmt.Sprintf("%.2f%%", coin.PercentChange7D),
|
|
|
|
|
})
|
|
|
|
|
case "percent_holdings":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 14,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: fmt.Sprintf("%.2f%%", percentHoldings),
|
|
|
|
|
})
|
|
|
|
|
case "last_updated":
|
|
|
|
|
rowCells = append(rowCells,
|
|
|
|
|
&table.RowCell{
|
|
|
|
|
LeftMargin: 1,
|
|
|
|
|
Width: 18,
|
|
|
|
|
LeftAlign: false,
|
|
|
|
|
Color: ct.colorscheme.TableRow,
|
|
|
|
|
Text: lastUpdated,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
t.AddRowCells(rowCells...)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return t
|
|
|
|
|