mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 16:25:16 +00:00
types: add and use OrderError
This commit is contained in:
parent
857db529af
commit
b302adcc7e
|
@ -545,15 +545,15 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
|
|||
if o.OrderID > 0 {
|
||||
req.OrderID(int64(o.OrderID))
|
||||
} else {
|
||||
err = multierr.Append(err, fmt.Errorf(
|
||||
"can not cancel %s order, order does not contain orderID or clientOrderID. %#v",
|
||||
o.Symbol, o))
|
||||
err = multierr.Append(err, types.NewOrderError(
|
||||
fmt.Errorf("can not cancel %s order, order does not contain orderID or clientOrderID", o.Symbol),
|
||||
o))
|
||||
continue
|
||||
}
|
||||
|
||||
_, err2 := req.Do(ctx)
|
||||
if err2 != nil {
|
||||
err = multierr.Append(err, err2)
|
||||
err = multierr.Append(err, types.NewOrderError(err2, o))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -571,20 +571,15 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
|
|||
} else if len(o.ClientOrderID) > 0 {
|
||||
req.OrigClientOrderID(o.ClientOrderID)
|
||||
} else {
|
||||
err = multierr.Append(err, fmt.Errorf(
|
||||
"can not cancel %s order, order does not contain orderID or clientOrderID. %#v",
|
||||
o.Symbol, o))
|
||||
err = multierr.Append(err, types.NewOrderError(
|
||||
fmt.Errorf("can not cancel %s order, order does not contain orderID or clientOrderID", o.Symbol),
|
||||
o))
|
||||
continue
|
||||
}
|
||||
|
||||
_, err2 := req.Do(ctx)
|
||||
if err2 != nil {
|
||||
err = multierr.Append(err, errors.Wrapf(
|
||||
err2, "can not cancel %s order. orderID: %d clientOrderID: %s order: %#v",
|
||||
o.Symbol,
|
||||
o.OrderID,
|
||||
o.ClientOrderID,
|
||||
o))
|
||||
err = multierr.Append(err, types.NewOrderError(err2, o))
|
||||
}
|
||||
} else {
|
||||
// SPOT
|
||||
|
@ -596,20 +591,15 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) (err
|
|||
} else if len(o.ClientOrderID) > 0 {
|
||||
req.OrigClientOrderID(o.ClientOrderID)
|
||||
} else {
|
||||
err = multierr.Append(err, fmt.Errorf(
|
||||
"can not cancel %s order, order does not contain orderID or clientOrderID. order: %#v",
|
||||
o.Symbol, o))
|
||||
err = multierr.Append(err, types.NewOrderError(
|
||||
fmt.Errorf("can not cancel %s order, order does not contain orderID or clientOrderID", o.Symbol),
|
||||
o))
|
||||
continue
|
||||
}
|
||||
|
||||
_, err2 := req.Do(ctx)
|
||||
if err2 != nil {
|
||||
err = multierr.Append(err, errors.Wrapf(
|
||||
err2, "can not cancel %s order. orderID: %d clientOrderID: %s order: %#v",
|
||||
o.Symbol,
|
||||
o.OrderID,
|
||||
o.ClientOrderID,
|
||||
o))
|
||||
err = multierr.Append(err, types.NewOrderError(err2, o))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
23
pkg/types/error.go
Normal file
23
pkg/types/error.go
Normal file
|
@ -0,0 +1,23 @@
|
|||
package types
|
||||
|
||||
import "fmt"
|
||||
|
||||
type OrderError struct {
|
||||
error error
|
||||
order Order
|
||||
}
|
||||
|
||||
func (e *OrderError) Error() string {
|
||||
return fmt.Sprintf("%s exchange: %s orderID:%d", e.error.Error(), e.order.Exchange, e.order.OrderID)
|
||||
}
|
||||
|
||||
func (e *OrderError) Order() Order {
|
||||
return e.order
|
||||
}
|
||||
|
||||
func NewOrderError(e error, o Order) error {
|
||||
return &OrderError{
|
||||
error: e,
|
||||
order: o,
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user