mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +00:00
* Removed package-lock.json form gitignore as it ensures specific package versions * Updated all @angular web dependencies * Resolved tslint errors using autofix option * Resolved some more tslint issues * Added lint scripts to package.json to easy lint the ts files * Updated codelyzer and tslint * Run web on travis using node 10 and run the lint task * Resolved some more tslint issues after upgrading tslint and codelyzer * Resolved golint issues with regards to exchange comments * Resolved spelling errors shown by goreportcard.com * Resolved gofmt warnings using goreportcard.com * Resolved golint issue by removing unrequired else statement * Refactored slack.go to reduce cyclomatic complexity * Fixed govet issue where Slack was passed as value instead of reference
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package base
|
|
|
|
import (
|
|
"errors"
|
|
"log"
|
|
)
|
|
|
|
// 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.Println(err)
|
|
for y := range fxp {
|
|
if !fxp[y].IsPrimaryProvider() && fxp[x].IsEnabled() {
|
|
rates, err = fxp[y].GetRates(baseCurrency, symbols)
|
|
if err != nil {
|
|
log.Println(err)
|
|
continue
|
|
}
|
|
return rates, nil
|
|
}
|
|
}
|
|
return nil, errors.New("ForexProvider error GetCurrencyData() failed to acquire data")
|
|
}
|
|
return rates, nil
|
|
}
|
|
}
|
|
return nil, errors.New("ForexProvider error GetCurrencyData() no providers enabled")
|
|
}
|