retry: fix and improve QueryOrderUntilFilled status check

This commit is contained in:
c9s 2024-02-21 16:54:25 +08:00
parent ac181959e5
commit c68832459d
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -2,7 +2,6 @@ package retry
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"strconv" "strconv"
@ -54,15 +53,17 @@ func QueryOrderUntilFilled(
OrderID: strconv.FormatUint(orderId, 10), OrderID: strconv.FormatUint(orderId, 10),
}) })
if err2 != nil || o == nil { if err2 != nil {
return err2 return err2
} }
if o.Status != types.OrderStatusFilled { // for final status return nil error to stop the retry
return errors.New("order is not filled yet") switch o.Status {
case types.OrderStatusFilled, types.OrderStatusCanceled:
return nil
} }
return err2 return fmt.Errorf("order is not filled yet: status=%s E/Q=%s/%s", o.Status, o.ExecutedQuantity.String(), o.Quantity.String())
} }
err = GeneralBackoff(ctx, op) err = GeneralBackoff(ctx, op)