mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-17 07:26:48 +00:00
(FIX) Update ZB API URLs (#474)
* Updates websocket URL * Minor test changes, URL changes too * verbosity purposity prepostery * Fixes issue where websocket data passed through the round trip was invalid * Adds a test protection
This commit is contained in:
@@ -19,8 +19,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
zbTradeURL = "http://api.zb.cn/data"
|
||||
zbMarketURL = "https://trade.zb.cn/api"
|
||||
zbTradeURL = "http://api.zb.live/data"
|
||||
zbMarketURL = "https://trade.zb.live/api"
|
||||
zbAPIVersion = "v1"
|
||||
|
||||
zbAccountInfo = "getAccountInfo"
|
||||
|
||||
@@ -59,7 +59,7 @@ func setupWsAuth(t *testing.T) {
|
||||
if wsSetupRan {
|
||||
return
|
||||
}
|
||||
if !z.Websocket.IsEnabled() && !z.API.AuthenticatedWebsocketSupport || !areTestAPIKeysSet() || !canManipulateRealOrders {
|
||||
if !z.Websocket.IsEnabled() && !z.API.AuthenticatedWebsocketSupport || !z.ValidateAPICredentials() || !canManipulateRealOrders {
|
||||
t.Skip(wshandler.WebsocketNotEnabled)
|
||||
}
|
||||
z.WebsocketConn = &wshandler.WebsocketConnection{
|
||||
@@ -83,7 +83,7 @@ func setupWsAuth(t *testing.T) {
|
||||
func TestSpotNewOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if !z.ValidateAPICredentials() {
|
||||
if !z.ValidateAPICredentials() || !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ func TestSpotNewOrder(t *testing.T) {
|
||||
func TestCancelExistingOrder(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
if !z.ValidateAPICredentials() {
|
||||
if !z.ValidateAPICredentials() || !canManipulateRealOrders {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ func setFeeBuilder() *exchange.FeeBuilder {
|
||||
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
||||
var feeBuilder = setFeeBuilder()
|
||||
z.GetFeeByType(feeBuilder)
|
||||
if !areTestAPIKeysSet() {
|
||||
if !z.ValidateAPICredentials() {
|
||||
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
||||
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
|
||||
}
|
||||
@@ -286,9 +286,9 @@ func TestGetActiveOrders(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := z.GetActiveOrders(&getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Errorf("Could not get open orders: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
@@ -302,21 +302,18 @@ func TestGetOrderHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
_, err := z.GetOrderHistory(&getOrdersRequest)
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Errorf("Could not get order history: %s", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
|
||||
// ----------------------------------------------------------------------------------------------------------------------------
|
||||
func areTestAPIKeysSet() bool {
|
||||
return z.ValidateAPICredentials()
|
||||
}
|
||||
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip(fmt.Sprintf("ApiKey: %s. Can place orders: %v",
|
||||
z.API.Credentials.Key,
|
||||
canManipulateRealOrders))
|
||||
@@ -335,15 +332,15 @@ func TestSubmitOrder(t *testing.T) {
|
||||
ClientID: "meowOrder",
|
||||
}
|
||||
response, err := z.SubmitOrder(orderSubmission)
|
||||
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
||||
if z.ValidateAPICredentials() && (err != nil || !response.IsOrderPlaced) {
|
||||
t.Errorf("Order failed to be placed: %v", err)
|
||||
} else if !areTestAPIKeysSet() && err == nil {
|
||||
} else if !z.ValidateAPICredentials() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelExchangeOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
@@ -356,16 +353,16 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
|
||||
err := z.CancelOrder(orderCancellation)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !z.ValidateAPICredentials() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
@@ -379,10 +376,10 @@ func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
|
||||
resp, err := z.CancelAllOrders(orderCancellation)
|
||||
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !z.ValidateAPICredentials() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Errorf("Could not cancel orders: %v", err)
|
||||
}
|
||||
|
||||
@@ -406,7 +403,7 @@ func TestGetAccountInfo(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestModifyOrder(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
_, err := z.ModifyOrder(&order.Modify{})
|
||||
@@ -426,21 +423,21 @@ func TestWithdraw(t *testing.T) {
|
||||
Description: "WITHDRAW IT ALL",
|
||||
}
|
||||
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
_, err := z.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
||||
if !areTestAPIKeysSet() && err == nil {
|
||||
if !z.ValidateAPICredentials() && err == nil {
|
||||
t.Error("Expecting an error when no keys are set")
|
||||
}
|
||||
if areTestAPIKeysSet() && err != nil {
|
||||
if z.ValidateAPICredentials() && err != nil {
|
||||
t.Errorf("Withdraw failed to be placed: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawFiat(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
@@ -452,7 +449,7 @@ func TestWithdrawFiat(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWithdrawInternationalBank(t *testing.T) {
|
||||
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
||||
if z.ValidateAPICredentials() && !canManipulateRealOrders {
|
||||
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
||||
}
|
||||
|
||||
@@ -464,7 +461,7 @@ func TestWithdrawInternationalBank(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetDepositAddress(t *testing.T) {
|
||||
if areTestAPIKeysSet() {
|
||||
if z.ValidateAPICredentials() {
|
||||
_, err := z.GetDepositAddress(currency.BTC, "")
|
||||
if err != nil {
|
||||
t.Error("GetDepositAddress() error PLEASE MAKE SURE YOU CREATE DEPOSIT ADDRESSES VIA ZB.COM",
|
||||
@@ -514,20 +511,6 @@ func TestWsTransferFunds(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWsCreateSuUserKey ws test
|
||||
func TestWsCreateSuUserKey(t *testing.T) {
|
||||
setupWsAuth(t)
|
||||
subUsers, err := z.wsGetSubUserList()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
userID := subUsers.Message[0].UserID
|
||||
_, err = z.wsCreateSubUserKey(true, true, true, true, "subu", strconv.FormatInt(userID, 10))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestGetSubUserList ws test
|
||||
func TestGetSubUserList(t *testing.T) {
|
||||
setupWsAuth(t)
|
||||
@@ -546,6 +529,23 @@ func TestAddSubUser(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestWsCreateSuUserKey ws test
|
||||
func TestWsCreateSuUserKey(t *testing.T) {
|
||||
setupWsAuth(t)
|
||||
subUsers, err := z.wsGetSubUserList()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(subUsers.Message) == 0 {
|
||||
t.Skip("User ID required for test to continue. Create a subuser first")
|
||||
}
|
||||
userID := subUsers.Message[0].UserID
|
||||
_, err = z.wsCreateSubUserKey(true, true, true, true, "subu", strconv.FormatInt(userID, 10))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
// TestWsSubmitOrder ws test
|
||||
func TestWsSubmitOrder(t *testing.T) {
|
||||
setupWsAuth(t)
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
zbWebsocketAPI = "wss://api.zb.cn:9999/websocket"
|
||||
zbWebsocketAPI = "wss://api.zb.live/websocket"
|
||||
zWebsocketAddChannel = "addChannel"
|
||||
zbWebsocketRateLimit = 20
|
||||
)
|
||||
@@ -81,7 +81,7 @@ func (z *ZB) wsHandleData(respRaw []byte) error {
|
||||
}
|
||||
if result.No > 0 {
|
||||
if z.WebsocketConn.IsIDWaitingForResponse(result.No) {
|
||||
z.WebsocketConn.SetResponseIDAndData(result.No, respRaw)
|
||||
z.WebsocketConn.SetResponseIDAndData(result.No, fixedJSON)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user