forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_interface.go
44 lines (40 loc) · 1.21 KB
/
base_interface.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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")
}