Merge branch 'feature/30d-and-1y-change' of https://github.com/simon-anz/cointop into simon-anz-feature/30d-and-1y-change

pull/153/head
Miguel Mota 3 years ago
commit 296590b466
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -28,6 +28,7 @@ func ActionsMap() map[string]bool {
"sort_column_24h_volume": true,
"sort_column_7d_change": true,
"sort_column_30d_change": true,
"sort_column_1y_change": true,
"sort_column_asc": true,
"sort_column_available_supply": true,
"sort_column_desc": true,

@ -16,6 +16,7 @@ type Coin struct {
PercentChange24H float64
PercentChange7D float64
PercentChange30D float64
PercentChange1Y float64
LastUpdated string
// for favorites
Favorite bool

@ -19,6 +19,7 @@ var SupportedCoinTableHeaders = []string{
"24h_change",
"7d_change",
"30d_change",
"1y_change",
"24h_volume",
"market_cap",
"available_supply",
@ -221,6 +222,25 @@ func (ct *Cointop) GetCoinsTable() *table.Table {
Color: color30d,
Text: text,
})
case "1y_change":
color1y := ct.colorscheme.TableColumnChange
if coin.PercentChange1Y > 0 {
color1y = ct.colorscheme.TableColumnChangeUp
}
if coin.PercentChange1Y < 0 {
color1y = ct.colorscheme.TableColumnChangeDown
}
text := fmt.Sprintf("%v%%", humanize.Numericf(coin.PercentChange1Y, 2))
ct.SetTableColumnWidthFromString(header, text)
ct.SetTableColumnAlignLeft(header, false)
rowCells = append(rowCells,
&table.RowCell{
LeftMargin: leftMargin,
RightMargin: rightMargin,
LeftAlign: false,
Color: color1y,
Text: text,
})
case "market_cap":
text := humanize.Monetaryf(coin.MarketCap, 0)
ct.SetTableColumnWidthFromString(header, text)

@ -69,6 +69,7 @@ func DefaultShortcuts() map[string]string {
"t": "sort_column_total_supply",
"u": "sort_column_last_updated",
"v": "sort_column_24h_volume",
"y": "sort_column_1y_change",
"q": "quit_view",
"Q": "quit_view",
"%": "sort_column_percent_holdings",

@ -227,6 +227,8 @@ func (ct *Cointop) Keybindings(g *gocui.Gui) error {
fn = ct.Sortfn("7d_change", true)
case "sort_column_30d_change":
fn = ct.Sortfn("30d_change", true)
case "sort_column_1y_change":
fn = ct.Sortfn("1y_change", true)
case "sort_column_available_supply":
fn = ct.Sortfn("available_supply", true)
case "toggle_row_chart":

@ -91,6 +91,7 @@ func (ct *Cointop) processCoins(coins []types.Coin) {
PercentChange24H: v.PercentChange24H,
PercentChange7D: v.PercentChange7D,
PercentChange30D: v.PercentChange30D,
PercentChange1Y: v.PercentChange1Y,
LastUpdated: v.LastUpdated,
})
if ilast != nil {
@ -141,6 +142,7 @@ func (ct *Cointop) processCoins(coins []types.Coin) {
c.PercentChange24H = cm.PercentChange24H
c.PercentChange7D = cm.PercentChange7D
c.PercentChange30D = cm.PercentChange30D
c.PercentChange1Y = cm.PercentChange1Y
c.LastUpdated = cm.LastUpdated
c.Favorite = cm.Favorite
}

@ -30,6 +30,7 @@ var SupportedPortfolioTableHeaders = []string{
"24h_change",
"7d_change",
"30d_change",
"1y_change",
"percent_holdings",
"last_updated",
}
@ -238,6 +239,25 @@ func (ct *Cointop) GetPortfolioTable() *table.Table {
Color: color30d,
Text: text,
})
case "1y_change":
color1y := ct.colorscheme.TableColumnChange
if coin.PercentChange1Y > 0 {
color1y = ct.colorscheme.TableColumnChangeUp
}
if coin.PercentChange1Y < 0 {
color1y = ct.colorscheme.TableColumnChangeDown
}
text := fmt.Sprintf("%.2f%%", coin.PercentChange1Y)
ct.SetTableColumnWidthFromString(header, text)
ct.SetTableColumnAlignLeft(header, false)
rowCells = append(rowCells,
&table.RowCell{
LeftMargin: leftMargin,
RightMargin: rightMargin,
LeftAlign: false,
Color: color1y,
Text: text,
})
case "percent_holdings":
percentHoldings := (coin.Balance / total) * 1e2
if math.IsNaN(percentHoldings) {

@ -59,6 +59,8 @@ func (ct *Cointop) Sort(sortBy string, desc bool, list []*Coin, renderHeaders bo
return a.PercentChange7D < b.PercentChange7D
case "30d_change":
return a.PercentChange30D < b.PercentChange30D
case "1y_change":
return a.PercentChange1Y < b.PercentChange1Y
case "total_supply":
return a.TotalSupply < b.TotalSupply
case "available_supply":

@ -95,6 +95,11 @@ var HeaderColumns = map[string]*HeaderColumn{
Label: "[3]0D%",
PlainLabel: "30D%",
},
"1y_change": &HeaderColumn{
Slug: "1y_change",
Label: "1[y]%",
PlainLabel: "1Y%",
},
"total_supply": &HeaderColumn{
Slug: "total_supply",
Label: "[t]otal supply",

@ -347,7 +347,7 @@ draft: false
## What price-change columns are available?
Supported columns relating to price change are `1h_change`, `24h_change`, `7d_change`, `30d_change`
Supported columns relating to price change are `1h_change`, `24h_change`, `7d_change`, `30d_change`, `1y_change`
## How can use a different config file other than the default?

@ -343,6 +343,7 @@ func (s *Service) getPaginatedCoinData(convert string, offset int, names []strin
pcp.PCP24h,
pcp.PCP7d,
pcp.PCP30d,
pcp.PCP1y,
}
order := geckoTypes.OrderTypeObject.MarketCapDesc
convertTo := strings.ToLower(convert)
@ -372,6 +373,7 @@ func (s *Service) getPaginatedCoinData(convert string, offset int, names []strin
var percentChange24H float64
var percentChange7D float64
var percentChange30D float64
var percentChange1Y float64
if item.PriceChangePercentage1hInCurrency != nil {
percentChange1H = *item.PriceChangePercentage1hInCurrency
@ -385,6 +387,9 @@ func (s *Service) getPaginatedCoinData(convert string, offset int, names []strin
if item.PriceChangePercentage30dInCurrency != nil {
percentChange30D = *item.PriceChangePercentage30dInCurrency
}
if item.PriceChangePercentage1yInCurrency != nil {
percentChange1Y = *item.PriceChangePercentage1yInCurrency
}
availableSupply := item.CirculatingSupply
totalSupply := item.TotalSupply
@ -405,6 +410,7 @@ func (s *Service) getPaginatedCoinData(convert string, offset int, names []strin
PercentChange24H: util.FormatPercentChange(percentChange24H),
PercentChange7D: util.FormatPercentChange(percentChange7D),
PercentChange30D: util.FormatPercentChange(percentChange30D),
PercentChange1Y: util.FormatPercentChange(percentChange1Y),
Volume24H: util.FormatVolume(item.TotalVolume),
LastUpdated: util.FormatLastUpdated(item.LastUpdated),
})

@ -15,6 +15,7 @@ type Coin struct {
PercentChange24H float64 `json:"percentChange24H"`
PercentChange7D float64 `json:"percentChange7D"`
PercentChange30D float64 `json:"percentChange30D"`
PercentChange1Y float64 `json:"percentChange1Y"`
LastUpdated string `json:"lastUpdated"`
}

Loading…
Cancel
Save