mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-28 15:10:32 +00:00
* Attempts to update orderbook so it doesn't need to sort * Reverts the ws ob stuff. Gets rid of sorting because it happens later. Adds some exchange features * update existing feature lists. Expands list definition to match my emotions * Adds bithumb bitmex and bitstamp. adds a couple more types * Features for you, features for me, features for bittrex, btcmarkets, btse, coinbasepro, coinut, exmo, gateio and gemini * Features for hitbtc, huobi, itbit, kraken, lakebtc, lbank, localbitcoins, okcoin, okex, poloniex, yobit, zb * Who can forget good old alphapoint? * Adds btcmarksets websocket :glitch_crab: fixes alphapoint features * Adds extra data not in the documentation :/ * Replaces websocket features by using protocol features. However, it breaks it due to import cycles. I'm not sure what I'll do just yet * Removes import cycle via duplicate structs. * Increases coverage of config with `TestCheckCurrencyConfigValues`. Moves all currency pair package types into their own files or places it at the bottom of files if necessary * Increase coverage in code.go * One way of determining a test has failed, is when to it fails. Removed redundant explanation * Increases code coverage of conversion * Lint fixes * Fixes orderbook tests * Re-adds sorting because its important to still have the internal pre-processed orderbook to be representative of a real orderbook * Secret lints that did not show up via Windows linting * Adds protocol package to contain exchange features * Fixes protocol implementation * Fixes ws tests * Addresses the following: Removes st-st-stutters in config types, changes GetAvailableForexProviders -> GetSupportedForexProviders, removes errors from tests where error is nil, removes orderbook setup when not necessary, removes import newlines, removes false bools from declaration, changes should of to should have * imports and casing * Fixes two more nil error checks
138 lines
3.6 KiB
Go
138 lines
3.6 KiB
Go
package currencylayer
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/thrasher-corp/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("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("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("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("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("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("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("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")
|
|
}
|
|
}
|