From ae5bd507a861ed2b288a867dd9106f22cdf8b83b Mon Sep 17 00:00:00 2001 From: c9s Date: Thu, 2 Mar 2023 17:17:18 +0800 Subject: [PATCH] bbgo: add BBGO_SUBMIT_ORDER_RETRY_TIMEOUT env var for overriding timeout --- pkg/bbgo/order_execution.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkg/bbgo/order_execution.go b/pkg/bbgo/order_execution.go index a4a52c095..d5f8fc2a0 100644 --- a/pkg/bbgo/order_execution.go +++ b/pkg/bbgo/order_execution.go @@ -12,8 +12,17 @@ import ( "github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/types" + "github.com/c9s/bbgo/pkg/util" ) +var DefaultSubmitOrderRetryTimeout = 5 * time.Minute + +func init() { + if du, ok := util.GetEnvVarDuration("BBGO_SUBMIT_ORDER_RETRY_TIMEOUT"); ok && du > 0 { + DefaultSubmitOrderRetryTimeout = du + } +} + type OrderExecutor interface { SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error) CancelOrders(ctx context.Context, orders ...types.Order) error @@ -342,7 +351,7 @@ func BatchRetryPlaceOrder(ctx context.Context, exchange types.Exchange, errIdx [ errIdx = errIdxNext } - timeoutCtx, cancelTimeout := context.WithTimeout(ctx, 30*time.Minute) + timeoutCtx, cancelTimeout := context.WithTimeout(ctx, DefaultSubmitOrderRetryTimeout) defer cancelTimeout() // if we got any error, we should re-iterate the errored orders