diff --git a/config/config.go b/config/config.go index 011d2ac4011..0effc129363 100644 --- a/config/config.go +++ b/config/config.go @@ -842,9 +842,6 @@ func (c *Config) CheckExchangeConfigValues() error { exchanges := 0 for i := range c.Exchanges { e := &c.Exchanges[i] - if strings.EqualFold(e.Name, "GDAX") { - e.Name = "CoinbasePro" - } // Check to see if the old API storage format is used if e.APIKey != nil { diff --git a/config/versions/import.go b/config/versions/import.go index 87688878c78..c7c52a85b92 100644 --- a/config/versions/import.go +++ b/config/versions/import.go @@ -3,9 +3,11 @@ package versions import ( v0 "github.com/thrasher-corp/gocryptotrader/config/versions/v0" v1 "github.com/thrasher-corp/gocryptotrader/config/versions/v1" + v2 "github.com/thrasher-corp/gocryptotrader/config/versions/v2" ) func init() { Manager.registerVersion(&v0.Version{}) Manager.registerVersion(&v1.Version{}) + Manager.registerVersion(&v2.Version{}) } diff --git a/config/versions/v2/version.go b/config/versions/v2/version.go new file mode 100644 index 00000000000..3302ecac2dd --- /dev/null +++ b/config/versions/v2/version.go @@ -0,0 +1,36 @@ +// v2 is an ExchangeVersion to change the name of GDAX to CoinbasePro +package v2 + +import ( + "context" + + "github.com/buger/jsonparser" +) + +// Version implements ExchangeVersion +type Version struct{} + +const ( + from = "GDAX" + to = "CoinbasePro" +) + +// Exchanges returns just GDAX and CoinbasePro +func (v *Version) Exchanges() []string { return []string{from, to} } + +// UpgradeExchange will change the exchange name from GDAX to CoinbasePro +func (v *Version) UpgradeExchange(_ context.Context, e []byte) ([]byte, error) { + if n, err := jsonparser.GetString(e, "name"); err == nil && n == from { + return jsonparser.Set(e, []byte(`"`+to+`"`), "name") + } + return e, nil + +} + +// DowngradeExchange will change the exchange name from CoinbasePro to GDAX +func (v *Version) DowngradeExchange(_ context.Context, e []byte) ([]byte, error) { + if n, err := jsonparser.GetString(e, "name"); err == nil && n == to { + return jsonparser.Set(e, []byte(`"`+from+`"`), "name") + } + return e, nil +} diff --git a/config/versions/v2/version_test.go b/config/versions/v2/version_test.go new file mode 100644 index 00000000000..7511aaa60d4 --- /dev/null +++ b/config/versions/v2/version_test.go @@ -0,0 +1,37 @@ +package v2 + +import ( + "context" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestUpgrade(t *testing.T) { + t.Parallel() + for _, tt := range [][]string{ + {"GDAX", "CoinbasePro"}, + {"Kraken", "Kraken"}, + {"CoinbasePro", "CoinbasePro"}, + } { + out, err := new(Version).UpgradeExchange(context.Background(), []byte(`{"name":"`+tt[0]+`"}`)) + require.NoError(t, err) + require.NotEmpty(t, out) + assert.Equalf(t, `{"name":"`+tt[1]+`"}`, string(out), "Test exchange name %s", tt[0]) + } +} + +func TestDowngrade(t *testing.T) { + t.Parallel() + for _, tt := range [][]string{ + {"GDAX", "GDAX"}, + {"Kraken", "Kraken"}, + {"CoinbasePro", "GDAX"}, + } { + out, err := new(Version).DowngradeExchange(context.Background(), []byte(`{"name":"`+tt[0]+`"}`)) + require.NoError(t, err) + require.NotEmpty(t, out) + assert.Equalf(t, `{"name":"`+tt[1]+`"}`, string(out), "Test exchange name %s", tt[0]) + } +}