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

@@ -431,10 +431,10 @@ func (a *Alphapoint) ModifyExistingOrder(symbol string, OrderID, action int64) (
// CancelExistingOrder cancels an order that has not been executed.
// symbol - Instrument code (ex: “BTCUSD”)
// OrderId - Order id (ex: 1000)
func (a *Alphapoint) CancelExistingOrder(symbol string, OrderID int64) (int64, error) {
func (a *Alphapoint) CancelExistingOrder(OrderID int64, OMSID string) (int64, error) {
request := make(map[string]interface{})
request["ins"] = symbol
request["serverOrderId"] = OrderID
request["OrderId"] = OrderID
request["OMSId"] = OMSID
response := Response{}
err := a.SendAuthenticatedHTTPRequest(

View File

@@ -4,14 +4,16 @@ import (
"testing"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
"github.com/thrasher-/gocryptotrader/currency/symbol"
exchange "github.com/thrasher-/gocryptotrader/exchanges"
)
const (
onlineTest = false
testAPIKey = ""
testAPISecret = ""
onlineTest = false
testAPIKey = ""
testAPISecret = ""
canManipulateRealOrders = false
)
func TestSetDefaults(t *testing.T) {
@@ -432,21 +434,6 @@ func TestModifyExistingOrder(t *testing.T) {
}
}
func TestCancelExistingOrder(t *testing.T) {
a := &Alphapoint{}
a.SetDefaults()
testSetAPIKey(a)
if !testIsAPIKeysSet(a) {
return
}
_, err := a.CancelExistingOrder("", 1)
if err == nil {
t.Error("Test Failed - GetUserInfo() error")
}
}
func TestCancelAllExistingOrders(t *testing.T) {
a := &Alphapoint{}
a.SetDefaults()
@@ -504,3 +491,60 @@ func TestFormatWithdrawPermissions(t *testing.T) {
t.Errorf("Expected: %s, Recieved: %s", expectedResult, withdrawPermissions)
}
}
// Any tests below this line have the ability to impact your orders on the exchange. Enable canManipulateRealOrders to run them
// ----------------------------------------------------------------------------------------------------------------------------
func isRealOrderTestEnabled(a *Alphapoint) bool {
if a.APIKey == "" || a.APISecret == "" ||
a.APIKey == "Key" || a.APISecret == "Secret" ||
!canManipulateRealOrders {
return false
}
return true
}
func TestSubmitOrder(t *testing.T) {
a := &Alphapoint{}
a.SetDefaults()
if !isRealOrderTestEnabled(a) {
t.Skip()
}
var p = pair.CurrencyPair{
Delimiter: "_",
FirstCurrency: symbol.BTC,
SecondCurrency: symbol.USD,
}
response, err := a.SubmitOrder(p, exchange.Buy, exchange.Market, 1, 1, "clientId")
if err != nil || !response.IsOrderPlaced {
t.Errorf("Order failed to be placed: %v", err)
}
}
func TestCancelExchangeOrder(t *testing.T) {
// Arrange
a := &Alphapoint{}
a.SetDefaults()
if !isRealOrderTestEnabled(a) {
t.Skip()
}
a.Verbose = true
currencyPair := pair.NewCurrencyPair(symbol.BTC, symbol.LTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
AccountID: "1",
CurrencyPair: currencyPair,
}
// Act
err := a.CancelOrder(orderCancellation)
// Assert
if err != nil {
t.Errorf("Test Failed - ANX CancelOrder() error: %s", err)
}
}

View File

@@ -3,6 +3,7 @@ package alphapoint
import (
"errors"
"fmt"
"strconv"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/currency/pair"
@@ -129,9 +130,16 @@ func (a *Alphapoint) ModifyOrder(orderID int64, action exchange.ModifyOrder) (in
}
// CancelOrder cancels an order by its corresponding ID number
func (a *Alphapoint) CancelOrder(orderID int64) error {
// return a.CancelExistingOrder(p.Pair().String(), orderID)
return common.ErrNotYetImplemented
func (a *Alphapoint) CancelOrder(order exchange.OrderCancellation) error {
orderIDInt, err := strconv.ParseInt(order.OrderID, 10, 64)
if err != nil {
return err
}
_, err = a.CancelExistingOrder(orderIDInt, order.AccountID)
return err
}
// CancelAllOrders cancels all orders associated with a currency pair