mirror of https://github.com/miguelmota/cointop
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.
40 lines
816 B
Go
40 lines
816 B
Go
4 years ago
|
package cointop
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
|
||
|
"github.com/miguelmota/cointop/cointop/common/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()
|
||
|
} 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
|
||
|
}
|