From b365021118c019394c03322d8b91ec64964179f3 Mon Sep 17 00:00:00 2001 From: c9s Date: Sat, 1 Jan 2022 00:51:02 +0800 Subject: [PATCH] kucoin: add history orders support --- examples/kucoin/orders.go | 44 +++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/examples/kucoin/orders.go b/examples/kucoin/orders.go index 7a5405c5c..bb260e1d7 100644 --- a/examples/kucoin/orders.go +++ b/examples/kucoin/orders.go @@ -2,6 +2,7 @@ package main import ( "context" + "time" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -26,6 +27,9 @@ func init() { placeOrderCmd.Flags().String("order-type", string(kucoinapi.OrderTypeLimit), "order type") placeOrderCmd.Flags().String("side", "", "buy or sell") ordersCmd.AddCommand(placeOrderCmd) + + historyOrdersCmd.Flags().String("symbol", "", "symbol, BTC-USDT, LTC-USDT...etc") + ordersCmd.AddCommand(historyOrdersCmd) } @@ -37,7 +41,6 @@ var ordersCmd = &cobra.Command{ SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { - req := client.TradeService.NewListOrdersRequest() symbol, err := cmd.Flags().GetString("symbol") if err != nil { @@ -48,14 +51,14 @@ var ordersCmd = &cobra.Command{ return errors.New("--symbol option is required") } - req.Symbol(symbol) - - status, err := cmd.Flags().GetString("status") if err != nil { return err } + req := client.TradeService.NewListOrdersRequest() + req.Symbol(symbol) + if len(status) > 0 { req.Status(status) } @@ -71,6 +74,39 @@ var ordersCmd = &cobra.Command{ } +// go run ./examples/kucoin orders history +var historyOrdersCmd = &cobra.Command{ + Use: "history [--symbol SYMBOL]", + + // SilenceUsage is an option to silence usage when an error occurs. + SilenceUsage: true, + + RunE: func(cmd *cobra.Command, args []string) error { + symbol, err := cmd.Flags().GetString("symbol") + if err != nil { + return err + } + + if len(symbol) == 0 { + return errors.New("--symbol option is required") + } + + req := client.TradeService.NewListHistoryOrdersRequest() + req.Symbol(symbol) + req.StartAt(time.Now().AddDate(0, -2, 0)) + + page, err := req.Do(context.Background()) + if err != nil { + return err + } + + logrus.Infof("page: %+v", page) + return nil + }, +} + + + // usage: // go run ./examples/kucoin orders place --symbol LTC-USDT --price 50 --size 1 --order-type limit --side buy var placeOrderCmd = &cobra.Command{