convert symbol to name for price api

pull/42/head
Miguel Mota 5 years ago
parent f64aa460b3
commit 3be23ec912
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -238,15 +238,26 @@ func (s *Service) GetGlobalMarketData(convert string) (apitypes.GlobalMarketData
// Price returns the current price of the coin
func (s *Service) Price(name string, convert string) (float64, error) {
ids := []string{name}
list, err := s.client.CoinsList()
if err != nil {
return 0, err
}
for _, item := range *list {
if item.Symbol == strings.ToLower(name) {
name = item.Name
}
}
ids := []string{util.NameToSlug(name)}
convert = strings.ToLower(convert)
currencies := []string{convert}
list, err := s.client.SimplePrice(ids, currencies)
priceList, err := s.client.SimplePrice(ids, currencies)
if err != nil {
return 0, err
}
for _, item := range *list {
for _, item := range *priceList {
if p, ok := item[convert]; ok {
return util.FormatPrice(float64(p), convert), nil
}

@ -168,7 +168,7 @@ func (s *Service) GetGlobalMarketData(convert string) (apitypes.GlobalMarketData
// Price returns the current price of the coin
func (s *Service) Price(name string, convert string) (float64, error) {
convert = strings.ToUpper(convert)
symbol, err := cmcv2.CoinSymbol(name)
symbol, err := cmcv2.CoinSymbol(util.NameToSlug(name))
if err != nil {
return 0, err
}

@ -3,6 +3,7 @@ module github.com/miguelmota/cointop
require (
github.com/BurntSushi/toml v0.3.1
github.com/anaskhan96/soup v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.1
github.com/fatih/color v1.7.0
github.com/gizak/termui v2.3.0+incompatible // indirect
github.com/google/pprof v0.0.0-20190502144155-8358a9778bd1 // indirect

Loading…
Cancel
Save