mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 15:09:42 +00:00
exchanges: Improve TestMain usage (#1946)
* exchanges: Improve TestMain usage * exchanges: Further cleanups * exchanges/kucoin: update TestProcessOrderbook to use test context * refactor: rename SetRunning to SetRunningURL for clarity across exchanges
This commit is contained in:
@@ -22,12 +22,17 @@ const (
|
|||||||
canManipulateRealOrders = false
|
canManipulateRealOrders = false
|
||||||
)
|
)
|
||||||
|
|
||||||
var a = &Alphapoint{}
|
var a *Alphapoint
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
a = new(Alphapoint)
|
||||||
a.SetDefaults()
|
a.SetDefaults()
|
||||||
a.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
|
||||||
a.API.AuthenticatedSupport = true
|
if apiKey != "" && apiSecret != "" {
|
||||||
|
a.API.AuthenticatedSupport = true
|
||||||
|
a.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ var mockTests = false
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
b = new(Binance)
|
b = new(Binance)
|
||||||
if err := testexch.Setup(b); err != nil {
|
if err := testexch.Setup(b); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Binance Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiKey != "" && apiSecret != "" {
|
if apiKey != "" && apiSecret != "" {
|
||||||
@@ -35,18 +35,16 @@ func TestMain(m *testing.M) {
|
|||||||
exchange.RestCoinMargined: testnetFutures,
|
exchange.RestCoinMargined: testnetFutures,
|
||||||
exchange.RestSpot: testnetSpotURL,
|
exchange.RestSpot: testnetSpotURL,
|
||||||
} {
|
} {
|
||||||
if err := b.API.Endpoints.SetRunning(k.String(), v); err != nil {
|
if err := b.API.Endpoints.SetRunningURL(k.String(), v); err != nil {
|
||||||
log.Fatalf("Testnet %q URL error with %q: %s", k, v, err)
|
log.Fatalf("Binance SetRunningURL error: %s", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
b.setupOrderbookManager(ctx)
|
|
||||||
b.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
b.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
||||||
log.Printf(sharedtestvalues.LiveTesting, b.Name)
|
log.Printf(sharedtestvalues.LiveTesting, b.Name)
|
||||||
if err := b.UpdateTradablePairs(ctx, true); err != nil {
|
if err := b.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||||
log.Fatal("Binance setup error", err)
|
log.Fatalf("Binance UpdateTradablePairs error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -22,17 +22,15 @@ func TestMain(m *testing.M) {
|
|||||||
|
|
||||||
b = new(Binance)
|
b = new(Binance)
|
||||||
if err := testexch.Setup(b); err != nil {
|
if err := testexch.Setup(b); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Binance Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := testexch.MockHTTPInstance(b); err != nil {
|
if err := testexch.MockHTTPInstance(b); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Binance MockHTTPInstance error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
if err := b.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||||
b.setupOrderbookManager(ctx)
|
log.Fatalf("Binance UpdateTradablePairs error: %s", err)
|
||||||
if err := b.UpdateTradablePairs(ctx, true); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package binanceus
|
package binanceus
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
reflects "reflect"
|
reflects "reflect"
|
||||||
@@ -12,7 +11,6 @@ import (
|
|||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
"github.com/thrasher-corp/gocryptotrader/encoding/json"
|
||||||
@@ -33,35 +31,25 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bi = &Binanceus{}
|
bi *Binanceus
|
||||||
testPairMapping = currency.NewBTCUSDT()
|
testPairMapping = currency.NewBTCUSDT()
|
||||||
// this lock guards against orderbook tests race
|
// this lock guards against orderbook tests race
|
||||||
binanceusOrderBookLock = &sync.Mutex{}
|
binanceusOrderBookLock = &sync.Mutex{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
bi = new(Binanceus)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(bi); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Binanceus Setup error: %s", err)
|
||||||
log.Fatal("Binanceus load config error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exchCfg, err := cfg.GetExchangeConfig("Binanceus")
|
if apiKey != "" && apiSecret != "" {
|
||||||
if err != nil {
|
bi.API.AuthenticatedSupport = true
|
||||||
log.Fatal(err)
|
bi.API.AuthenticatedWebsocketSupport = true
|
||||||
|
bi.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
}
|
}
|
||||||
exchCfg.API.AuthenticatedSupport = true
|
|
||||||
exchCfg.API.AuthenticatedWebsocketSupport = true
|
|
||||||
exchCfg.API.Credentials.Key = apiKey
|
|
||||||
exchCfg.API.Credentials.Secret = apiSecret
|
|
||||||
bi.SetDefaults()
|
|
||||||
bi.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
bi.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
bi.WebsocketResponseMaxLimit = exchange.DefaultWebsocketResponseMaxLimit
|
||||||
err = bi.Setup(exchCfg)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Binanceus TestMain()", err)
|
|
||||||
}
|
|
||||||
bi.setupOrderbookManager(context.Background())
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,21 +44,14 @@ var (
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
b = new(Bitfinex)
|
b = new(Bitfinex)
|
||||||
if err := testexch.Setup(b); err != nil {
|
if err := testexch.Setup(b); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Bitfinex Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiKey != "" {
|
if apiKey != "" && apiSecret != "" {
|
||||||
b.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
b.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
||||||
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
|
||||||
}
|
|
||||||
|
|
||||||
if !b.Enabled || len(b.BaseCurrencies) < 1 {
|
|
||||||
log.Fatal("Bitfinex Setup values not set correctly")
|
|
||||||
}
|
|
||||||
|
|
||||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
|
||||||
b.API.AuthenticatedSupport = true
|
b.API.AuthenticatedSupport = true
|
||||||
b.API.AuthenticatedWebsocketSupport = true
|
b.API.AuthenticatedWebsocketSupport = true
|
||||||
|
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -27,26 +26,17 @@ const (
|
|||||||
canManipulateRealOrders = false
|
canManipulateRealOrders = false
|
||||||
)
|
)
|
||||||
|
|
||||||
var b = &Bitflyer{}
|
var b *Bitflyer
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
b = new(Bitflyer)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(b); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Bitflyer Setup error: %s", err)
|
||||||
log.Fatal("Bitflyer load config error", err)
|
|
||||||
}
|
|
||||||
bitflyerConfig, err := cfg.GetExchangeConfig("Bitflyer")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("bitflyer Setup() init error")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bitflyerConfig.API.AuthenticatedSupport = true
|
if apiKey != "" && apiSecret != "" {
|
||||||
bitflyerConfig.API.Credentials.Key = apiKey
|
b.API.AuthenticatedSupport = true
|
||||||
bitflyerConfig.API.Credentials.Secret = apiSecret
|
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
b.SetDefaults()
|
|
||||||
err = b.Setup(bitflyerConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Bitflyer setup error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/key"
|
"github.com/thrasher-corp/gocryptotrader/common/key"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
||||||
@@ -36,29 +35,20 @@ const (
|
|||||||
canManipulateRealOrders = false
|
canManipulateRealOrders = false
|
||||||
)
|
)
|
||||||
|
|
||||||
var b = &Bitmex{}
|
var b *Bitmex
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
b.SetDefaults()
|
b = new(Bitmex)
|
||||||
cfg := config.GetConfig()
|
if err := testexch.Setup(b); err != nil {
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
log.Fatalf("Bitmex Setup error: %s", err)
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Bitmex load config error", err)
|
|
||||||
}
|
|
||||||
bitmexConfig, err := cfg.GetExchangeConfig("Bitmex")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Bitmex Setup() init error")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bitmexConfig.API.AuthenticatedSupport = true
|
if apiKey != "" && apiSecret != "" {
|
||||||
bitmexConfig.API.AuthenticatedWebsocketSupport = true
|
b.API.AuthenticatedSupport = true
|
||||||
bitmexConfig.API.Credentials.Key = apiKey
|
b.API.AuthenticatedWebsocketSupport = true
|
||||||
bitmexConfig.API.Credentials.Secret = apiSecret
|
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
b.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = b.Setup(bitmexConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Bitmex setup error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -486,7 +476,7 @@ func TestGetActiveOrders(t *testing.T) {
|
|||||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -503,7 +493,7 @@ func TestGetOrderHistory(t *testing.T) {
|
|||||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -532,7 +522,7 @@ func TestSubmitOrder(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, order.New, response.Status)
|
assert.Equal(t, order.New, response.Status)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +542,7 @@ func TestCancelExchangeOrder(t *testing.T) {
|
|||||||
if sharedtestvalues.AreAPICredentialsSet(b) {
|
if sharedtestvalues.AreAPICredentialsSet(b) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,7 +563,7 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, resp.Status, "CancelAllOrders must not fail to cancel orders")
|
require.Empty(t, resp.Status, "CancelAllOrders must not fail to cancel orders")
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,37 +9,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||||
|
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mockTests = false
|
var mockTests = false
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
b = new(Bitstamp)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(b); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Bitstamp Setup error: %s", err)
|
||||||
log.Fatal("Bitstamp load config error", err)
|
|
||||||
}
|
}
|
||||||
bitstampConfig, err := cfg.GetExchangeConfig("Bitstamp")
|
if apiKey != "" && apiSecret != "" {
|
||||||
if err != nil {
|
b.API.AuthenticatedSupport = true
|
||||||
log.Fatal("Bitstamp Setup() init error", err)
|
b.SetCredentials(apiKey, apiSecret, customerID, "", "", "")
|
||||||
}
|
|
||||||
bitstampConfig.API.AuthenticatedSupport = true
|
|
||||||
if apiKey != "" {
|
|
||||||
bitstampConfig.API.Credentials.Key = apiKey
|
|
||||||
}
|
|
||||||
if apiSecret != "" {
|
|
||||||
bitstampConfig.API.Credentials.Secret = apiSecret
|
|
||||||
}
|
|
||||||
if customerID != "" {
|
|
||||||
bitstampConfig.API.Credentials.ClientID = customerID
|
|
||||||
}
|
|
||||||
b.SetDefaults()
|
|
||||||
b.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = b.Setup(bitstampConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Bitstamp setup error", err)
|
|
||||||
}
|
}
|
||||||
log.Printf(sharedtestvalues.LiveTesting, b.Name)
|
log.Printf(sharedtestvalues.LiveTesting, b.Name)
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -9,59 +9,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/mock"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const mockfile = "../../testdata/http_mock/bitstamp/bitstamp.json"
|
|
||||||
|
|
||||||
var mockTests = true
|
var mockTests = true
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
b = new(Bitstamp)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(b); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Bitstamp Setup error: %s", err)
|
||||||
log.Fatal("Bitstamp load config error", err)
|
|
||||||
}
|
|
||||||
bitstampConfig, err := cfg.GetExchangeConfig("Bitstamp")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Bitstamp Setup() init error", err)
|
|
||||||
}
|
|
||||||
b.SkipAuthCheck = true
|
|
||||||
bitstampConfig.API.AuthenticatedSupport = true
|
|
||||||
if apiKey != "" {
|
|
||||||
bitstampConfig.API.Credentials.Key = apiKey
|
|
||||||
}
|
|
||||||
if apiSecret != "" {
|
|
||||||
bitstampConfig.API.Credentials.Secret = apiSecret
|
|
||||||
}
|
|
||||||
if customerID != "" {
|
|
||||||
bitstampConfig.API.Credentials.ClientID = customerID
|
|
||||||
}
|
|
||||||
b.SetDefaults()
|
|
||||||
b.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = b.Setup(bitstampConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Bitstamp setup error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
|
if err := testexch.MockHTTPInstance(b, "api"); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Bitstamp MockHTTPInstance error: %s", err)
|
||||||
log.Fatalf("Mock server error %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = b.SetHTTPClient(newClient)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Mock server error %s", err)
|
|
||||||
}
|
|
||||||
endpointMap := b.API.Endpoints.GetURLMap()
|
|
||||||
for k := range endpointMap {
|
|
||||||
err = b.API.Endpoints.SetRunning(k, serverDetails+"/api")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Printf(sharedtestvalues.MockTesting, b.Name)
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package btcmarkets
|
package btcmarkets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -11,7 +9,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/asset"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/kline"
|
||||||
@@ -36,30 +33,17 @@ const (
|
|||||||
var spotTestPair = currency.NewPair(currency.BTC, currency.AUD).Format(currency.PairFormat{Uppercase: true, Delimiter: currency.DashDelimiter})
|
var spotTestPair = currency.NewPair(currency.BTC, currency.AUD).Format(currency.PairFormat{Uppercase: true, Delimiter: currency.DashDelimiter})
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
b.SetDefaults()
|
b = new(BTCMarkets)
|
||||||
cfg := config.GetConfig()
|
if err := testexch.Setup(b); err != nil {
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
log.Fatalf("BTCMarkets Setup error: %s", err)
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
bConfig, err := cfg.GetExchangeConfig("BTC Markets")
|
|
||||||
if err != nil {
|
if apiKey != "" && apiSecret != "" {
|
||||||
log.Fatal(err)
|
b.API.AuthenticatedSupport = true
|
||||||
}
|
b.API.AuthenticatedWebsocketSupport = true
|
||||||
bConfig.API.Credentials.Key = apiKey
|
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
bConfig.API.Credentials.Secret = apiSecret
|
|
||||||
bConfig.API.AuthenticatedSupport = true
|
|
||||||
b.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = b.Setup(bConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
err = b.ValidateAPICredentials(context.Background(), asset.Spot)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Println("API credentials are invalid:", err)
|
|
||||||
b.API.AuthenticatedSupport = false
|
|
||||||
b.API.AuthenticatedWebsocketSupport = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/key"
|
"github.com/thrasher-corp/gocryptotrader/common/key"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -35,28 +34,20 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
b = &BTSE{}
|
b *BTSE
|
||||||
futuresPair = currency.NewPair(currency.ENJ, currency.PFC)
|
futuresPair = currency.NewPair(currency.ENJ, currency.PFC)
|
||||||
spotPair = currency.NewPairWithDelimiter("BTC", "USD", "-")
|
spotPair = currency.NewPairWithDelimiter("BTC", "USD", "-")
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
b.SetDefaults()
|
b = new(BTSE)
|
||||||
cfg := config.GetConfig()
|
if err := testexch.Setup(b); err != nil {
|
||||||
if err := cfg.LoadConfig("../../testdata/configtest.json", true); err != nil {
|
log.Fatalf("BTSE Setup error: %s", err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
btseConfig, err := cfg.GetExchangeConfig("BTSE")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
btseConfig.API.AuthenticatedSupport = true
|
if apiKey != "" && apiSecret != "" {
|
||||||
btseConfig.API.Credentials.Key = apiKey
|
b.API.AuthenticatedSupport = true
|
||||||
btseConfig.API.Credentials.Secret = apiSecret
|
b.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
b.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
if err = b.Setup(btseConfig); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ var mockTests = false
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
b = new(Bybit)
|
b = new(Bybit)
|
||||||
if err := testexch.Setup(b); err != nil {
|
if err := testexch.Setup(b); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Bybit Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiKey != "" && apiSecret != "" {
|
if apiKey != "" && apiSecret != "" {
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ var mockTests = true
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
b = new(Bybit)
|
b = new(Bybit)
|
||||||
if err := testexch.Setup(b); err != nil {
|
if err := testexch.Setup(b); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Bybit Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b.SetCredentials("mock", "tester", "", "", "", "") // Hack for UpdateAccountInfo test
|
b.SetCredentials("mock", "tester", "", "", "", "") // Hack for UpdateAccountInfo test
|
||||||
|
|
||||||
if err := testexch.MockHTTPInstance(b); err != nil {
|
if err := testexch.MockHTTPInstance(b); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Bybit MockHTTPInstance error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := b.UpdateTradablePairs(context.Background(), true); err != nil {
|
if err := b.UpdateTradablePairs(context.Background(), true); err != nil {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
c = &CoinbasePro{}
|
c *CoinbasePro
|
||||||
testPair = currency.NewPairWithDelimiter(currency.BTC.String(), currency.USD.String(), "-")
|
testPair = currency.NewPairWithDelimiter(currency.BTC.String(), currency.USD.String(), "-")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
||||||
@@ -26,7 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
c = &COINUT{}
|
c *COINUT
|
||||||
wsSetupRan bool
|
wsSetupRan bool
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,29 +37,21 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
c.SetDefaults()
|
c = new(COINUT)
|
||||||
cfg := config.GetConfig()
|
if err := testexch.Setup(c); err != nil {
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
log.Fatalf("Coinut Setup error: %s", err)
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Coinut load config error", err)
|
|
||||||
}
|
}
|
||||||
coinutCfg, err := cfg.GetExchangeConfig("COINUT")
|
|
||||||
if err != nil {
|
if apiKey != "" && clientID != "" {
|
||||||
log.Fatal("Coinut Setup() init error")
|
c.API.AuthenticatedSupport = true
|
||||||
|
c.API.AuthenticatedWebsocketSupport = true
|
||||||
|
c.SetCredentials(apiKey, clientID, "", "", "", "")
|
||||||
}
|
}
|
||||||
coinutCfg.API.AuthenticatedSupport = true
|
|
||||||
coinutCfg.API.AuthenticatedWebsocketSupport = true
|
if err := c.SeedInstruments(context.Background()); err != nil {
|
||||||
coinutCfg.API.Credentials.Key = apiKey
|
log.Fatalf("Coinut SeedInstruments error: %s", err)
|
||||||
coinutCfg.API.Credentials.ClientID = clientID
|
|
||||||
c.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = c.Setup(coinutCfg)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Coinut setup error", err)
|
|
||||||
}
|
|
||||||
err = c.SeedInstruments(context.Background())
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Coinut setup error ", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,9 +52,8 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
err := testexch.Setup(d)
|
if err := testexch.Setup(d); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Deribit Setup error: %s", err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiKey != "" && apiSecret != "" {
|
if apiKey != "" && apiSecret != "" {
|
||||||
@@ -65,15 +64,13 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
if useTestNet {
|
if useTestNet {
|
||||||
deribitWebsocketAddress = "wss://test.deribit.com/ws" + deribitAPIVersion
|
deribitWebsocketAddress = "wss://test.deribit.com/ws" + deribitAPIVersion
|
||||||
err = d.Websocket.SetWebsocketURL(deribitWebsocketAddress, false, true)
|
if err := d.Websocket.SetWebsocketURL(deribitWebsocketAddress, false, true); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Deribit SetWebsocketURL error: %s", err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
for k, v := range d.API.Endpoints.GetURLMap() {
|
for k, v := range d.API.Endpoints.GetURLMap() {
|
||||||
v = strings.Replace(v, "www.deribit.com", "test.deribit.com", 1)
|
v = strings.Replace(v, "www.deribit.com", "test.deribit.com", 1)
|
||||||
err = d.API.Endpoints.SetRunning(k, v)
|
if err := d.API.Endpoints.SetRunningURL(k, v); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Deribit SetRunningURL error: %s", err)
|
||||||
log.Fatal(err)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -804,21 +804,21 @@ func (b *Base) SetAPIURL() error {
|
|||||||
var err error
|
var err error
|
||||||
if b.Config.API.OldEndPoints != nil {
|
if b.Config.API.OldEndPoints != nil {
|
||||||
if b.Config.API.OldEndPoints.URL != "" && b.Config.API.OldEndPoints.URL != config.APIURLNonDefaultMessage {
|
if b.Config.API.OldEndPoints.URL != "" && b.Config.API.OldEndPoints.URL != config.APIURLNonDefaultMessage {
|
||||||
err = b.API.Endpoints.SetRunning(RestSpot.String(), b.Config.API.OldEndPoints.URL)
|
err = b.API.Endpoints.SetRunningURL(RestSpot.String(), b.Config.API.OldEndPoints.URL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
checkInsecureEndpoint(b.Config.API.OldEndPoints.URL)
|
checkInsecureEndpoint(b.Config.API.OldEndPoints.URL)
|
||||||
}
|
}
|
||||||
if b.Config.API.OldEndPoints.URLSecondary != "" && b.Config.API.OldEndPoints.URLSecondary != config.APIURLNonDefaultMessage {
|
if b.Config.API.OldEndPoints.URLSecondary != "" && b.Config.API.OldEndPoints.URLSecondary != config.APIURLNonDefaultMessage {
|
||||||
err = b.API.Endpoints.SetRunning(RestSpotSupplementary.String(), b.Config.API.OldEndPoints.URLSecondary)
|
err = b.API.Endpoints.SetRunningURL(RestSpotSupplementary.String(), b.Config.API.OldEndPoints.URLSecondary)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
checkInsecureEndpoint(b.Config.API.OldEndPoints.URLSecondary)
|
checkInsecureEndpoint(b.Config.API.OldEndPoints.URLSecondary)
|
||||||
}
|
}
|
||||||
if b.Config.API.OldEndPoints.WebsocketURL != "" && b.Config.API.OldEndPoints.WebsocketURL != config.WebsocketURLNonDefaultMessage {
|
if b.Config.API.OldEndPoints.WebsocketURL != "" && b.Config.API.OldEndPoints.WebsocketURL != config.WebsocketURLNonDefaultMessage {
|
||||||
err = b.API.Endpoints.SetRunning(WebsocketSpot.String(), b.Config.API.OldEndPoints.WebsocketURL)
|
err = b.API.Endpoints.SetRunningURL(WebsocketSpot.String(), b.Config.API.OldEndPoints.WebsocketURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -865,7 +865,7 @@ func (b *Base) SetAPIURL() error {
|
|||||||
|
|
||||||
checkInsecureEndpoint(val)
|
checkInsecureEndpoint(val)
|
||||||
|
|
||||||
err = b.API.Endpoints.SetRunning(key, val)
|
err = b.API.Endpoints.SetRunningURL(key, val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1242,7 +1242,7 @@ func (b *Base) NewEndpoints() *Endpoints {
|
|||||||
// SetDefaultEndpoints declares and sets the default URLs map
|
// SetDefaultEndpoints declares and sets the default URLs map
|
||||||
func (e *Endpoints) SetDefaultEndpoints(m map[URL]string) error {
|
func (e *Endpoints) SetDefaultEndpoints(m map[URL]string) error {
|
||||||
for k, v := range m {
|
for k, v := range m {
|
||||||
err := e.SetRunning(k.String(), v)
|
err := e.SetRunningURL(k.String(), v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1250,8 +1250,8 @@ func (e *Endpoints) SetDefaultEndpoints(m map[URL]string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetRunning populates running URLs map
|
// SetRunningURL populates running URLs map
|
||||||
func (e *Endpoints) SetRunning(key, val string) error {
|
func (e *Endpoints) SetRunningURL(key, val string) error {
|
||||||
e.mu.Lock()
|
e.mu.Lock()
|
||||||
defer e.mu.Unlock()
|
defer e.mu.Unlock()
|
||||||
err := validateKey(key)
|
err := validateKey(key)
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ func TestSet(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
err = b.API.Endpoints.SetRunning(EdgeCase2.String(), "http://google.com/")
|
err = b.API.Endpoints.SetRunningURL(EdgeCase2.String(), "http://google.com/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@@ -102,7 +102,7 @@ func TestSet(t *testing.T) {
|
|||||||
if val != "http://google.com/" {
|
if val != "http://google.com/" {
|
||||||
t.Errorf("vals didn't match. expecting: %s, got: %s\n", "http://google.com/", val)
|
t.Errorf("vals didn't match. expecting: %s, got: %s\n", "http://google.com/", val)
|
||||||
}
|
}
|
||||||
err = b.API.Endpoints.SetRunning(EdgeCase3.String(), "Added Edgecase3")
|
err = b.API.Endpoints.SetRunningURL(EdgeCase3.String(), "Added Edgecase3")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("not expecting an error since invalid url val err should be logged but received: %v", err)
|
t.Errorf("not expecting an error since invalid url val err should be logged but received: %v", err)
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ func TestGetURL(t *testing.T) {
|
|||||||
if getVal != "http://test1.com/" {
|
if getVal != "http://test1.com/" {
|
||||||
t.Errorf("getVal failed")
|
t.Errorf("getVal failed")
|
||||||
}
|
}
|
||||||
err = b.API.Endpoints.SetRunning(EdgeCase2.String(), "http://OVERWRITTENBRO.com.au/")
|
err = b.API.Endpoints.SetRunningURL(EdgeCase2.String(), "http://OVERWRITTENBRO.com.au/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
@@ -1827,12 +1827,12 @@ func TestSetAPIURL(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetRunning(t *testing.T) {
|
func TestSetRunningURL(t *testing.T) {
|
||||||
b := Base{
|
b := Base{
|
||||||
Name: "HELOOOOOOOO",
|
Name: "HELOOOOOOOO",
|
||||||
}
|
}
|
||||||
b.API.Endpoints = b.NewEndpoints()
|
b.API.Endpoints = b.NewEndpoints()
|
||||||
err := b.API.Endpoints.SetRunning(EdgeCase1.String(), "http://google.com/")
|
err := b.API.Endpoints.SetRunningURL(EdgeCase1.String(), "http://google.com/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -28,29 +27,21 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
e = &EXMO{}
|
e *EXMO
|
||||||
testPair = currency.NewBTCUSD().Format(currency.PairFormat{Uppercase: true, Delimiter: "_"})
|
testPair = currency.NewBTCUSD().Format(currency.PairFormat{Uppercase: true, Delimiter: "_"})
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
e.SetDefaults()
|
e = new(EXMO)
|
||||||
cfg := config.GetConfig()
|
if err := testexch.Setup(e); err != nil {
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
log.Fatalf("EXMO Setup error: %s", err)
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Exmo load config error", err)
|
|
||||||
}
|
|
||||||
exmoConf, err := cfg.GetExchangeConfig("EXMO")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Exmo Setup() init error")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = e.Setup(exmoConf)
|
if APIKey != "" && APISecret != "" {
|
||||||
if err != nil {
|
e.API.AuthenticatedSupport = true
|
||||||
log.Fatal("Exmo setup error", err)
|
e.SetCredentials(APIKey, APISecret, "", "", "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
e.API.AuthenticatedSupport = true
|
|
||||||
e.SetCredentials(APIKey, APISecret, "", "", "", "")
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ var g *Gateio
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
g = new(Gateio)
|
g = new(Gateio)
|
||||||
if err := testexch.Setup(g); err != nil {
|
if err := testexch.Setup(g); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Gateio Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiKey != "" && apiSecret != "" {
|
if apiKey != "" && apiSecret != "" {
|
||||||
|
|||||||
@@ -9,35 +9,24 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||||
|
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mockTests = false
|
var mockTests = false
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
g = new(Gemini)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(g); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Gemini Setup error: %s", err)
|
||||||
log.Fatal("Gemini load config error", err)
|
|
||||||
}
|
}
|
||||||
geminiConfig, err := cfg.GetExchangeConfig("Gemini")
|
if apiKey != "" && apiSecret != "" {
|
||||||
if err != nil {
|
g.API.AuthenticatedSupport = true
|
||||||
log.Fatal("Gemini Setup() init error", err)
|
g.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
}
|
}
|
||||||
geminiConfig.API.AuthenticatedSupport = true
|
if err := g.API.Endpoints.SetRunningURL(exchange.RestSpot.String(), geminiAPIURL); err != nil {
|
||||||
geminiConfig.API.Credentials.Key = apiKey
|
log.Fatalf("Gemini SetRunningURL error: %s", err)
|
||||||
geminiConfig.API.Credentials.Secret = apiSecret
|
|
||||||
g.SetDefaults()
|
|
||||||
g.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = g.Setup(geminiConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Gemini setup error", err)
|
|
||||||
}
|
|
||||||
err = g.API.Endpoints.SetRunning(exchange.RestSpot.String(), geminiAPIURL)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("endpoint setting failed. key: %s, val: %s", exchange.RestSpot.String(), geminiAPIURL)
|
|
||||||
}
|
}
|
||||||
log.Printf(sharedtestvalues.LiveTesting, g.Name)
|
log.Printf(sharedtestvalues.LiveTesting, g.Name)
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -9,52 +9,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/mock"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const mockFile = "../../testdata/http_mock/gemini/gemini.json"
|
|
||||||
|
|
||||||
var mockTests = true
|
var mockTests = true
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
g = new(Gemini)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(g); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Gemini Setup error: %s", err)
|
||||||
log.Fatal("Gemini load config error", err)
|
|
||||||
}
|
|
||||||
geminiConfig, err := cfg.GetExchangeConfig("Gemini")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Mock server error", err)
|
|
||||||
}
|
|
||||||
g.SkipAuthCheck = true
|
|
||||||
geminiConfig.API.AuthenticatedSupport = true
|
|
||||||
geminiConfig.API.Credentials.Key = apiKey
|
|
||||||
geminiConfig.API.Credentials.Secret = apiSecret
|
|
||||||
g.SetDefaults()
|
|
||||||
g.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = g.Setup(geminiConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Gemini setup error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serverDetails, newClient, err := mock.NewVCRServer(mockFile)
|
if err := testexch.MockHTTPInstance(g); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Gemini MockHTTPInstance error: %s", err)
|
||||||
log.Fatalf("Mock server error %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = g.SetHTTPClient(newClient)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Mock server error %s", err)
|
|
||||||
}
|
|
||||||
endpointMap := g.API.Endpoints.GetURLMap()
|
|
||||||
for k := range endpointMap {
|
|
||||||
err = g.API.Endpoints.SetRunning(k, serverDetails)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Printf(sharedtestvalues.MockTesting, g.Name)
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -552,7 +552,7 @@ func TestGetDepositAddress(t *testing.T) {
|
|||||||
// TestWsAuth dials websocket, sends login request.
|
// TestWsAuth dials websocket, sends login request.
|
||||||
func TestWsAuth(t *testing.T) {
|
func TestWsAuth(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
err := g.API.Endpoints.SetRunning(exchange.WebsocketSpot.String(), geminiWebsocketSandboxEndpoint)
|
err := g.API.Endpoints.SetRunningURL(exchange.WebsocketSpot.String(), geminiWebsocketSandboxEndpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -128,7 +128,7 @@ func (g *Gemini) Setup(exch *config.Exchange) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if exch.UseSandbox {
|
if exch.UseSandbox {
|
||||||
err = g.API.Endpoints.SetRunning(exchange.RestSpot.String(), geminiSandboxAPIURL)
|
err = g.API.Endpoints.SetRunningURL(exchange.RestSpot.String(), geminiSandboxAPIURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorln(log.ExchangeSys, err)
|
log.Errorln(log.ExchangeSys, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
||||||
@@ -28,7 +27,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
h = &HitBTC{}
|
h *HitBTC
|
||||||
wsSetupRan bool
|
wsSetupRan bool
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -42,29 +41,19 @@ const (
|
|||||||
var spotPair = currency.NewBTCUSD().Format(currency.PairFormat{Uppercase: true})
|
var spotPair = currency.NewBTCUSD().Format(currency.PairFormat{Uppercase: true})
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
h.SetDefaults()
|
h = new(HitBTC)
|
||||||
cfg := config.GetConfig()
|
if err := testexch.Setup(h); err != nil {
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
log.Fatalf("HitBTC Setup error: %s", err)
|
||||||
if err != nil {
|
|
||||||
log.Fatal("HitBTC load config error", err)
|
|
||||||
}
|
|
||||||
hitbtcConfig, err := cfg.GetExchangeConfig("HitBTC")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("HitBTC Setup() init error")
|
|
||||||
}
|
|
||||||
hitbtcConfig.API.AuthenticatedSupport = true
|
|
||||||
hitbtcConfig.API.AuthenticatedWebsocketSupport = true
|
|
||||||
hitbtcConfig.API.Credentials.Key = apiKey
|
|
||||||
hitbtcConfig.API.Credentials.Secret = apiSecret
|
|
||||||
h.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = h.Setup(hitbtcConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("HitBTC setup error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.UpdateTradablePairs(context.Background(), false)
|
if apiKey != "" && apiSecret != "" {
|
||||||
if err != nil {
|
h.API.AuthenticatedSupport = true
|
||||||
log.Fatal("HitBTC setup error", err)
|
h.API.AuthenticatedWebsocketSupport = true
|
||||||
|
h.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := h.UpdateTradablePairs(context.Background(), false); err != nil {
|
||||||
|
log.Fatalf("HitBTC UpdateTradablePairs error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common/key"
|
"github.com/thrasher-corp/gocryptotrader/common/key"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
"github.com/thrasher-corp/gocryptotrader/exchange/websocket"
|
||||||
@@ -46,7 +45,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
h = &HUOBI{}
|
h *HUOBI
|
||||||
btcFutureDatedPair currency.Pair
|
btcFutureDatedPair currency.Pair
|
||||||
btccwPair = currency.NewPair(currency.BTC, currency.NewCode("CW"))
|
btccwPair = currency.NewPair(currency.BTC, currency.NewCode("CW"))
|
||||||
btcusdPair = currency.NewPairWithDelimiter("BTC", "USD", "-")
|
btcusdPair = currency.NewPairWithDelimiter("BTC", "USD", "-")
|
||||||
@@ -55,25 +54,17 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
h.SetDefaults()
|
h = new(HUOBI)
|
||||||
cfg := config.GetConfig()
|
if err := testexch.Setup(h); err != nil {
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
log.Fatalf("HUOBI Setup error: %s", err)
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Huobi load config error", err)
|
|
||||||
}
|
}
|
||||||
hConfig, err := cfg.GetExchangeConfig("Huobi")
|
|
||||||
if err != nil {
|
if apiKey != "" && apiSecret != "" {
|
||||||
log.Fatal("Huobi Setup() init error")
|
h.API.AuthenticatedSupport = true
|
||||||
}
|
h.API.AuthenticatedWebsocketSupport = true
|
||||||
hConfig.API.AuthenticatedSupport = true
|
h.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
hConfig.API.AuthenticatedWebsocketSupport = true
|
|
||||||
hConfig.API.Credentials.Key = apiKey
|
|
||||||
hConfig.API.Credentials.Secret = apiSecret
|
|
||||||
h.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = h.Setup(hConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Huobi setup error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1160,7 +1151,7 @@ func TestGetActiveOrders(t *testing.T) {
|
|||||||
if sharedtestvalues.AreAPICredentialsSet(h) {
|
if sharedtestvalues.AreAPICredentialsSet(h) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1271,7 +1262,7 @@ func TestQueryDepositAddress(t *testing.T) {
|
|||||||
if sharedtestvalues.AreAPICredentialsSet(h) {
|
if sharedtestvalues.AreAPICredentialsSet(h) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1281,7 +1272,7 @@ func TestGetDepositAddress(t *testing.T) {
|
|||||||
if sharedtestvalues.AreAPICredentialsSet(h) {
|
if sharedtestvalues.AreAPICredentialsSet(h) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1291,7 +1282,7 @@ func TestQueryWithdrawQuota(t *testing.T) {
|
|||||||
if sharedtestvalues.AreAPICredentialsSet(h) {
|
if sharedtestvalues.AreAPICredentialsSet(h) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
} else {
|
} else {
|
||||||
require.ErrorIs(t, err, exchange.ErrCredentialsAreEmpty)
|
require.ErrorIs(t, err, exchange.ErrAuthenticationSupportNotEnabled)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ const (
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
k = new(Kraken)
|
k = new(Kraken)
|
||||||
if err := testexch.Setup(k); err != nil {
|
if err := testexch.Setup(k); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Kraken Setup error: %s", err)
|
||||||
}
|
}
|
||||||
if apiKey != "" && apiSecret != "" {
|
if apiKey != "" && apiSecret != "" {
|
||||||
k.API.AuthenticatedSupport = true
|
k.API.AuthenticatedSupport = true
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ var (
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
ku = new(Kucoin)
|
ku = new(Kucoin)
|
||||||
if err := testexch.Setup(ku); err != nil {
|
if err := testexch.Setup(ku); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Kucoin Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiKey != "" && apiSecret != "" && passPhrase != "" {
|
if apiKey != "" && apiSecret != "" && passPhrase != "" {
|
||||||
@@ -64,14 +64,12 @@ func TestMain(m *testing.M) {
|
|||||||
ku.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
ku.Websocket.SetCanUseAuthenticatedEndpoints(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
getFirstTradablePairOfAssets(context.Background())
|
||||||
getFirstTradablePairOfAssets(ctx)
|
|
||||||
assertToTradablePairMap = map[asset.Item]currency.Pair{
|
assertToTradablePairMap = map[asset.Item]currency.Pair{
|
||||||
asset.Spot: spotTradablePair,
|
asset.Spot: spotTradablePair,
|
||||||
asset.Margin: marginTradablePair,
|
asset.Margin: marginTradablePair,
|
||||||
asset.Futures: futuresTradablePair,
|
asset.Futures: futuresTradablePair,
|
||||||
}
|
}
|
||||||
ku.setupOrderbookManager(ctx)
|
|
||||||
fetchedFuturesOrderbook = map[string]bool{}
|
fetchedFuturesOrderbook = map[string]bool{}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
@@ -2976,6 +2974,7 @@ func TestProcessOrderbook(t *testing.T) {
|
|||||||
response := &WsOrderbook{}
|
response := &WsOrderbook{}
|
||||||
err := json.Unmarshal([]byte(wsOrderbookData), &response)
|
err := json.Unmarshal([]byte(wsOrderbookData), &response)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
ku.setupOrderbookManager(t.Context())
|
||||||
result, err := ku.updateLocalBuffer(response, asset.Spot)
|
result, err := ku.updateLocalBuffer(response, asset.Spot)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotNil(t, result)
|
assert.NotNil(t, result)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ var (
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
l = new(Lbank)
|
l = new(Lbank)
|
||||||
if err := testexch.Setup(l); err != nil {
|
if err := testexch.Setup(l); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Lbank Setup error: %s", err)
|
||||||
}
|
}
|
||||||
if apiKey != "" && apiSecret != "" {
|
if apiKey != "" && apiSecret != "" {
|
||||||
l.API.AuthenticatedSupport = true
|
l.API.AuthenticatedSupport = true
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ var (
|
|||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
ok = new(Okx)
|
ok = new(Okx)
|
||||||
if err := testexch.Setup(ok); err != nil {
|
if err := testexch.Setup(ok); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatalf("Okx Setup error: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiKey != "" && apiSecret != "" && passphrase != "" {
|
if apiKey != "" && apiSecret != "" && passphrase != "" {
|
||||||
|
|||||||
@@ -9,30 +9,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
||||||
|
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
|
||||||
)
|
)
|
||||||
|
|
||||||
var mockTests = false
|
var mockTests = false
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
p = new(Poloniex)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(p); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Poloniex Setup error: %s", err)
|
||||||
log.Fatal("Poloniex load config error", err)
|
|
||||||
}
|
}
|
||||||
poloniexConfig, err := cfg.GetExchangeConfig("Poloniex")
|
if apiKey != "" && apiSecret != "" {
|
||||||
if err != nil {
|
p.API.AuthenticatedSupport = true
|
||||||
log.Fatal("Poloniex Setup() init error", err)
|
p.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
}
|
|
||||||
poloniexConfig.API.AuthenticatedSupport = true
|
|
||||||
poloniexConfig.API.Credentials.Key = apiKey
|
|
||||||
poloniexConfig.API.Credentials.Secret = apiSecret
|
|
||||||
p.SetDefaults()
|
|
||||||
p.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = p.Setup(poloniexConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Poloniex setup error", err)
|
|
||||||
}
|
}
|
||||||
log.Printf(sharedtestvalues.LiveTesting, p.Name)
|
log.Printf(sharedtestvalues.LiveTesting, p.Name)
|
||||||
p.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
p.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
||||||
|
|||||||
@@ -9,52 +9,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
testexch "github.com/thrasher-corp/gocryptotrader/internal/testing/exchange"
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/mock"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/exchanges/sharedtestvalues"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const mockfile = "../../testdata/http_mock/poloniex/poloniex.json"
|
|
||||||
|
|
||||||
var mockTests = true
|
var mockTests = true
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
cfg := config.GetConfig()
|
p = new(Poloniex)
|
||||||
err := cfg.LoadConfig("../../testdata/configtest.json", true)
|
if err := testexch.Setup(p); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Poloniex Setup error: %s", err)
|
||||||
log.Fatal("Poloniex load config error", err)
|
|
||||||
}
|
|
||||||
poloniexConfig, err := cfg.GetExchangeConfig("Poloniex")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Poloniex Setup() init error", err)
|
|
||||||
}
|
|
||||||
p.SkipAuthCheck = true
|
|
||||||
poloniexConfig.API.AuthenticatedSupport = true
|
|
||||||
poloniexConfig.API.Credentials.Key = apiKey
|
|
||||||
poloniexConfig.API.Credentials.Secret = apiSecret
|
|
||||||
p.SetDefaults()
|
|
||||||
p.Websocket = sharedtestvalues.NewTestWebsocket()
|
|
||||||
err = p.Setup(poloniexConfig)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Poloniex setup error", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serverDetails, newClient, err := mock.NewVCRServer(mockfile)
|
if err := testexch.MockHTTPInstance(p); err != nil {
|
||||||
if err != nil {
|
log.Fatalf("Poloniex MockHTTPInstance error: %s", err)
|
||||||
log.Fatalf("Mock server error %s", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err = p.SetHTTPClient(newClient)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Mock server error %s", err)
|
|
||||||
}
|
|
||||||
endpoints := p.API.Endpoints.GetURLMap()
|
|
||||||
for k := range endpoints {
|
|
||||||
err = p.API.Endpoints.SetRunning(k, serverDetails)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Printf(sharedtestvalues.MockTesting, p.Name)
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/thrasher-corp/gocryptotrader/common"
|
"github.com/thrasher-corp/gocryptotrader/common"
|
||||||
"github.com/thrasher-corp/gocryptotrader/config"
|
|
||||||
"github.com/thrasher-corp/gocryptotrader/core"
|
"github.com/thrasher-corp/gocryptotrader/core"
|
||||||
"github.com/thrasher-corp/gocryptotrader/currency"
|
"github.com/thrasher-corp/gocryptotrader/currency"
|
||||||
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
|
||||||
@@ -21,7 +20,7 @@ import (
|
|||||||
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
"github.com/thrasher-corp/gocryptotrader/portfolio/withdraw"
|
||||||
)
|
)
|
||||||
|
|
||||||
var y = &Yobit{}
|
var y *Yobit
|
||||||
|
|
||||||
// Please supply your own keys for better unit testing
|
// Please supply your own keys for better unit testing
|
||||||
const (
|
const (
|
||||||
@@ -33,23 +32,14 @@ const (
|
|||||||
var testPair = currency.NewBTCUSD().Format(currency.PairFormat{Delimiter: "_"})
|
var testPair = currency.NewBTCUSD().Format(currency.PairFormat{Delimiter: "_"})
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
y.SetDefaults()
|
y = new(Yobit)
|
||||||
yobitConfig := config.GetConfig()
|
if err := testexch.Setup(y); err != nil {
|
||||||
err := yobitConfig.LoadConfig("../../testdata/configtest.json", true)
|
log.Fatalf("Yobit Setup error: %s", err)
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Yobit load config error", err)
|
|
||||||
}
|
}
|
||||||
conf, err := yobitConfig.GetExchangeConfig("Yobit")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal("Yobit init error", err)
|
|
||||||
}
|
|
||||||
conf.API.Credentials.Key = apiKey
|
|
||||||
conf.API.Credentials.Secret = apiSecret
|
|
||||||
conf.API.AuthenticatedSupport = true
|
|
||||||
|
|
||||||
err = y.Setup(conf)
|
if apiKey != "" && apiSecret != "" {
|
||||||
if err != nil {
|
y.API.AuthenticatedSupport = true
|
||||||
log.Fatal("Yobit setup error", err)
|
y.SetCredentials(apiKey, apiSecret, "", "", "", "")
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -58,24 +59,32 @@ const httpMockFile = "testdata/http.json"
|
|||||||
|
|
||||||
// MockHTTPInstance takes an existing Exchange instance and attaches it to a new http server
|
// MockHTTPInstance takes an existing Exchange instance and attaches it to a new http server
|
||||||
// It is expected to be run once, since http requests do not often tangle with each other
|
// It is expected to be run once, since http requests do not often tangle with each other
|
||||||
func MockHTTPInstance(e exchange.IBotExchange) error {
|
func MockHTTPInstance(e exchange.IBotExchange, optionalPathPostfix ...string) error {
|
||||||
serverDetails, newClient, err := mock.NewVCRServer(httpMockFile)
|
serverPath, newClient, err := mock.NewVCRServer(httpMockFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("mock server error %s", err)
|
return fmt.Errorf("error starting NewVCRServer: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
b := e.GetBase()
|
b := e.GetBase()
|
||||||
b.SkipAuthCheck = true
|
b.SkipAuthCheck = true
|
||||||
err = b.SetHTTPClient(newClient)
|
if err := b.SetHTTPClient(newClient); err != nil {
|
||||||
if err != nil {
|
return fmt.Errorf("error setting HTTP client: %w", err)
|
||||||
return fmt.Errorf("mock server error %s", err)
|
|
||||||
}
|
}
|
||||||
endpointMap := b.API.Endpoints.GetURLMap()
|
|
||||||
for k := range endpointMap {
|
if len(optionalPathPostfix) > 0 {
|
||||||
err = b.API.Endpoints.SetRunning(k, serverDetails)
|
newPath, err := url.JoinPath(serverPath, optionalPathPostfix...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("mock server error %s", err)
|
return fmt.Errorf("error joining server URL path: %w", err)
|
||||||
|
}
|
||||||
|
serverPath = newPath
|
||||||
|
}
|
||||||
|
|
||||||
|
for k := range b.API.Endpoints.GetURLMap() {
|
||||||
|
if err := b.API.Endpoints.SetRunningURL(k, serverPath); err != nil {
|
||||||
|
return fmt.Errorf("error setting running endpoint: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Printf(sharedtestvalues.MockTesting, e.GetName())
|
log.Printf(sharedtestvalues.MockTesting, e.GetName())
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -100,8 +109,8 @@ func MockWsInstance[T any, PT interface {
|
|||||||
b := e.GetBase()
|
b := e.GetBase()
|
||||||
b.SkipAuthCheck = true
|
b.SkipAuthCheck = true
|
||||||
b.API.AuthenticatedWebsocketSupport = true
|
b.API.AuthenticatedWebsocketSupport = true
|
||||||
err := b.API.Endpoints.SetRunning("RestSpotURL", s.URL)
|
err := b.API.Endpoints.SetRunningURL("RestSpotURL", s.URL)
|
||||||
require.NoError(tb, err, "Endpoints.SetRunning must not error for RestSpotURL")
|
require.NoError(tb, err, "Endpoints.SetRunningURL must not error for RestSpotURL")
|
||||||
for _, auth := range []bool{true, false} {
|
for _, auth := range []bool{true, false} {
|
||||||
err = b.Websocket.SetWebsocketURL("ws"+strings.TrimPrefix(s.URL, "http"), auth, true)
|
err = b.Websocket.SetWebsocketURL("ws"+strings.TrimPrefix(s.URL, "http"), auth, true)
|
||||||
require.NoErrorf(tb, err, "SetWebsocketURL must not error for auth: %v", auth)
|
require.NoErrorf(tb, err, "SetWebsocketURL must not error for auth: %v", auth)
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ func TestSetup(t *testing.T) {
|
|||||||
func TestMockHTTPInstance(t *testing.T) {
|
func TestMockHTTPInstance(t *testing.T) {
|
||||||
b := new(binance.Binance)
|
b := new(binance.Binance)
|
||||||
require.NoError(t, Setup(b), "Test exchange Setup must not error")
|
require.NoError(t, Setup(b), "Test exchange Setup must not error")
|
||||||
require.NoError(t, MockHTTPInstance(b), "MockHTTPInstance must not error")
|
require.NoError(t, MockHTTPInstance(b), "MockHTTPInstance with no optional path must not error")
|
||||||
|
require.NoError(t, MockHTTPInstance(b, "api"), "MockHTTPInstance with optional path must not error")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestMockWsInstance exercises MockWsInstance
|
// TestMockWsInstance exercises MockWsInstance
|
||||||
|
|||||||
Reference in New Issue
Block a user