Files
gocryptotrader/currency/forexprovider/forexprovider.go
Andrew d01e7bad72 Implement Logger (#228)
* Added new base logger

* updated example and test configs

* updated exchange helpers restful router & server

* logPath is now passed to the logger to remove dependency on common package

* updated everything besides exchanges to use new logger

* alphapoint to bitmex done

* updated bitmex bitstamp bittrex btcc and also performance changes to logger

* btcmarkets coinbase coinut exmo gateio wrappers updated

* gateio and gemini logger updated

* hitbtc huobi itbit & kraken updated

* All exchanges updatd

* return correct error for disabled websocket

* don't disconnect client on invalid json

* updated router internal logging

* log.Fatal to t.Error for tests

* Changed from fatal to error failure to set maxprocs

* output ANSI codes for everything but windows for now due to lack of windows support

* added error handling to logger and unit tests

* clear wording on print -> log.print

* added benchmark test

* cleaned up import sections

* Updated logger based on PR requests (added default config options on failure/setting errors)

* ah this should fix travici enc config issue

* Load entire config and clear out logging to hopefully fix travisci issue

* wording & test error handling

* fixed formatting issues based on feedback

* fixed formatting issues based on feedback

* changed CheckDir to use mkdirall instead of mkdir and other changes based on feedback
2019-01-08 21:56:22 +11:00

67 lines
2.5 KiB
Go

// Package forexprovider utilises foreign exchange API services to manage
// relational FIAT currencies
package forexprovider
import (
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
currencyconverter "github.com/thrasher-/gocryptotrader/currency/forexprovider/currencyconverterapi"
"github.com/thrasher-/gocryptotrader/currency/forexprovider/currencylayer"
fixer "github.com/thrasher-/gocryptotrader/currency/forexprovider/fixer.io"
"github.com/thrasher-/gocryptotrader/currency/forexprovider/openexchangerates"
log "github.com/thrasher-/gocryptotrader/logger"
)
// ForexProviders is an array of foreign exchange interfaces
type ForexProviders struct {
base.IFXProviders
}
// GetAvailableForexProviders returns a list of supported forex providers
func GetAvailableForexProviders() []string {
return []string{"CurrencyConverter", "CurrencyLayer", "Fixer", "OpenExchangeRates"}
}
// NewDefaultFXProvider returns the default forex provider (currencyconverterAPI)
func NewDefaultFXProvider() *ForexProviders {
fxp := new(ForexProviders)
currencyC := new(currencyconverter.CurrencyConverter)
currencyC.PrimaryProvider = true
currencyC.Enabled = true
currencyC.Name = "CurrencyConverter"
currencyC.APIKeyLvl = 0
currencyC.Verbose = false
fxp.IFXProviders = append(fxp.IFXProviders, currencyC)
return fxp
}
// StartFXService starts the forex provider service and returns a pointer to it
func StartFXService(fxProviders []base.Settings) *ForexProviders {
fxp := new(ForexProviders)
for i := range fxProviders {
if fxProviders[i].Name == "CurrencyConverter" && fxProviders[i].Enabled {
currencyC := new(currencyconverter.CurrencyConverter)
currencyC.Setup(fxProviders[i])
fxp.IFXProviders = append(fxp.IFXProviders, currencyC)
}
if fxProviders[i].Name == "CurrencyLayer" && fxProviders[i].Enabled {
currencyLayerP := new(currencylayer.CurrencyLayer)
currencyLayerP.Setup(fxProviders[i])
fxp.IFXProviders = append(fxp.IFXProviders, currencyLayerP)
}
if fxProviders[i].Name == "Fixer" && fxProviders[i].Enabled {
fixerP := new(fixer.Fixer)
fixerP.Setup(fxProviders[i])
fxp.IFXProviders = append(fxp.IFXProviders, fixerP)
}
if fxProviders[i].Name == "OpenExchangeRates" && fxProviders[i].Enabled {
OpenExchangeRatesP := new(openexchangerates.OXR)
OpenExchangeRatesP.Setup(fxProviders[i])
fxp.IFXProviders = append(fxp.IFXProviders, OpenExchangeRatesP)
}
}
if len(fxp.IFXProviders) == 0 {
log.Error("No foreign exchange providers enabled")
}
return fxp
}