From 8c03147ff43fd54e0148a71196f27bb467cfcd7a Mon Sep 17 00:00:00 2001 From: c9s Date: Sun, 26 Dec 2021 01:34:03 +0800 Subject: [PATCH] kucoin: implement QueryClosedOrders --- pkg/exchange/kucoin/convert.go | 5 +++-- pkg/exchange/kucoin/exchange.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/pkg/exchange/kucoin/convert.go b/pkg/exchange/kucoin/convert.go index 04d0c6a1f..70600e70d 100644 --- a/pkg/exchange/kucoin/convert.go +++ b/pkg/exchange/kucoin/convert.go @@ -134,8 +134,9 @@ func toGlobalOrderStatus(o kucoinapi.Order) types.OrderStatus { var status types.OrderStatus if o.IsActive { status = types.OrderStatusNew - } else if o.DealSize > 0 { - status = types.OrderStatusPartiallyFilled + if o.DealSize > 0 { + status = types.OrderStatusPartiallyFilled + } } else if o.CancelExist { status = types.OrderStatusCanceled } else { diff --git a/pkg/exchange/kucoin/exchange.go b/pkg/exchange/kucoin/exchange.go index 01efe4431..66418a52b 100644 --- a/pkg/exchange/kucoin/exchange.go +++ b/pkg/exchange/kucoin/exchange.go @@ -27,6 +27,7 @@ type Exchange struct { client *kucoinapi.RestClient } + func New(key, secret, passphrase string) *Exchange { client := kucoinapi.NewClient() @@ -225,6 +226,32 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [ return orders, err } +func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since, until time.Time, lastOrderID uint64) (orders []types.Order, err error) { + req := e.client.TradeService.NewListOrdersRequest() + req.Symbol(toLocalSymbol(symbol)) + req.Status("done") + req.EndAt(until) + req.StartAt(since) + + orderList, err := req.Do(ctx) + if err != nil { + return orders, err + } + + // TODO: support pagination (right now we can only get 50 items from the first page) + for _, o := range orderList.Items { + order := toGlobalOrder(o) + orders = append(orders, order) + } + + return orders, err +} + +func (e *Exchange) QueryTrades(ctx context.Context, symbol string, options *types.TradeQueryOptions) ([]types.Trade, error) { + panic("implement me") +} + + func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (errs error) { for _, o := range orders { req := e.client.TradeService.NewCancelOrderRequest()