kucoin: implement QueryClosedOrders

This commit is contained in:
c9s 2021-12-26 01:34:03 +08:00
parent 0cef2c52ef
commit 8c03147ff4
2 changed files with 30 additions and 2 deletions

View File

@ -134,8 +134,9 @@ func toGlobalOrderStatus(o kucoinapi.Order) types.OrderStatus {
var status types.OrderStatus var status types.OrderStatus
if o.IsActive { if o.IsActive {
status = types.OrderStatusNew status = types.OrderStatusNew
} else if o.DealSize > 0 { if o.DealSize > 0 {
status = types.OrderStatusPartiallyFilled status = types.OrderStatusPartiallyFilled
}
} else if o.CancelExist { } else if o.CancelExist {
status = types.OrderStatusCanceled status = types.OrderStatusCanceled
} else { } else {

View File

@ -27,6 +27,7 @@ type Exchange struct {
client *kucoinapi.RestClient client *kucoinapi.RestClient
} }
func New(key, secret, passphrase string) *Exchange { func New(key, secret, passphrase string) *Exchange {
client := kucoinapi.NewClient() client := kucoinapi.NewClient()
@ -225,6 +226,32 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
return orders, err 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) { func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (errs error) {
for _, o := range orders { for _, o := range orders {
req := e.client.TradeService.NewCancelOrderRequest() req := e.client.TradeService.NewCancelOrderRequest()