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

@@ -22,14 +22,15 @@ const (
zbMarketURL = "https://trade.zb.com/api"
zbAPIVersion = "v1"
zbAccountInfo = "getAccountInfo"
zbMarkets = "markets"
zbKline = "kline"
zbOrder = "order"
zbCancelOrder = "cancelOrder"
zbTicker = "ticker"
zbTickers = "allTicker"
zbDepth = "depth"
zbAccountInfo = "getAccountInfo"
zbMarkets = "markets"
zbKline = "kline"
zbOrder = "order"
zbCancelOrder = "cancelOrder"
zbTicker = "ticker"
zbTickers = "allTicker"
zbDepth = "depth"
zbUnfinishedOrdersIgnoreTradeType = "getUnfinishedOrdersIgnoreTradeType"
zbAuthRate = 100
zbUnauthRate = 100
@@ -175,6 +176,24 @@ func (z *ZB) GetAccountInformation() (AccountsResponse, error) {
return result, nil
}
// GetUnfinishedOrdersIgnoreTradeType returns unfinished orders
func (z *ZB) GetUnfinishedOrdersIgnoreTradeType(currency, pageindex, pagesize string) ([]UnfinishedOpenOrder, error) {
var result []UnfinishedOpenOrder
vals := url.Values{}
vals.Set("accesskey", z.APIKey)
vals.Set("method", zbUnfinishedOrdersIgnoreTradeType)
vals.Set("currency", currency)
vals.Set("pageIndex", pageindex)
vals.Set("pageSize", pagesize)
err := z.SendAuthenticatedHTTPRequest("GET", zbUnfinishedOrdersIgnoreTradeType, vals, &result)
if err != nil {
return result, err
}
return result, nil
}
// GetMarkets returns market information including pricing, symbols and
// each symbols decimal precision
func (z *ZB) GetMarkets() (map[string]MarketResponseItem, error) {

View File

@@ -244,7 +244,6 @@ func isRealOrderTestEnabled() bool {
func TestSubmitOrder(t *testing.T) {
z.SetDefaults()
TestSetup(t)
z.Verbose = true
if !isRealOrderTestEnabled() {
t.Skip(fmt.Sprintf("ApiKey: %s. Can place orders: %v", z.APIKey, canManipulateRealOrders))
@@ -269,7 +268,6 @@ func TestCancelExchangeOrder(t *testing.T) {
t.Skip()
}
z.Verbose = true
currencyPair := pair.NewCurrencyPair(symbol.LTC, symbol.BTC)
var orderCancellation = exchange.OrderCancellation{
@@ -288,6 +286,37 @@ func TestCancelExchangeOrder(t *testing.T) {
}
}
func TestCancelAllExchangeOrders(t *testing.T) {
// Arrange
z.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 := z.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 != "" {
_, err := z.GetAccountInfo()

View File

@@ -29,6 +29,19 @@ type AccountsBaseResponse struct {
AuthMobileEnabled bool `json:"auth_mobile_enabled"` //是否开通手机验证
}
// UnfinishedOpenOrder is the order details for retrieving all open orders
type UnfinishedOpenOrder struct {
Currency string `json:"currency"`
ID int64 `json:"id"`
Price int `json:"price"`
Status int `json:"status"`
TotalAmount float64 `json:"total_amount"`
TradeAmount int `json:"trade_amount"`
TradeDate int `json:"trade_date"`
TradeMoney int `json:"trade_money"`
Type int `json:"type"`
}
// AccountsResponse 用户基本信息
type AccountsResponse struct {
Result struct {

View File

@@ -210,8 +210,30 @@ func (z *ZB) CancelOrder(order exchange.OrderCancellation) error {
}
// CancelAllOrders cancels all orders associated with a currency pair
func (z *ZB) CancelAllOrders() error {
return common.ErrNotYetImplemented
func (z *ZB) CancelAllOrders(orderCancellation exchange.OrderCancellation) (exchange.CancelAllOrdersResponse, error) {
cancelAllOrdersResponse := exchange.CancelAllOrdersResponse{
OrderStatus: make(map[string]string),
}
var allOpenOrders []UnfinishedOpenOrder
for _, currency := range z.GetEnabledCurrencies() {
openOrders, err := z.GetUnfinishedOrdersIgnoreTradeType(exchange.FormatExchangeCurrency(z.Name, currency).String(), "1", "10")
if err != nil {
return cancelAllOrdersResponse, err
}
for _, openOrder := range openOrders {
allOpenOrders = append(allOpenOrders, openOrder)
}
}
for _, openOrder := range allOpenOrders {
err := z.CancelExistingOrder(openOrder.ID, openOrder.Currency)
if err != nil {
cancelAllOrdersResponse.OrderStatus[strconv.FormatInt(openOrder.ID, 10)] = err.Error()
}
}
return cancelAllOrdersResponse, nil
}
// GetOrderInfo returns information on a current open order