Merge branch 'master' into engine

This commit is contained in:
Adrian Gallagher
2019-06-21 18:10:55 +10:00
87 changed files with 5669 additions and 992 deletions

View File

@@ -215,10 +215,11 @@ func (c *Config) PurgeExchangeAPICredentials() {
m.Lock()
defer m.Unlock()
for x := range c.Exchanges {
if !c.Exchanges[x].API.AuthenticatedSupport {
if !c.Exchanges[x].API.AuthenticatedSupport && !c.Exchanges[x].API.AuthenticatedWebsocketSupport {
continue
}
c.Exchanges[x].API.AuthenticatedSupport = false
c.Exchanges[x].API.AuthenticatedWebsocketSupport = false
if c.Exchanges[x].API.CredentialsValidator.RequiresKey {
c.Exchanges[x].API.Credentials.Key = DefaultAPIKey
@@ -838,6 +839,9 @@ func (c *Config) CheckExchangeConfigValues() error {
if c.Exchanges[i].APIKey != nil {
// It is, migrate settings to new format
c.Exchanges[i].API.AuthenticatedSupport = *c.Exchanges[i].AuthenticatedAPISupport
if c.Exchanges[i].AuthenticatedWebsocketAPISupport != nil {
c.Exchanges[i].API.AuthenticatedWebsocketSupport = *c.Exchanges[i].AuthenticatedWebsocketAPISupport
}
c.Exchanges[i].API.Credentials.Key = *c.Exchanges[i].APIKey
c.Exchanges[i].API.Credentials.Secret = *c.Exchanges[i].APISecret
@@ -862,6 +866,7 @@ func (c *Config) CheckExchangeConfigValues() error {
// Flush settings
c.Exchanges[i].AuthenticatedAPISupport = nil
c.Exchanges[i].AuthenticatedWebsocketAPISupport = nil
c.Exchanges[i].APIKey = nil
c.Exchanges[i].APIAuthPEMKey = nil
c.Exchanges[i].APISecret = nil
@@ -941,20 +946,23 @@ func (c *Config) CheckExchangeConfigValues() error {
c.Exchanges[i].Enabled = false
continue
}
if c.Exchanges[i].API.AuthenticatedSupport && c.Exchanges[i].API.CredentialsValidator != nil {
if (c.Exchanges[i].API.AuthenticatedSupport || c.Exchanges[i].API.AuthenticatedWebsocketSupport) && c.Exchanges[i].API.CredentialsValidator != nil {
var failed bool
if c.Exchanges[i].API.CredentialsValidator.RequiresKey && (c.Exchanges[i].API.Credentials.Key == "" || c.Exchanges[i].API.Credentials.Key == DefaultAPIKey) {
c.Exchanges[i].API.AuthenticatedSupport = false
failed = true
}
if c.Exchanges[i].API.CredentialsValidator.RequiresSecret && (c.Exchanges[i].API.Credentials.Secret == "" || c.Exchanges[i].API.Credentials.Secret == DefaultAPISecret) {
c.Exchanges[i].API.AuthenticatedSupport = false
failed = true
}
if c.Exchanges[i].API.CredentialsValidator.RequiresClientID && (c.Exchanges[i].API.Credentials.ClientID == DefaultAPIClientID || c.Exchanges[i].API.Credentials.ClientID == "") {
c.Exchanges[i].API.AuthenticatedSupport = false
failed = true
}
if !c.Exchanges[i].API.AuthenticatedSupport {
if failed {
c.Exchanges[i].API.AuthenticatedSupport = false
c.Exchanges[i].API.AuthenticatedWebsocketSupport = false
log.Warnf(WarningExchangeAuthAPIDefaultOrEmptyValues, c.Exchanges[i].Name)
}
}

View File

@@ -628,6 +628,7 @@ func TestUpdateExchangeConfig(t *testing.T) {
}
}
// TestCheckExchangeConfigValues logic test
func TestCheckExchangeConfigValues(t *testing.T) {
checkExchangeConfigValues := Config{}
@@ -651,25 +652,43 @@ func TestCheckExchangeConfigValues(t *testing.T) {
t.Fatalf("Test failed. Expected exchange %s to have updated HTTPTimeout value", checkExchangeConfigValues.Exchanges[0].Name)
}
v := &APICredentialsValidatorConfig{
RequiresKey: true,
RequiresSecret: true,
}
checkExchangeConfigValues.Exchanges[0].API.CredentialsValidator = v
checkExchangeConfigValues.Exchanges[0].API.Credentials.Key = "Key"
checkExchangeConfigValues.Exchanges[0].API.Credentials.Secret = "Secret"
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedSupport = true
err = checkExchangeConfigValues.CheckExchangeConfigValues()
if err != nil {
t.Errorf(
"Test failed. checkExchangeConfigValues.CheckExchangeConfigValues Error",
)
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedWebsocketSupport = true
checkExchangeConfigValues.CheckExchangeConfigValues()
if checkExchangeConfigValues.Exchanges[0].API.AuthenticatedSupport ||
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedWebsocketSupport {
t.Error("Expected authenticated endpoints to be false from invalid API keys")
}
v.RequiresKey = false
v.RequiresClientID = true
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedSupport = true
checkExchangeConfigValues.Exchanges[0].API.Credentials.Key = "TESTYTEST"
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedWebsocketSupport = true
checkExchangeConfigValues.Exchanges[0].API.Credentials.ClientID = DefaultAPIClientID
checkExchangeConfigValues.Exchanges[0].API.Credentials.Secret = "TESTYTEST"
checkExchangeConfigValues.Exchanges[0].Name = "ITBIT"
err = checkExchangeConfigValues.CheckExchangeConfigValues()
if err != nil {
t.Errorf(
"Test failed. checkExchangeConfigValues.CheckExchangeConfigValues Error",
)
checkExchangeConfigValues.CheckExchangeConfigValues()
if checkExchangeConfigValues.Exchanges[0].API.AuthenticatedSupport ||
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedWebsocketSupport {
t.Error("Expected AuthenticatedAPISupport to be false from invalid API keys")
}
v.RequiresKey = true
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedSupport = true
checkExchangeConfigValues.Exchanges[0].API.AuthenticatedWebsocketSupport = true
checkExchangeConfigValues.Exchanges[0].API.Credentials.Key = "meow"
checkExchangeConfigValues.Exchanges[0].API.Credentials.Secret = "test123"
checkExchangeConfigValues.Exchanges[0].API.Credentials.ClientID = "clientIDerino"
checkExchangeConfigValues.CheckExchangeConfigValues()
if !checkExchangeConfigValues.Exchanges[0].API.AuthenticatedSupport ||
!checkExchangeConfigValues.Exchanges[0].API.AuthenticatedWebsocketSupport {
t.Error("Expected AuthenticatedAPISupport and AuthenticatedWebsocketAPISupport to be false from invalid API keys")
}
checkExchangeConfigValues.Exchanges[0].Enabled = true

View File

@@ -61,23 +61,24 @@ type ExchangeConfig struct {
BankAccounts []BankAccount `json:"bankAccounts,omitempty"`
// Deprecated settings which will be removed in a future update
AvailablePairs *currency.Pairs `json:"availablePairs,omitempty"`
EnabledPairs *currency.Pairs `json:"enabledPairs,omitempty"`
AssetTypes *string `json:"assetTypes,omitempty"`
PairsLastUpdated *int64 `json:"pairsLastUpdated,omitempty"`
ConfigCurrencyPairFormat *currency.PairFormat `json:"configCurrencyPairFormat,omitempty"`
RequestCurrencyPairFormat *currency.PairFormat `json:"requestCurrencyPairFormat,omitempty"`
AuthenticatedAPISupport *bool `json:"authenticatedApiSupport,omitempty"`
APIKey *string `json:"apiKey,omitempty"`
APISecret *string `json:"apiSecret,omitempty"`
APIAuthPEMKeySupport *bool `json:"apiAuthPemKeySupport,omitempty"`
APIAuthPEMKey *string `json:"apiAuthPemKey,omitempty"`
APIURL *string `json:"apiUrl,omitempty"`
APIURLSecondary *string `json:"apiUrlSecondary,omitempty"`
ClientID *string `json:"clientId,omitempty"`
SupportsAutoPairUpdates *bool `json:"supportsAutoPairUpdates,omitempty"`
Websocket *bool `json:"websocket,omitempty"`
WebsocketURL *string `json:"websocketUrl,omitempty"`
AvailablePairs *currency.Pairs `json:"availablePairs,omitempty"`
EnabledPairs *currency.Pairs `json:"enabledPairs,omitempty"`
AssetTypes *string `json:"assetTypes,omitempty"`
PairsLastUpdated *int64 `json:"pairsLastUpdated,omitempty"`
ConfigCurrencyPairFormat *currency.PairFormat `json:"configCurrencyPairFormat,omitempty"`
RequestCurrencyPairFormat *currency.PairFormat `json:"requestCurrencyPairFormat,omitempty"`
AuthenticatedAPISupport *bool `json:"authenticatedApiSupport,omitempty"`
AuthenticatedWebsocketAPISupport *bool `json:"authenticatedWebsocketApiSupport,omitempty"`
APIKey *string `json:"apiKey,omitempty"`
APISecret *string `json:"apiSecret,omitempty"`
APIAuthPEMKeySupport *bool `json:"apiAuthPemKeySupport,omitempty"`
APIAuthPEMKey *string `json:"apiAuthPemKey,omitempty"`
APIURL *string `json:"apiUrl,omitempty"`
APIURLSecondary *string `json:"apiUrlSecondary,omitempty"`
ClientID *string `json:"clientId,omitempty"`
SupportsAutoPairUpdates *bool `json:"supportsAutoPairUpdates,omitempty"`
Websocket *bool `json:"websocket,omitempty"`
WebsocketURL *string `json:"websocketUrl,omitempty"`
}
// ProfilerConfig defines the profiler configuration to enable pprof
@@ -339,8 +340,9 @@ type APICredentialsValidatorConfig struct {
// APIConfig stores the exchange API config
type APIConfig struct {
AuthenticatedSupport bool `json:"authenticatedSupport"`
PEMKeySupport bool `json:"pemKeySupport,omitempty"`
AuthenticatedSupport bool `json:"authenticatedSupport"`
AuthenticatedWebsocketSupport bool `json:"authenticatedWebsocketApiSupport"`
PEMKeySupport bool `json:"pemKeySupport,omitempty"`
Endpoints APIEndpointsConfig `json:"endpoints"`
Credentials APICredentialsConfig `json:"credentials"`