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