You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cointop/cointop/dominance.go

43 lines
883 B
Go

package cointop
import (
"fmt"
"os"
"github.com/cointop-sh/cointop/pkg/api"
)
// DominanceConfig is the config options for the dominance command
type DominanceConfig struct {
Currency string
APIChoice string
}
// PrintBitcoinDominance outputs the dominance percentage of bitcoin
func PrintBitcoinDominance(config *DominanceConfig) error {
if config == nil {
config = &DominanceConfig{}
}
var coinAPI api.Interface
if config.APIChoice == CoinMarketCap {
coinAPI = api.NewCMC("")
} else if config.APIChoice == CoinGecko {
coinAPI = api.NewCG(&api.CoinGeckoConfig{
ApiKey: os.Getenv("COINGECKO_PRO_API_KEY"),
})
} else {
return ErrInvalidAPIChoice
}
data, err := coinAPI.GetGlobalMarketData(config.Currency)
if err != nil {
return err
}
value := fmt.Sprintf("Bitcoin: %.2f%%", data.BitcoinPercentageOfMarketCap)
fmt.Println(value)
return nil
}