mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-01 07:26:48 +00:00
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:
@@ -195,6 +195,34 @@ func (i *ItBit) GetWalletBalance(walletID, currency string) (Balance, error) {
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetOrders returns active orders for itBit
|
||||
// perPage defaults to & has a limit of 50
|
||||
func (i *ItBit) GetOrders(walletID, symbol, status string, page, perPage int64) ([]Order, error) {
|
||||
var resp []Order
|
||||
params := make(map[string]interface{})
|
||||
params["walletID"] = walletID
|
||||
|
||||
if symbol != "" {
|
||||
params["instrument"] = symbol
|
||||
}
|
||||
if status != "" {
|
||||
params["status"] = status
|
||||
}
|
||||
if page > 0 {
|
||||
params["page"] = strconv.FormatInt(page, 10)
|
||||
}
|
||||
if perPage > 0 {
|
||||
params["perPage"] = strconv.FormatInt(perPage, 10)
|
||||
}
|
||||
|
||||
err := i.SendAuthenticatedHTTPRequest("GET", itbitOrders, params, &resp)
|
||||
if err != nil {
|
||||
return resp, err
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetWalletTrades returns all trades for a specified wallet.
|
||||
func (i *ItBit) GetWalletTrades(walletID string, params url.Values) (Records, error) {
|
||||
resp := Records{}
|
||||
|
||||
@@ -258,7 +258,6 @@ func isRealOrderTestEnabled() bool {
|
||||
func TestSubmitOrder(t *testing.T) {
|
||||
i.SetDefaults()
|
||||
TestSetup(t)
|
||||
i.Verbose = true
|
||||
|
||||
if !isRealOrderTestEnabled() {
|
||||
t.Skip()
|
||||
@@ -284,7 +283,6 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
t.Skip()
|
||||
}
|
||||
|
||||
i.Verbose = true
|
||||
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
|
||||
|
||||
var orderCancellation = exchange.OrderCancellation{
|
||||
@@ -303,6 +301,37 @@ func TestCancelExchangeOrder(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelAllExchangeOrders(t *testing.T) {
|
||||
// Arrange
|
||||
i.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 := i.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) {
|
||||
if apiKey != "" || apiSecret != "" || clientID != "" {
|
||||
_, err := i.GetAccountInfo()
|
||||
|
||||
@@ -211,8 +211,23 @@ func (i *ItBit) CancelOrder(order exchange.OrderCancellation) error {
|
||||
}
|
||||
|
||||
// CancelAllOrders cancels all orders associated with a currency pair
|
||||
func (i *ItBit) CancelAllOrders() error {
|
||||
return common.ErrNotYetImplemented
|
||||
func (i *ItBit) CancelAllOrders(orderCancellation exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
|
||||
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
|
||||
OrderStatus: make(map[string]string),
|
||||
}
|
||||
openOrders, err := i.GetOrders(orderCancellation.WalletAddress, "", "open", 0, 0)
|
||||
if err != nil {
|
||||
return cancelAllOrdersResponse, err
|
||||
}
|
||||
|
||||
for _, openOrder := range openOrders {
|
||||
err = i.CancelExistingOrder(orderCancellation.WalletAddress, openOrder.ID)
|
||||
if err != nil {
|
||||
cancelAllOrdersResponse.OrderStatus[openOrder.ID] = err.Error()
|
||||
}
|
||||
}
|
||||
|
||||
return cancelAllOrdersResponse, nil
|
||||
}
|
||||
|
||||
// GetOrderInfo returns information on a current open order
|
||||
|
||||
Reference in New Issue
Block a user