kucoin: fix kucoin order query

This commit is contained in:
c9s 2022-01-01 01:28:29 +08:00
parent 1652c17e33
commit 6d5ab33d17
3 changed files with 16 additions and 3 deletions

View File

@ -106,7 +106,6 @@ var historyOrdersCmd = &cobra.Command{
} }
// usage: // usage:
// go run ./examples/kucoin orders place --symbol LTC-USDT --price 50 --size 1 --order-type limit --side buy // go run ./examples/kucoin orders place --symbol LTC-USDT --price 50 --size 1 --order-type limit --side buy
var placeOrderCmd = &cobra.Command{ var placeOrderCmd = &cobra.Command{

View File

@ -295,15 +295,24 @@ func (e *Exchange) QueryClosedOrders(ctx context.Context, symbol string, since,
req := e.client.TradeService.NewListOrdersRequest() req := e.client.TradeService.NewListOrdersRequest()
req.Symbol(toLocalSymbol(symbol)) req.Symbol(toLocalSymbol(symbol))
req.Status("done") req.Status("done")
req.EndAt(until)
req.StartAt(since) req.StartAt(since)
// kucoin:
// When you query orders in active status, there is no time limit.
// However, when you query orders in done status, the start and end time range cannot exceed 7* 24 hours.
// An error will occur if the specified time window exceeds the range.
// If you specify the end time only, the system will automatically calculate the start time as end time minus 7*24 hours, and vice versa.
if until.Sub(since) < 7 * 24 * time.Hour {
req.EndAt(until)
} else {
req.EndAt(since.Add(7 * 24 * time.Hour - time.Minute))
}
orderList, err := req.Do(ctx) orderList, err := req.Do(ctx)
if err != nil { if err != nil {
return orders, err return orders, err
} }
// TODO: support pagination (right now we can only get 50 items from the first page)
for _, o := range orderList.Items { for _, o := range orderList.Items {
order := toGlobalOrder(o) order := toGlobalOrder(o)
orders = append(orders, order) orders = append(orders, order)

View File

@ -80,6 +80,11 @@ func (s *OrderService) Sync(ctx context.Context, exchange types.Exchange, symbol
continue continue
} }
// skip canceled and not filled orders
if order.Status == types.OrderStatusCanceled && order.ExecutedQuantity == 0.0 {
continue
}
if err := s.Insert(order); err != nil { if err := s.Insert(order); err != nil {
return err return err
} }