mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-05 23:16:53 +00:00
* Initial currency overhaul before service system implementation * Remove redundant currency string in orderbook.Base Unexport lastupdated field in orderbook.Base as it was being instantiated multiple times Add error handling for process orderbook * Remove redundant currency string in ticker.Price Unexport lastupdated field in ticker.Price Add error handling for process ticker function and fix tests * Phase Two Update * Update translations to use map type - thankyou to kempeng for spotting this * Change pair method name from Display -> Format for better readability * Fixes misspelling and tests * Implement requested changes from GloriousCode * Remove reduntant function and streamlined return in currency_translation.go * Revert pair method naming conventions * Change currency naming conventions * Changed code type to exported Item type with underlying string to reduce complexity * Added interim orderbook process method to orderbook.Base type * Changed feebuilder struct field to currency.Pair * Adds fall over system for backup fx providers * deprecate function and children and fix linter issue with btcmarkets * Fixed requested changes * Fix bug and move mtx for rates * Fixed after rebase oopsies * Fix linter issues * Fixes race conditions in testing functions * Final phase coinmarketcap update * fix linter issues * Implement requested changes * Adds configuration variables to increase/decrease time durations between updating currency file and fetching new currency rates * Add a collection of tests to improve codecov * After rebase oopsy fixes for btse * Fix requested changes * fix after rebase oopsies and add more efficient comparison checks within currency pair * Fix linter issues
138 lines
3.7 KiB
Go
138 lines
3.7 KiB
Go
package currencylayer
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/thrasher-/gocryptotrader/currency/forexprovider/base"
|
|
)
|
|
|
|
var c CurrencyLayer
|
|
|
|
// please set your API key here for due diligence testing NOTE be aware you will
|
|
// minimize your API calls using this test.
|
|
const (
|
|
APIkey = ""
|
|
Apilevel = 0
|
|
)
|
|
|
|
var isSet bool
|
|
|
|
func setup() error {
|
|
if !isSet {
|
|
defaultCfg := base.Settings{
|
|
Name: "CurrencyLayer",
|
|
Enabled: true,
|
|
}
|
|
|
|
if APIkey != "" {
|
|
defaultCfg.APIKey = APIkey
|
|
}
|
|
|
|
if Apilevel > -2 && Apilevel < 4 {
|
|
defaultCfg.APIKeyLvl = Apilevel
|
|
}
|
|
|
|
err := c.Setup(defaultCfg)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
isSet = true
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func areAPIKeysSet() bool {
|
|
return APIkey != "" && Apilevel != -1
|
|
}
|
|
|
|
func TestGetRates(t *testing.T) {
|
|
err := setup()
|
|
if err != nil {
|
|
t.Skip("Test Failed - CurrencyLayer GetRates error", err)
|
|
}
|
|
_, err = c.GetRates("USD", "AUD")
|
|
if areAPIKeysSet() && err != nil {
|
|
t.Error("test error - currencylayer GetRates() error", err)
|
|
} else if !areAPIKeysSet() && err == nil {
|
|
t.Error("test error - currencylayer GetRates() error cannot be nil")
|
|
}
|
|
}
|
|
|
|
func TestGetSupportedCurrencies(t *testing.T) {
|
|
err := setup()
|
|
if err != nil {
|
|
t.Fatal("Test Failed - CurrencyLayer GetSupportedCurrencies error", err)
|
|
}
|
|
_, err = c.GetSupportedCurrencies()
|
|
if areAPIKeysSet() && err != nil {
|
|
t.Error("test error - currencylayer GetSupportedCurrencies() error", err)
|
|
} else if !areAPIKeysSet() && err == nil {
|
|
t.Error("test error - currencylayer GetSupportedCurrencies() error cannot be nil")
|
|
}
|
|
}
|
|
|
|
func TestGetliveData(t *testing.T) {
|
|
err := setup()
|
|
if err != nil {
|
|
t.Fatal("Test Failed - CurrencyLayer GetliveData error", err)
|
|
}
|
|
_, err = c.GetliveData("AUD", "USD")
|
|
if areAPIKeysSet() && err != nil {
|
|
t.Error("test error - currencylayer GetliveData() error", err)
|
|
} else if !areAPIKeysSet() && err == nil {
|
|
t.Error("test error - currencylayer GetliveData() error cannot be nil")
|
|
}
|
|
}
|
|
|
|
func TestGetHistoricalData(t *testing.T) {
|
|
err := setup()
|
|
if err != nil {
|
|
t.Fatal("Test Failed - CurrencyLayer GetHistoricalData error", err)
|
|
}
|
|
_, err = c.GetHistoricalData("2016-12-15", []string{"AUD"}, "USD")
|
|
if areAPIKeysSet() && err != nil {
|
|
t.Error("test error - currencylayer GetHistoricalData() error", err)
|
|
} else if !areAPIKeysSet() && err == nil {
|
|
t.Error("test error - currencylayer GetHistoricalData() error cannot be nil")
|
|
}
|
|
}
|
|
|
|
func TestConvert(t *testing.T) {
|
|
err := setup()
|
|
if err != nil {
|
|
t.Fatal("Test Failed - CurrencyLayer Convert error", err)
|
|
}
|
|
_, err = c.Convert("USD", "AUD", "", 1)
|
|
if areAPIKeysSet() && err != nil && c.APIKeyLvl >= AccountBasic {
|
|
t.Error("test error - currencylayer Convert() error", err)
|
|
} else if !areAPIKeysSet() && err == nil {
|
|
t.Error("test error - currencylayer Convert() error cannot be nil")
|
|
}
|
|
}
|
|
|
|
func TestQueryTimeFrame(t *testing.T) {
|
|
err := setup()
|
|
if err != nil {
|
|
t.Fatal("Test Failed - CurrencyLayer QueryTimeFrame error", err)
|
|
}
|
|
_, err = c.QueryTimeFrame("2010-12-0", "2010-12-5", "USD", []string{"AUD"})
|
|
if areAPIKeysSet() && err != nil && c.APIKeyLvl >= AccountPro {
|
|
t.Error("test error - currencylayer QueryTimeFrame() error", err)
|
|
} else if !areAPIKeysSet() && err == nil {
|
|
t.Error("test error - currencylayer QueryTimeFrame() error cannot be nil")
|
|
}
|
|
}
|
|
|
|
func TestQueryCurrencyChange(t *testing.T) {
|
|
err := setup()
|
|
if err != nil {
|
|
t.Fatal("Test Failed - CurrencyLayer QueryCurrencyChange() error", err)
|
|
}
|
|
_, err = c.QueryCurrencyChange("2010-12-0", "2010-12-5", "USD", []string{"AUD"})
|
|
if areAPIKeysSet() && err != nil && c.APIKeyLvl == AccountEnterprise {
|
|
t.Error("test error - currencylayer QueryCurrencyChange() error", err)
|
|
} else if !areAPIKeysSet() && err == nil {
|
|
t.Error("test error - currencylayer QueryCurrencyChange() error cannot be nil")
|
|
}
|
|
}
|