mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 15:10:46 +00:00
* Establishes new websocket functionality. Begins the creation of the websocket request * Adding a wrapper over gorilla websocket connect,send,receive to handle ID messages. Doesn't work * Successfully moved exchange_websocket into its own wshandler namespace. oof * Sets up ZB to use a round trip WS request system * Adds Kraken ID support to subscriptions. Renames duplicate func name UnsubscribeToChannels to RemoveSubscribedChannels. Adds some helper methods in the WebsocketConn to reduce duplicate code. Cleans up ZB implementation * Fixes double locking which caused no websocket data to be read. Fixes requestid for kraken subscriptions * Completes Huobi and Hadax implementation. Extends ZB error handling. Adds GZip support for reading messages * Adds HitBTC support. Adds GetCurrencies, GetSymbols, GetTrades WS funcs. Adds super fun new parameter to GenerateMessageID for Unix and UnixNano * Adds GateIO id support * Adds Coinut support. Prevents nil reference error in constatus when there isnt one * Standardises all Exchange websockets to use the wshandler websocket. Removes the wsRequestMtx as wshandler handles that now. Makes the Dialer a dialer, its not externally referenced that I can see. * Fixes issue with coinut implementation. Updates bitmex currencies. Removes redundant log messages which are used to log messages * Starts testing. Renames files * Adds tests for websocket connection * Reverts request.go change * Linting everything * Fixes rebase issue * Final changes. Fixes variable names, removes log.Debug, removes lines, rearranges test types, removes order correlation websocket type * Final final commit, fixing ZB issues. * Adds traffic alerts where missed. Changes empty struct pointer addresses to nil instead. Removes empty lines * Fixed string conversion * Fixes issue with ZB not sending success codes * Fixes issue with coinut processing due to nonce handling with subscriptions * Fixes issue where ZB test failure was not caught. Removes unnecessary error handling from other ZB tests * Removes unused interface * Renames wshandler.Init() to wshandler.Run() * Updates template file * Capitalises cryptocurrencies in struct. Moves websocketResponseCheckTimeout and websocketResponseMaxLimit into config options. Moves connection configuration to main exchange Setup (where appropriate). Reverts currencylastupdated ticks. Improves reader close error checking * Fixes two inconsistent websocket delay times * Creates a default variable for websocket ResponseMaxLimit and ResponseCheckTimeout, then applies it to setdefaults and all tests * Updates exchange template to set and use default websocket response limits
691 lines
18 KiB
Go
691 lines
18 KiB
Go
package huobi
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"crypto/rand"
|
|
"crypto/x509"
|
|
"encoding/pem"
|
|
"io/ioutil"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gorilla/websocket"
|
|
"github.com/thrasher-/gocryptotrader/common"
|
|
"github.com/thrasher-/gocryptotrader/config"
|
|
"github.com/thrasher-/gocryptotrader/currency"
|
|
exchange "github.com/thrasher-/gocryptotrader/exchanges"
|
|
"github.com/thrasher-/gocryptotrader/exchanges/sharedtestvalues"
|
|
"github.com/thrasher-/gocryptotrader/exchanges/wshandler"
|
|
)
|
|
|
|
// Please supply you own test keys here for due diligence testing.
|
|
const (
|
|
apiKey = ""
|
|
apiSecret = ""
|
|
canManipulateRealOrders = false
|
|
testSymbol = "btcusdt"
|
|
)
|
|
|
|
var h HUOBI
|
|
var wsSetupRan bool
|
|
|
|
func TestSetDefaults(t *testing.T) {
|
|
h.SetDefaults()
|
|
}
|
|
|
|
func TestSetup(t *testing.T) {
|
|
cfg := config.GetConfig()
|
|
cfg.LoadConfig("../../testdata/configtest.json")
|
|
hConfig, err := cfg.GetExchangeConfig("Huobi")
|
|
if err != nil {
|
|
t.Error("Test Failed - Huobi Setup() init error")
|
|
}
|
|
hConfig.AuthenticatedAPISupport = true
|
|
hConfig.AuthenticatedWebsocketAPISupport = true
|
|
hConfig.APIKey = apiKey
|
|
hConfig.APISecret = apiSecret
|
|
|
|
h.Setup(&hConfig)
|
|
}
|
|
|
|
func setupWsTests(t *testing.T) {
|
|
if wsSetupRan {
|
|
return
|
|
}
|
|
TestSetDefaults(t)
|
|
TestSetup(t)
|
|
if !h.Websocket.IsEnabled() && !h.AuthenticatedWebsocketAPISupport || !areTestAPIKeysSet() {
|
|
t.Skip(wshandler.WebsocketNotEnabled)
|
|
}
|
|
comms = make(chan WsMessage, sharedtestvalues.WebsocketChannelOverrideCapacity)
|
|
h.Websocket.DataHandler = sharedtestvalues.GetWebsocketInterfaceChannelOverride()
|
|
h.Websocket.TrafficAlert = sharedtestvalues.GetWebsocketStructChannelOverride()
|
|
go h.WsHandleData()
|
|
h.AuthenticatedWebsocketConn = &wshandler.WebsocketConnection{
|
|
ExchangeName: h.Name,
|
|
URL: wsAccountsOrdersURL,
|
|
Verbose: h.Verbose,
|
|
ResponseMaxLimit: exchange.DefaultWebsocketResponseMaxLimit,
|
|
ResponseCheckTimeout: exchange.DefaultWebsocketResponseCheckTimeout,
|
|
}
|
|
h.WebsocketConn = &wshandler.WebsocketConnection{
|
|
ExchangeName: h.Name,
|
|
URL: wsMarketURL,
|
|
Verbose: h.Verbose,
|
|
ResponseMaxLimit: exchange.DefaultWebsocketResponseMaxLimit,
|
|
ResponseCheckTimeout: exchange.DefaultWebsocketResponseCheckTimeout,
|
|
}
|
|
var dialer websocket.Dialer
|
|
err := h.wsAuthenticatedDial(&dialer)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
err = h.wsLogin()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
wsSetupRan = true
|
|
}
|
|
|
|
func TestGetSpotKline(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetSpotKline(KlinesRequestParams{
|
|
Symbol: testSymbol,
|
|
Period: TimeIntervalHour,
|
|
Size: 0,
|
|
})
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetSpotKline: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetMarketDetailMerged(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetMarketDetailMerged(testSymbol)
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetMarketDetailMerged: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetDepth(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetDepth(OrderBookDataRequestParams{
|
|
Symbol: testSymbol,
|
|
Type: OrderBookDataRequestParamsTypeStep1,
|
|
})
|
|
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetDepth: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetTrades(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetTrades(testSymbol)
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetTrades: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetLatestSpotPrice(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetLatestSpotPrice(testSymbol)
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi GetLatestSpotPrice: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetTradeHistory(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetTradeHistory(testSymbol, "50")
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetTradeHistory: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetMarketDetail(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetMarketDetail(testSymbol)
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetTradeHistory: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetSymbols(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetSymbols()
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetSymbols: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetCurrencies(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetCurrencies()
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetCurrencies: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetTimestamp(t *testing.T) {
|
|
t.Parallel()
|
|
_, err := h.GetTimestamp()
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetTimestamp: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetAccounts(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
_, err := h.GetAccounts()
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi GetAccounts: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetAccountBalance(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
result, err := h.GetAccounts()
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi GetAccounts: %s", err)
|
|
}
|
|
|
|
userID := strconv.FormatInt(result[0].ID, 10)
|
|
_, err = h.GetAccountBalance(userID)
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi GetAccountBalance: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetAggregatedBalance(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
_, err := h.GetAggregatedBalance()
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi GetAggregatedBalance: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestSpotNewOrder(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
arg := SpotNewOrderRequestParams{
|
|
Symbol: testSymbol,
|
|
AccountID: 1,
|
|
Amount: 0.01,
|
|
Price: 10.1,
|
|
Type: SpotNewOrderRequestTypeBuyLimit,
|
|
}
|
|
|
|
_, err := h.SpotNewOrder(arg)
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi SpotNewOrder: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestCancelExistingOrder(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
_, err := h.CancelExistingOrder(1337)
|
|
if err == nil {
|
|
t.Error("Test failed - Huobi TestCancelExistingOrder: Invalid orderID returned true")
|
|
}
|
|
}
|
|
|
|
func TestGetOrder(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
_, err := h.GetOrder(1337)
|
|
if err == nil {
|
|
t.Error("Test failed - Huobi TestCancelOrder: Invalid orderID returned true")
|
|
}
|
|
}
|
|
|
|
func TestGetMarginLoanOrders(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
_, err := h.GetMarginLoanOrders(testSymbol, "", "", "", "", "", "", "")
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetMarginLoanOrders: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestGetMarginAccountBalance(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
if h.APIKey == "" || h.APISecret == "" || h.APIAuthPEMKey == "" {
|
|
t.Skip()
|
|
}
|
|
|
|
_, err := h.GetMarginAccountBalance(testSymbol)
|
|
if err != nil {
|
|
t.Errorf("Test failed - Huobi TestGetMarginAccountBalance: %s", err)
|
|
}
|
|
}
|
|
|
|
func TestCancelWithdraw(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
_, err := h.CancelWithdraw(1337)
|
|
if err == nil {
|
|
t.Error("Test failed - Huobi TestCancelWithdraw: Invalid withdraw-ID was valid")
|
|
}
|
|
}
|
|
|
|
func TestPEMLoadAndSign(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
pemKey := strings.NewReader(h.APIAuthPEMKey)
|
|
pemBytes, err := ioutil.ReadAll(pemKey)
|
|
if err != nil {
|
|
t.Fatalf("Test Failed. TestPEMLoadAndSign Unable to ioutil.ReadAll PEM key: %s", err)
|
|
}
|
|
|
|
block, _ := pem.Decode(pemBytes)
|
|
if block == nil {
|
|
t.Fatalf("Test Failed. TestPEMLoadAndSign Block is nil")
|
|
}
|
|
|
|
x509Encoded := block.Bytes
|
|
privKey, err := x509.ParseECPrivateKey(x509Encoded)
|
|
if err != nil {
|
|
t.Fatalf("Test Failed. TestPEMLoadAndSign Unable to ParseECPrivKey: %s", err)
|
|
}
|
|
|
|
_, _, err = ecdsa.Sign(rand.Reader, privKey, common.GetSHA256([]byte("test")))
|
|
if err != nil {
|
|
t.Fatalf("Test Failed. TestPEMLoadAndSign Unable to sign: %s", err)
|
|
}
|
|
}
|
|
|
|
func setFeeBuilder() *exchange.FeeBuilder {
|
|
return &exchange.FeeBuilder{
|
|
Amount: 1,
|
|
FeeType: exchange.CryptocurrencyTradeFee,
|
|
Pair: currency.NewPairWithDelimiter(currency.BTC.String(),
|
|
currency.LTC.String(),
|
|
"_"),
|
|
PurchasePrice: 1,
|
|
FiatCurrency: currency.USD,
|
|
BankTransactionType: exchange.WireTransfer,
|
|
}
|
|
}
|
|
|
|
// TestGetFeeByTypeOfflineTradeFee logic test
|
|
func TestGetFeeByTypeOfflineTradeFee(t *testing.T) {
|
|
var feeBuilder = setFeeBuilder()
|
|
h.GetFeeByType(feeBuilder)
|
|
if apiKey == "" || apiSecret == "" {
|
|
if feeBuilder.FeeType != exchange.OfflineTradeFee {
|
|
t.Errorf("Expected %v, received %v", exchange.OfflineTradeFee, feeBuilder.FeeType)
|
|
}
|
|
} else {
|
|
if feeBuilder.FeeType != exchange.CryptocurrencyTradeFee {
|
|
t.Errorf("Expected %v, received %v", exchange.CryptocurrencyTradeFee, feeBuilder.FeeType)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestGetFee(t *testing.T) {
|
|
t.Parallel()
|
|
var feeBuilder = setFeeBuilder()
|
|
// CryptocurrencyTradeFee Basic
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0.002) || err != nil {
|
|
t.Error(err)
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.002), resp)
|
|
}
|
|
|
|
// CryptocurrencyTradeFee High quantity
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.Amount = 1000
|
|
feeBuilder.PurchasePrice = 1000
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(2000) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(2000), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CryptocurrencyTradeFee IsMaker
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.IsMaker = true
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0.002) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0.002), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CryptocurrencyTradeFee Negative purchase price
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.PurchasePrice = -1000
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
// CryptocurrencyWithdrawalFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CryptocurrencyWithdrawalFee Invalid currency
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.Pair.Base = currency.NewCode("hello")
|
|
feeBuilder.FeeType = exchange.CryptocurrencyWithdrawalFee
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// CyptocurrencyDepositFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.CyptocurrencyDepositFee
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// InternationalBankDepositFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.InternationalBankDepositFee
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
|
|
// InternationalBankWithdrawalFee Basic
|
|
feeBuilder = setFeeBuilder()
|
|
feeBuilder.FeeType = exchange.InternationalBankWithdrawalFee
|
|
feeBuilder.FiatCurrency = currency.USD
|
|
if resp, err := h.GetFee(feeBuilder); resp != float64(0) || err != nil {
|
|
t.Errorf("Test Failed - GetFee() error. Expected: %f, Received: %f", float64(0), resp)
|
|
t.Error(err)
|
|
}
|
|
}
|
|
|
|
func TestFormatWithdrawPermissions(t *testing.T) {
|
|
h.SetDefaults()
|
|
expectedResult := exchange.AutoWithdrawCryptoWithSetupText + " & " + exchange.NoFiatWithdrawalsText
|
|
|
|
withdrawPermissions := h.FormatWithdrawPermissions()
|
|
|
|
if withdrawPermissions != expectedResult {
|
|
t.Errorf("Expected: %s, Received: %s", expectedResult, withdrawPermissions)
|
|
}
|
|
}
|
|
|
|
func TestGetActiveOrders(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
var getOrdersRequest = exchange.GetOrdersRequest{
|
|
OrderType: exchange.AnyOrderType,
|
|
Currencies: []currency.Pair{currency.NewPair(currency.BTC, currency.USDT)},
|
|
}
|
|
|
|
_, err := h.GetActiveOrders(&getOrdersRequest)
|
|
if areTestAPIKeysSet() && err != nil {
|
|
t.Errorf("Could not get open orders: %s", err)
|
|
} else if !areTestAPIKeysSet() && err == nil {
|
|
t.Error("Expecting an error when no keys are set")
|
|
}
|
|
}
|
|
|
|
func TestGetOrderHistory(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
var getOrdersRequest = exchange.GetOrdersRequest{
|
|
OrderType: exchange.AnyOrderType,
|
|
Currencies: []currency.Pair{currency.NewPair(currency.BTC, currency.USDT)},
|
|
}
|
|
|
|
_, err := h.GetOrderHistory(&getOrdersRequest)
|
|
if areTestAPIKeysSet() && err != nil {
|
|
t.Errorf("Could not get order history: %s", err)
|
|
} else if !areTestAPIKeysSet() && 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 {
|
|
if h.APIKey != "" && h.APIKey != "Key" &&
|
|
h.APISecret != "" && h.APISecret != "Secret" {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
func TestSubmitOrder(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
if (h.APIKey == "" || h.APIKey == "Key") &&
|
|
(h.APISecret == "" || h.APISecret == "Secret") {
|
|
t.Skip()
|
|
}
|
|
|
|
var p = currency.Pair{
|
|
Delimiter: "",
|
|
Base: currency.BTC,
|
|
Quote: currency.USDT,
|
|
}
|
|
|
|
accounts, err := h.GetAccounts()
|
|
if err != nil {
|
|
t.Errorf("Failed to get accounts. Err: %s", err)
|
|
}
|
|
|
|
response, err := h.SubmitOrder(p, exchange.BuyOrderSide, exchange.LimitOrderType, 1, 10, strconv.FormatInt(accounts[0].ID, 10))
|
|
if areTestAPIKeysSet() && (err != nil || !response.IsOrderPlaced) {
|
|
t.Errorf("Order failed to be placed: %v", err)
|
|
} else if !areTestAPIKeysSet() && err == nil {
|
|
t.Error("Expecting an error when no keys are set")
|
|
}
|
|
}
|
|
|
|
func TestCancelExchangeOrder(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
|
|
|
var orderCancellation = &exchange.OrderCancellation{
|
|
OrderID: "1",
|
|
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
|
AccountID: "1",
|
|
CurrencyPair: currencyPair,
|
|
}
|
|
|
|
err := h.CancelOrder(orderCancellation)
|
|
|
|
if !areTestAPIKeysSet() && err == nil {
|
|
t.Error("Expecting an error when no keys are set")
|
|
}
|
|
if areTestAPIKeysSet() && err != nil {
|
|
t.Errorf("Could not cancel orders: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestCancelAllExchangeOrders(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
currencyPair := currency.NewPair(currency.LTC, currency.BTC)
|
|
var orderCancellation = exchange.OrderCancellation{
|
|
OrderID: "1",
|
|
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
|
AccountID: "1",
|
|
CurrencyPair: currencyPair,
|
|
}
|
|
|
|
resp, err := h.CancelAllOrders(&orderCancellation)
|
|
|
|
if !areTestAPIKeysSet() && err == nil {
|
|
t.Error("Expecting an error when no keys are set")
|
|
}
|
|
if areTestAPIKeysSet() && err != nil {
|
|
t.Errorf("Could not cancel orders: %v", err)
|
|
}
|
|
|
|
if len(resp.OrderStatus) > 0 {
|
|
t.Errorf("%v orders failed to cancel", len(resp.OrderStatus))
|
|
}
|
|
}
|
|
|
|
func TestGetAccountInfo(t *testing.T) {
|
|
if apiKey == "" || apiSecret == "" {
|
|
_, err := h.GetAccountInfo()
|
|
if err == nil {
|
|
t.Error("Test Failed - GetAccountInfo() error")
|
|
}
|
|
} else {
|
|
_, err := h.GetAccountInfo()
|
|
if err != nil {
|
|
t.Error("Test Failed - GetAccountInfo() error", err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestModifyOrder(t *testing.T) {
|
|
_, err := h.ModifyOrder(&exchange.ModifyOrder{})
|
|
if err == nil {
|
|
t.Error("Test failed - ModifyOrder() error")
|
|
}
|
|
}
|
|
|
|
func TestWithdraw(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
var withdrawCryptoRequest = exchange.WithdrawRequest{
|
|
Amount: 100,
|
|
Currency: currency.BTC,
|
|
Address: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
|
|
Description: "WITHDRAW IT ALL",
|
|
}
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
_, err := h.WithdrawCryptocurrencyFunds(&withdrawCryptoRequest)
|
|
if !areTestAPIKeysSet() && err == nil {
|
|
t.Error("Expecting an error when no keys are set")
|
|
}
|
|
if areTestAPIKeysSet() && err != nil {
|
|
t.Errorf("Withdraw failed to be placed: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestWithdrawFiat(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
var withdrawFiatRequest = exchange.WithdrawRequest{}
|
|
|
|
_, err := h.WithdrawFiatFunds(&withdrawFiatRequest)
|
|
if err != common.ErrFunctionNotSupported {
|
|
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
|
}
|
|
}
|
|
|
|
func TestWithdrawInternationalBank(t *testing.T) {
|
|
h.SetDefaults()
|
|
TestSetup(t)
|
|
|
|
if areTestAPIKeysSet() && !canManipulateRealOrders {
|
|
t.Skip("API keys set, canManipulateRealOrders false, skipping test")
|
|
}
|
|
|
|
var withdrawFiatRequest = exchange.WithdrawRequest{}
|
|
|
|
_, err := h.WithdrawFiatFundsToInternationalBank(&withdrawFiatRequest)
|
|
if err != common.ErrFunctionNotSupported {
|
|
t.Errorf("Expected '%v', received: '%v'", common.ErrFunctionNotSupported, err)
|
|
}
|
|
}
|
|
|
|
func TestGetDepositAddress(t *testing.T) {
|
|
_, err := h.GetDepositAddress(currency.BTC, "")
|
|
if err == nil {
|
|
t.Error("Test Failed - GetDepositAddress() error cannot be nil")
|
|
}
|
|
}
|
|
|
|
// TestWsGetAccountsList connects to WS, logs in, gets account list
|
|
func TestWsGetAccountsList(t *testing.T) {
|
|
setupWsTests(t)
|
|
resp, err := h.wsGetAccountsList(currency.NewPairFromString("ethbtc"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if resp.ErrorCode > 0 {
|
|
t.Error(resp.ErrorMessage)
|
|
}
|
|
}
|
|
|
|
// TestWsGetOrderList connects to WS, logs in, gets order list
|
|
func TestWsGetOrderList(t *testing.T) {
|
|
setupWsTests(t)
|
|
resp, err := h.wsGetOrdersList(1, currency.NewPairFromString("ethbtc"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if resp.ErrorCode > 0 {
|
|
t.Error(resp.ErrorMessage)
|
|
}
|
|
}
|
|
|
|
// TestWsGetOrderDetails connects to WS, logs in, gets order details
|
|
func TestWsGetOrderDetails(t *testing.T) {
|
|
setupWsTests(t)
|
|
orderID := "123"
|
|
resp, err := h.wsGetOrderDetails(orderID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if resp.ErrorCode > 0 && (orderID == "123" && resp.ErrorCode != 10022) {
|
|
t.Error(resp.ErrorMessage)
|
|
}
|
|
}
|