2
0
mirror of https://github.com/miguelmota/cointop synced 2024-11-05 00:00:14 +00:00

Merge branch 'master' into feature/resample-data

This commit is contained in:
Simon Roberts 2021-09-26 18:43:13 +10:00
commit 065f23eba2
No known key found for this signature in database
GPG Key ID: 0F30F99E6B771FD4
9 changed files with 85 additions and 55 deletions

View File

@ -10,10 +10,24 @@ import (
// CacheKey returns cached value given key
func (ct *Cointop) CacheKey(key string) string {
log.Debug("CacheKey()")
return strings.ToLower(fmt.Sprintf("%s_%s", ct.apiChoice, key))
}
// CompositeCacheKey returns a CacheKey for a coin (or globaldata)
func (ct *Cointop) CompositeCacheKey(symbol string, name string, convert string, chartRange string) string {
keyname := symbol
if name != "" {
keyname += "-" + name
}
if convert != "" {
keyname += "_" + convert
}
if chartRange != "" {
keyname += "_" + strings.Replace(chartRange, " ", "", -1) // "All Time" contains space
}
return ct.CacheKey(keyname)
}
// CacheAllCoinsSlugMap writes the coins map to the memory and disk cache
func (ct *Cointop) CacheAllCoinsSlugMap() {
log.Debug("CacheAllCoinsSlugMap()")

View File

@ -4,7 +4,6 @@ import (
"fmt"
"math"
"sort"
"strings"
"sync"
"time"
@ -135,7 +134,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
if keyname == "" {
keyname = "globaldata"
}
cachekey := ct.CacheKey(fmt.Sprintf("%s_%s", keyname, strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
cachekey := ct.CompositeCacheKey(keyname, name, ct.State.currencyConversion, ct.State.selectedChartRange)
cached, found := ct.cache.Get(cachekey)
if found {
@ -241,7 +240,7 @@ func (ct *Cointop) PortfolioChart() error {
}
var cacheData [][]float64 // [][time,value]
cachekey := strings.ToLower(fmt.Sprintf("%s_%s_%s", p.Symbol, convert, strings.Replace(selectedChartRange, " ", "", -1)))
cachekey := ct.CompositeCacheKey(p.Symbol, p.Name, convert, selectedChartRange)
cached, found := ct.cache.Get(cachekey)
if found {
// cache hit
@ -318,6 +317,16 @@ func (ct *Cointop) PortfolioChart() error {
}
}
// Scale Portfolio Balances to hide value
if ct.State.hidePortfolioBalances {
var lastPrice = data[len(data)-1]
if lastPrice > 0.0 {
for i, price := range data {
data[i] = 100 * price / lastPrice
}
}
}
chart.SetData(data)
ct.State.chartPoints = chart.GetChartPoints(maxX)

View File

@ -445,7 +445,7 @@ func NewCointop(config *Config) (*Cointop, error) {
})
var globaldata []float64
chartcachekey := ct.CacheKey(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
chartcachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
if ct.filecache != nil {
ct.filecache.Get(chartcachekey, &globaldata)
}

View File

@ -56,53 +56,55 @@ var FiatCurrencyNames = map[string]string{
// CryptocurrencyNames is a map of cryptocurrency symbols to name
var CryptocurrencyNames = map[string]string{
"BTC": "Bitcoin",
"ETH": "Ethereum",
"BTC": "Bitcoin",
"ETH": "Ethereum",
"SATS": "Satoshi",
}
// CurrencySymbolMap is map of fiat currency symbols to names.
// Keep these in alphabetical order.
var CurrencySymbolMap = map[string]string{
"AUD": "$",
"BGN": "Лв.",
"BRL": "R$",
"BTC": "Ƀ",
"CAD": "$",
"CFH": "₣",
"CLP": "$",
"CNY": "¥",
"CZK": "Kč",
"DKK": "Kr",
"ETH": "Ξ",
"EUR": "€",
"GBP": "£",
"HKD": "$",
"HRK": "kn",
"HUF": "Ft",
"IDR": "Rp.",
"ILS": "₪",
"INR": "₹",
"ISK": "kr",
"JPY": "¥",
"KRW": "₩",
"MXN": "$",
"MYR": "RM",
"NOK": "kr",
"NZD": "$",
"PHP": "₱",
"PKR": "₨",
"PLN": "zł",
"RON": "lei",
"RUB": "Ꝑ",
"SEK": "kr",
"SGD": "S$",
"THB": "฿",
"TRY": "₺",
"TWD": "NT$",
"UAH": "₴",
"USD": "$",
"VND": "₫",
"ZAR": "R",
"AUD": "$",
"BGN": "Лв.",
"BRL": "R$",
"BTC": "Ƀ",
"CAD": "$",
"CFH": "₣",
"CLP": "$",
"CNY": "¥",
"CZK": "Kč",
"DKK": "Kr",
"ETH": "Ξ",
"EUR": "€",
"GBP": "£",
"HKD": "$",
"HRK": "kn",
"HUF": "Ft",
"IDR": "Rp.",
"ILS": "₪",
"INR": "₹",
"ISK": "kr",
"JPY": "¥",
"KRW": "₩",
"MXN": "$",
"MYR": "RM",
"NOK": "kr",
"NZD": "$",
"PHP": "₱",
"PKR": "₨",
"PLN": "zł",
"RON": "lei",
"RUB": "Ꝑ",
"SEK": "kr",
"SGD": "S$",
"SATS": "丰",
"THB": "฿",
"TRY": "₺",
"TWD": "NT$",
"UAH": "₴",
"USD": "$",
"VND": "₫",
"ZAR": "R",
}
var alphanumericcharacters = []rune{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'}

View File

@ -1,9 +1,6 @@
package cointop
import (
"fmt"
"strings"
log "github.com/sirupsen/logrus"
)
@ -99,7 +96,7 @@ func (ct *Cointop) layout() error {
ct.Views.Chart.SetBgColor(ct.colorscheme.GocuiBgColor(ct.Views.Chart.Name()))
go func() {
ct.UpdateChart()
cachekey := strings.ToLower(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1)))
cachekey := ct.CompositeCacheKey("globaldata", "", "", ct.State.selectedChartRange)
_, found := ct.cache.Get(cachekey)
if found {
ct.cache.Delete(cachekey)

View File

@ -71,6 +71,7 @@ func (ct *Cointop) UpdateMarketbar() error {
color24h = ct.colorscheme.MarketbarChangeDownSprintf()
arrow = "▼"
}
percentChange24Hstr := color24h(fmt.Sprintf("%.2f%%%s", percentChange24H, arrow))
chartInfo := ""
if !ct.State.hideChart {
@ -84,13 +85,14 @@ func (ct *Cointop) UpdateMarketbar() error {
totalstr = fmt.Sprintf("%s%s", ct.CurrencySymbol(), totalstr)
if ct.State.hidePortfolioBalances {
totalstr = HiddenBalanceChars
percentChange24Hstr = HiddenBalanceChars
}
content = fmt.Sprintf(
"%sTotal Portfolio Value: %s • 24H: %s",
chartInfo,
ct.colorscheme.MarketBarLabelActive(totalstr),
color24h(fmt.Sprintf("%.2f%%%s", percentChange24H, arrow)),
percentChange24Hstr,
)
} else {
ct.State.marketBarHeight = 1
@ -100,7 +102,7 @@ func (ct *Cointop) UpdateMarketbar() error {
var market types.GlobalMarketData
var err error
cachekey := ct.CacheKey("market")
cachekey := ct.CompositeCacheKey("market", "", ct.State.currencyConversion, "")
cached, found := ct.cache.Get(cachekey)
if found {

View File

@ -183,7 +183,12 @@ func (ct *Cointop) UpdateTableHeader() error {
leftAlign := ct.GetTableColumnAlignLeft(col)
switch col {
case "price", "balance":
label = ct.CurrencySymbol() + label
spacing := ""
// Add an extra space because "satoshi" UTF-8 chracter overlaps text on right
if ct.State.currencyConversion == "SATS" {
spacing = " "
}
label = fmt.Sprintf("%s%s%s", ct.CurrencySymbol(), spacing, label)
}
if leftAlign {
label = label + arrow

View File

@ -187,7 +187,7 @@ draft: false
You can run cointop with the `--hide-portfolio-balances` flag to hide portfolio balances or use the keyboard shortcut <kbd>Ctrl</kbd>+<kbd>space</kbd> on the portfolio page to toggle hide/show.
<img width="880" alt="hide portfolio balances" src="https://user-images.githubusercontent.com/168240/133199691-f5ec0714-8c83-4df3-a525-5ccea1fcf931.png" />
<img width="880" alt="hide portfolio balances" src="https://user-images.githubusercontent.com/122371/133578568-153af3cc-350d-4744-ac89-dd8f5e317d1d.png" />
## I'm getting question marks or weird symbols instead of the correct characters.

View File

@ -268,6 +268,7 @@ func (s *Service) SupportedCurrencies() []string {
"PLN",
"RUB",
"SAR",
"SATS",
"SEK",
"SGD",
"THB",