mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 14:55:16 +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) {
|
||||
|
@ -106,9 +110,13 @@ func (e *GeneralOrderExecutor) SubmitOrders(ctx context.Context, submitOrders ..
|
|||
}
|
||||
|
||||
createdOrders, err := e.session.Exchange.SubmitOrders(ctx, formattedOrders...)
|
||||
if err != nil {
|
||||
// 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...)
|
||||
e.activeMakerOrders.Add(createdOrders...)
|
||||
|
@ -122,8 +130,11 @@ func (e *GeneralOrderExecutor) GracefulCancelActiveOrderBook(ctx context.Context
|
|||
return nil
|
||||
}
|
||||
if err := activeOrders.GracefulCancel(ctx, e.session.Exchange); err != nil {
|
||||
// Retry once
|
||||
if err = activeOrders.GracefulCancel(ctx, e.session.Exchange); err != nil {
|
||||
return fmt.Errorf("graceful cancel order error: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
e.tradeCollector.Process()
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user