mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
Merge pull request #873 from andycheng123/improve/retry-submit-order
improve: generalorderexecutor retries submit/cancel order once
This commit is contained in:
commit
88ca021b3d
|
@ -96,7 +96,11 @@ func (e *GeneralOrderExecutor) Bind() {
|
|||
|
||||
// CancelOrders cancels the given order objects directly
|
||||
func (e *GeneralOrderExecutor) CancelOrders(ctx context.Context, orders ...types.Order) error {
|
||||
return e.session.Exchange.CancelOrders(ctx, orders...)
|
||||
err := e.session.Exchange.CancelOrders(ctx, orders...)
|
||||
if err != nil { // Retry once
|
||||
err = e.session.Exchange.CancelOrders(ctx, orders...)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *GeneralOrderExecutor) SubmitOrders(ctx context.Context, submitOrders ...types.SubmitOrder) (types.OrderSlice, error) {
|
||||
|
@ -107,7 +111,11 @@ func (e *GeneralOrderExecutor) SubmitOrders(ctx context.Context, submitOrders ..
|
|||
|
||||
createdOrders, err := e.session.Exchange.SubmitOrders(ctx, formattedOrders...)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("can not place orders: %w", err)
|
||||
// Retry once
|
||||
createdOrders, err = e.session.Exchange.SubmitOrders(ctx, formattedOrders...)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("can not place orders: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
e.orderStore.Add(createdOrders...)
|
||||
|
@ -122,7 +130,10 @@ func (e *GeneralOrderExecutor) GracefulCancelActiveOrderBook(ctx context.Context
|
|||
return nil
|
||||
}
|
||||
if err := activeOrders.GracefulCancel(ctx, e.session.Exchange); err != nil {
|
||||
return fmt.Errorf("graceful cancel order error: %w", err)
|
||||
// Retry once
|
||||
if err = activeOrders.GracefulCancel(ctx, e.session.Exchange); err != nil {
|
||||
return fmt.Errorf("graceful cancel order error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
e.tradeCollector.Process()
|
||||
|
|
Loading…
Reference in New Issue
Block a user