diff --git a/pkg/cmd/cancel.go b/pkg/cmd/cancel.go index 99c24e4d0..856a4bacd 100644 --- a/pkg/cmd/cancel.go +++ b/pkg/cmd/cancel.go @@ -22,6 +22,7 @@ func init() { CancelCmd.Flags().String("session", "", "session to execute cancel orders") CancelCmd.Flags().String("symbol", "", "symbol to cancel orders") CancelCmd.Flags().Int64("group-id", 0, "groupID to cancel orders") + CancelCmd.Flags().Bool("all", false, "cancel all orders") RootCmd.AddCommand(CancelCmd) } @@ -47,6 +48,11 @@ var CancelCmd = &cobra.Command{ return err } + all, err := cmd.Flags().GetBool("all") + if err != nil { + return err + } + configFile, err := cmd.Flags().GetString("config") if err != nil { return err @@ -62,7 +68,7 @@ var CancelCmd = &cobra.Command{ } environ := bbgo.NewEnvironment() - if err := environ.ConfigureDatabase(ctx) ; err != nil { + if err := environ.ConfigureDatabase(ctx); err != nil { return err } @@ -91,30 +97,41 @@ var CancelCmd = &cobra.Command{ var log = logrus.WithField("session", sessionID) e, ok := session.Exchange.(advancedOrderCancelApi) - if ok && groupID > 0 { - log.Infof("canceling orders by group id: %d", groupID) + if ok { + if all { + log.Infof("canceling all orders") - orders, err := e.CancelOrdersByGroupID(ctx, groupID) - if err != nil { - return err + orders, err := e.CancelAllOrders(ctx) + if err != nil { + return err + } + + for _, o := range orders { + log.Info("CANCELED ", o.String()) + } + } else if groupID > 0 { + log.Infof("canceling orders by group id: %d", groupID) + + orders, err := e.CancelOrdersByGroupID(ctx, groupID) + if err != nil { + return err + } + + for _, o := range orders { + log.Info("CANCELED ", o.String()) + } + } else if len(symbol) > 0 { + log.Infof("canceling orders by symbol: %s", symbol) + + orders, err := e.CancelOrdersBySymbol(ctx, symbol) + if err != nil { + return err + } + + for _, o := range orders { + log.Info("CANCELED ", o.String()) + } } - - for _, o := range orders { - log.Info("CANCELED ", o.String()) - } - - } else if ok && len(symbol) > 0 { - log.Infof("canceling orders by symbol: %s", symbol) - - orders, err := e.CancelOrdersBySymbol(ctx, symbol) - if err != nil { - return err - } - - for _, o := range orders { - log.Info("CANCELED ", o.String()) - } - } else if len(symbol) > 0 { openOrders, err := session.Exchange.QueryOpenOrders(ctx, symbol) if err != nil { diff --git a/pkg/exchange/max/maxapi/order.go b/pkg/exchange/max/maxapi/order.go index 1d6a8f4bc..ea5900a10 100644 --- a/pkg/exchange/max/maxapi/order.go +++ b/pkg/exchange/max/maxapi/order.go @@ -243,25 +243,40 @@ type OrderCancelAllRequest struct { client *RestClient params OrderCancelAllRequestParams + + side *string + market *string + groupID *int64 } func (r *OrderCancelAllRequest) Side(side string) *OrderCancelAllRequest { - r.params.Side = side + r.side = &side return r } func (r *OrderCancelAllRequest) Market(market string) *OrderCancelAllRequest { - r.params.Market = market + r.market = &market return r } func (r *OrderCancelAllRequest) GroupID(groupID int64) *OrderCancelAllRequest { - r.params.GroupID = groupID + r.groupID = &groupID return r } func (r *OrderCancelAllRequest) Do(ctx context.Context) (orders []Order, err error) { - req, err := r.client.newAuthenticatedRequest("POST", "v2/orders/clear", &r.params) + var payload = map[string]interface{}{} + if r.side != nil { + payload["side"] = *r.side + } + if r.market != nil { + payload["market"] = *r.market + } + if r.groupID != nil { + payload["groupID"] = *r.groupID + } + + req, err := r.client.newAuthenticatedRequest("POST", "v2/orders/clear", payload) if err != nil { return }