Cancel order wrapper wrapup (#214)

* Reimplements order cancellation for alphapoint, anx, binance, bitfinex, bithumb, bitmex, bitstamp, bittrex,  btcmarkets, coinbasepro, coinut, exmo, gateio, gemini, gitbtc, huobi, hadax, itbit, kraken, lakebtc, liqui, okcoin, okex, poloniex, wex, yobit and zb wrappers. Adds new order cancellation struct type. Updates old tests that pointed to the wrong unrenamed methods

* Sets up tests for all supported exchanges. request.DoRequest errors when response status is not 200

* Updates alphapoint, coinut, hitbtc, lakebtc cancel order implementations. Finishes testing

* Adds localbitcoin cancel order wrapper support

* Fixes tests and build issues. Adds WexIssue flag for tests

* Changes CancelOrder signature to only return error. Allows exchange to format currency pairs with delimiters
This commit is contained in:
Scott
2018-11-30 16:20:34 +11:00
committed by Adrian Gallagher
parent d039593b67
commit 458aab301e
72 changed files with 1771 additions and 384 deletions

View File

@@ -1,7 +1,6 @@
package wex
import (
"fmt"
"testing"
"github.com/thrasher-/gocryptotrader/config"
@@ -14,9 +13,10 @@ var w WEX
// Please supply your own keys for better unit testing
const (
apiKey = ""
apiSecret = ""
canPlaceOrders = false
apiKey = ""
apiSecret = ""
canManipulateRealOrders = false
isWexEncounteringIssues = true
)
func TestSetDefaults(t *testing.T) {
@@ -38,6 +38,9 @@ func TestSetup(t *testing.T) {
}
func TestGetTradablePairs(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetTradablePairs()
if err != nil {
@@ -46,6 +49,9 @@ func TestGetTradablePairs(t *testing.T) {
}
func TestGetInfo(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetInfo()
if err != nil {
@@ -54,6 +60,9 @@ func TestGetInfo(t *testing.T) {
}
func TestGetTicker(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetTicker("btc_usd")
if err != nil {
@@ -62,6 +71,9 @@ func TestGetTicker(t *testing.T) {
}
func TestGetDepth(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetDepth("btc_usd")
if err != nil {
@@ -70,6 +82,9 @@ func TestGetDepth(t *testing.T) {
}
func TestGetTrades(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetTrades("btc_usd")
if err != nil {
@@ -78,6 +93,9 @@ func TestGetTrades(t *testing.T) {
}
func TestGetAccountInfo(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetAccountInfo()
if err == nil {
@@ -86,6 +104,9 @@ func TestGetAccountInfo(t *testing.T) {
}
func TestGetActiveOrders(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetActiveOrders("")
if err == nil {
@@ -94,6 +115,9 @@ func TestGetActiveOrders(t *testing.T) {
}
func TestGetOrderInfo(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetOrderInfo(6196974)
if err == nil {
@@ -102,6 +126,9 @@ func TestGetOrderInfo(t *testing.T) {
}
func TestCancelExistingOrder(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.CancelExistingOrder(1337)
if err == nil {
@@ -110,6 +137,9 @@ func TestCancelExistingOrder(t *testing.T) {
}
func TestTrade(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.Trade("", "buy", 0, 0)
if err == nil {
@@ -118,6 +148,9 @@ func TestTrade(t *testing.T) {
}
func TestGetTransactionHistory(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetTransactionHistory(0, 0, 0, "", "", "")
if err == nil {
@@ -126,6 +159,9 @@ func TestGetTransactionHistory(t *testing.T) {
}
func TestGetTradeHistory(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.GetTradeHistory(0, 0, 0, "", "", "", "")
if err == nil {
@@ -134,6 +170,9 @@ func TestGetTradeHistory(t *testing.T) {
}
func TestWithdrawCoins(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.WithdrawCoins("", 0, "")
if err == nil {
@@ -142,6 +181,9 @@ func TestWithdrawCoins(t *testing.T) {
}
func TestCoinDepositAddress(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.CoinDepositAddress("btc")
if err == nil {
@@ -150,6 +192,9 @@ func TestCoinDepositAddress(t *testing.T) {
}
func TestCreateCoupon(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.CreateCoupon("bla", 0)
if err == nil {
@@ -158,6 +203,9 @@ func TestCreateCoupon(t *testing.T) {
}
func TestRedeemCoupon(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
t.Parallel()
_, err := w.RedeemCoupon("bla")
if err == nil {
@@ -180,6 +228,9 @@ func setFeeBuilder() exchange.FeeBuilder {
}
func TestGetFee(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
w.SetDefaults()
TestSetup(t)
var feeBuilder = setFeeBuilder()
@@ -258,6 +309,9 @@ func TestGetFee(t *testing.T) {
}
func TestFormatWithdrawPermissions(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
// Arrange
w.SetDefaults()
expectedResult := exchange.AutoWithdrawCryptoWithAPIPermissionText
@@ -269,18 +323,29 @@ func TestFormatWithdrawPermissions(t *testing.T) {
}
}
// This will really really use the API to place an order
// If you're going to test this, make sure you're willing to place real orders on the exchange
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
// ----------------------------------------------------------------------------------------------------------------------------
func isRealOrderTestEnabled() bool {
if w.APIKey == "" || w.APISecret == "" ||
w.APIKey == "Key" || w.APISecret == "Secret" ||
!canManipulateRealOrders {
return false
}
return true
}
func TestSubmitOrder(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
w.SetDefaults()
TestSetup(t)
w.Verbose = true
if w.APIKey == "" || w.APISecret == "" ||
w.APIKey == "Key" || w.APISecret == "Secret" ||
!canPlaceOrders {
t.Skip(fmt.Sprintf("ApiKey: %s. Can place orders: %v", w.APIKey, canPlaceOrders))
if !isRealOrderTestEnabled() {
t.Skip()
}
var pair = pair.CurrencyPair{
Delimiter: "_",
FirstCurrency: symbol.BTC,
@@ -291,3 +356,34 @@ func TestSubmitOrder(t *testing.T) {
t.Errorf("Order failed to be placed: %v", err)
}
}
func TestCancelExchangeOrder(t *testing.T) {
if isWexEncounteringIssues {
t.Skip()
}
// Arrange
w.SetDefaults()
TestSetup(t)
if !isRealOrderTestEnabled() {
t.Skip()
}
w.Verbose = true
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
AccountID: "1",
CurrencyPair: currencyPair,
}
// Act
err := w.CancelOrder(orderCancellation)
// Assert
if err != nil {
t.Errorf("Could not cancel order: %s", err)
}
}

View File

@@ -3,6 +3,7 @@ package wex
import (
"fmt"
"log"
"strconv"
"sync"
"github.com/thrasher-/gocryptotrader/common"
@@ -180,8 +181,16 @@ func (w *WEX) ModifyOrder(orderID int64, action exchange.ModifyOrder) (int64, er
}
// CancelOrder cancels an order by its corresponding ID number
func (w *WEX) CancelOrder(orderID int64) error {
return common.ErrNotYetImplemented
func (w *WEX) CancelOrder(order exchange.OrderCancellation) error {
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
if err != nil {
return err
}
_, err = w.CancelExistingOrder(orderIDInt)
return err
}
// CancelAllOrders cancels all orders associated with a currency pair