Files
gocryptotrader/currency/forexprovider/base/base_interface.go
Adrian Gallagher 7dcb1ab553 Migrate from gometalinter.v2 to golangci-lint (#249)
* Migrate from gometalinter.v2 to golangci-lint
2019-03-01 16:10:29 +11:00

47 lines
1.2 KiB
Go

package base
import (
"errors"
"fmt"
log "github.com/thrasher-/gocryptotrader/logger"
)
// IFXProviders contains an array of foreign exchange interfaces
type IFXProviders []IFXProvider
// IFXProvider enforces standard functions for all foreign exchange providers
// supported in GoCryptoTrader
type IFXProvider interface {
Setup(config Settings)
GetRates(baseCurrency, symbols string) (map[string]float64, error)
GetName() string
IsEnabled() bool
IsPrimaryProvider() bool
}
// GetCurrencyData returns currency data from enabled FX providers
func (fxp IFXProviders) GetCurrencyData(baseCurrency, symbols string) (map[string]float64, error) {
for x := range fxp {
if fxp[x].IsPrimaryProvider() && fxp[x].IsEnabled() {
rates, err := fxp[x].GetRates(baseCurrency, symbols)
if err != nil {
log.Error(err)
for y := range fxp {
if !fxp[y].IsPrimaryProvider() && fxp[x].IsEnabled() {
rates, err = fxp[y].GetRates(baseCurrency, symbols)
if err != nil {
log.Error(err)
continue
}
return rates, nil
}
}
return nil, fmt.Errorf("forex provider %s unable to acquire rates data", fxp[x].GetName())
}
return rates, nil
}
}
return nil, errors.New("no forex providers enabled")
}