Merge pull request #873 from andycheng123/improve/retry-submit-order

improve: generalorderexecutor retries submit/cancel order once
This commit is contained in:
Andy Cheng 2022-08-11 17:27:29 +08:00 committed by GitHub
commit 88ca021b3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -96,7 +96,11 @@ func (e *GeneralOrderExecutor) Bind() {
// CancelOrders cancels the given order objects directly // CancelOrders cancels the given order objects directly
func (e *GeneralOrderExecutor) CancelOrders(ctx context.Context, orders ...types.Order) error { 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) { 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...) createdOrders, err := e.session.Exchange.SubmitOrders(ctx, formattedOrders...)
if err != nil {
// Retry once
createdOrders, err = e.session.Exchange.SubmitOrders(ctx, formattedOrders...)
if err != nil { if err != nil {
err = fmt.Errorf("can not place orders: %w", err) err = fmt.Errorf("can not place orders: %w", err)
} }
}
e.orderStore.Add(createdOrders...) e.orderStore.Add(createdOrders...)
e.activeMakerOrders.Add(createdOrders...) e.activeMakerOrders.Add(createdOrders...)
@ -122,8 +130,11 @@ func (e *GeneralOrderExecutor) GracefulCancelActiveOrderBook(ctx context.Context
return nil return nil
} }
if err := activeOrders.GracefulCancel(ctx, e.session.Exchange); err != 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) return fmt.Errorf("graceful cancel order error: %w", err)
} }
}
e.tradeCollector.Process() e.tradeCollector.Process()
return nil return nil