bbgo: add BBGO_SUBMIT_ORDER_RETRY_TIMEOUT env var for overriding timeout

This commit is contained in:
c9s 2023-03-02 17:17:18 +08:00
parent f4b012623f
commit ae5bd507a8
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -12,8 +12,17 @@ import (
"github.com/c9s/bbgo/pkg/fixedpoint" "github.com/c9s/bbgo/pkg/fixedpoint"
"github.com/c9s/bbgo/pkg/types" "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 { type OrderExecutor interface {
SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error) SubmitOrders(ctx context.Context, orders ...types.SubmitOrder) (createdOrders types.OrderSlice, err error)
CancelOrders(ctx context.Context, orders ...types.Order) error CancelOrders(ctx context.Context, orders ...types.Order) error
@ -342,7 +351,7 @@ func BatchRetryPlaceOrder(ctx context.Context, exchange types.Exchange, errIdx [
errIdx = errIdxNext errIdx = errIdxNext
} }
timeoutCtx, cancelTimeout := context.WithTimeout(ctx, 30*time.Minute) timeoutCtx, cancelTimeout := context.WithTimeout(ctx, DefaultSubmitOrderRetryTimeout)
defer cancelTimeout() defer cancelTimeout()
// if we got any error, we should re-iterate the errored orders // if we got any error, we should re-iterate the errored orders