forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]) | ||
} | ||
} |