diff --git a/cointop/marketbar.go b/cointop/marketbar.go index a381573..86b5dbf 100644 --- a/cointop/marketbar.go +++ b/cointop/marketbar.go @@ -78,9 +78,10 @@ func (ct *Cointop) UpdateMarketbar() error { chartInfo := "" if !ct.State.hideChart { chartInfo = fmt.Sprintf( - "[ Chart: %s %s ] ", + "[ Chart: %s %s %s ] ", charttitle, timeframe, + ct.State.currencyConversion, ) } @@ -141,9 +142,10 @@ func (ct *Cointop) UpdateMarketbar() error { chartInfo := "" if !ct.State.hideChart { chartInfo = fmt.Sprintf( - "[ Chart: %s %s ] ", + "[ Chart: %s %s %s] ", ct.colorscheme.MarketBarLabelActive(chartname), timeframe, + ct.State.currencyConversion, ) } diff --git a/pkg/api/impl/coingecko/coingecko.go b/pkg/api/impl/coingecko/coingecko.go index e196870..612cb68 100644 --- a/pkg/api/impl/coingecko/coingecko.go +++ b/pkg/api/impl/coingecko/coingecko.go @@ -154,18 +154,40 @@ func (s *Service) GetGlobalMarketGraphData(convert string, start int64, end int6 if convertTo == "" { convertTo = "usd" } - graphData, err := s.client.GlobalCharts(convertTo, days) + graphData, err := s.client.GlobalCharts("usd", days) if err != nil { return ret, err } + // This API does not appear to support vs_currency and only returns USD, so use ExchangeRates to convert + rate := 1.0 + if convertTo != "usd" { + rates, err := s.client.ExchangeRates() + if err != nil { + return ret, err + } + if rates == nil { + return ret, fmt.Errorf("expected rates, received nil") + } + // Combined rate is USD->BTC->other + btcRate, found := (*rates)[convertTo] + if !found { + return ret, fmt.Errorf("unsupported currency conversion: %s", convertTo) + } + usdRate, found := (*rates)["usd"] + if !found { + return ret, fmt.Errorf("unsupported currency conversion: usd") + } + rate = btcRate.Value / usdRate.Value + } + var marketCapUSD [][]float64 var marketVolumeUSD [][]float64 if graphData.Stats != nil { for _, item := range *graphData.Stats { marketCapUSD = append(marketCapUSD, []float64{ float64(item[0]), - float64(item[1]), + float64(item[1]) * rate, }) } }