Cancel all orders wrapper implementation (#217)

* Changes method signature for cancelling all orders (experitmental). Implements cancelAllOrders wrapper for alphapoint, anx, binance

* Implements cancel all wrapper for bitfinex, bitmex, bitstamp, bittrex, btcmarkets, coinbasepro and hilariously coinut

* Changes method signature to only use one OrderCancellation type. Adds support for Exmo, gateio, gemini, itbit, lakebtc

* Adds/updates support for hitbtc, huobi, hadax, itbit and kraken

* Adds support for liqui, localbitcoins, okcoin, poloniex, wex and yobit. Splits up open order methods for poloniex

* Adds bithumb, okex and zb support. BTCC for another PR

* Updates bitflyer, bithumb, bitmex, coinut, okex and zb cancelAllOrders method to cancel via enabled currency pairs rather than a singular currency

* Adds tests to all exchanges to test wrapper function CancelAllOrders

* Fixes OKEX and huobi, btcmarkets, kraken, okCoin cancel order implementations

* Fixes coinut, hitbtc and okex api for authenticated requests

* Fixes comment and spacing

* Changes the CancelAllOrders signature to return orderids and errors along with a generic error.

* Fixes OKEX delimiter

* Removes spacing and test verbosity

* Removes more spacing

* Removes space

* Fixes okex rebasing issue. Also makes the maps instead of assuming they just work
This commit is contained in:
Scott
2018-12-14 15:53:26 +11:00
committed by Adrian Gallagher
parent 4ca3fd5b00
commit ff6a84f0f1
89 changed files with 2050 additions and 304 deletions

View File

@@ -326,7 +326,6 @@ func TestCancelExchangeOrder(t *testing.T) {
t.Skip()
}
b.Verbose = true
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
var orderCancellation = exchange.OrderCancellation{
@@ -345,6 +344,37 @@ func TestCancelExchangeOrder(t *testing.T) {
}
}
func TestCancelAllExchangeOrders(t *testing.T) {
// Arrange
b.SetDefaults()
TestSetup(t)
if !isRealOrderTestEnabled() {
t.Skip()
}
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
var orderCancellation = exchange.OrderCancellation{
OrderID: "1",
WalletAddress: "1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB",
AccountID: "1",
CurrencyPair: currencyPair,
}
// Act
resp, err := b.CancelAllOrders(orderCancellation)
// Assert
if err != nil {
t.Errorf("Could not cancel order: %s", err)
}
if len(resp.OrderStatus) > 0 {
t.Errorf("%v orders failed to cancel", len(resp.OrderStatus))
}
}
func TestGetAccountInfo(t *testing.T) {
t.Parallel()
if testAPIKey != "" || testAPISecret != "" {

View File

@@ -115,22 +115,25 @@ type LastTransactionTicker struct {
// Orders contains information about your current orders
type Orders struct {
Status string `json:"status"`
Data []struct {
OrderID string `json:"order_id"`
OrderCurrency string `json:"order_currency"`
OrderDate int64 `json:"order_date"`
PaymentCurrency string `json:"payment_currency"`
Type string `json:"type"`
Status string `json:"status"`
Units float64 `json:"units,string"`
UnitsRemaining float64 `json:"units_remaining,string"`
Price float64 `json:"price,string"`
Fee float64 `json:"fee,string"`
Total float64 `json:"total,string"`
DateCompleted int64 `json:"date_completed"`
} `json:"data"`
Message string `json:"message"`
Status string `json:"status"`
Data []OrderData `json:"data"`
Message string `json:"message"`
}
// OrderData contains all individual order details
type OrderData struct {
OrderID string `json:"order_id"`
OrderCurrency string `json:"order_currency"`
OrderDate int64 `json:"order_date"`
PaymentCurrency string `json:"payment_currency"`
Type string `json:"type"`
Status string `json:"status"`
Units float64 `json:"units,string"`
UnitsRemaining float64 `json:"units_remaining,string"`
Price float64 `json:"price,string"`
Fee float64 `json:"fee,string"`
Total float64 `json:"total,string"`
DateCompleted int64 `json:"date_completed"`
}
// UserTransactions holds users full transaction list

View File

@@ -200,8 +200,31 @@ func (b *Bithumb) CancelOrder(order exchange.OrderCancellation) error {
}
// CancelAllOrders cancels all orders associated with a currency pair
func (b *Bithumb) CancelAllOrders() error {
return common.ErrNotYetImplemented
func (b *Bithumb) CancelAllOrders(orderCancellation exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
OrderStatus: make(map[string]string),
}
var allOrders []OrderData
for _, currency := range b.GetEnabledCurrencies() {
orders, err := b.GetOrders("", orderCancellation.Side.ToString(), "100", "", currency.FirstCurrency.String())
if err != nil {
return cancelAllOrdersResponse, err
}
for _, order := range orders.Data {
allOrders = append(allOrders, order)
}
}
for _, order := range allOrders {
_, err := b.CancelTrade(orderCancellation.Side.ToString(), order.OrderID, orderCancellation.CurrencyPair.FirstCurrency.String())
if err != nil {
cancelAllOrdersResponse.OrderStatus[order.OrderID] = err.Error()
}
}
return cancelAllOrdersResponse, nil
}
// GetOrderInfo returns information on a current open order