Fix global chart always showing in USD, and add current currency to chart name (#209)

* Use exchange-rates to convert GlobalMarketGraphData
* Ask for global data in usd just in case it starts working again :)
* Include currency conversion in chart title #207
* Better error handling
pull/213/head^2
Simon Roberts 3 years ago committed by GitHub
parent b22c040ffb
commit cf5270623d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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,
)
}

@ -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,
})
}
}

Loading…
Cancel
Save