Skip to content

Commit

Permalink
bbgo: pull out retry parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
c9s committed Mar 1, 2023
1 parent 81a447f commit 80ce316
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions pkg/bbgo/order_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,14 +342,20 @@ func BatchRetryPlaceOrder(ctx context.Context, exchange types.Exchange, errIdx [
defer cancelTimeout()

// if we got any error, we should re-iterate the errored orders
for len(errIdx) > 0 {
coolDownTime := 200 * time.Millisecond

// set backoff max retries to 101 because https://ja.wikipedia.org/wiki/101%E5%9B%9E%E7%9B%AE%E3%81%AE%E3%83%97%E3%83%AD%E3%83%9D%E3%83%BC%E3%82%BA
backoffMaxRetries := uint64(101)
for retryRound := 0; len(errIdx) > 0 && retryRound < 10; retryRound++ {
// sleep for 200 millisecond between each retry
time.Sleep(200 * time.Millisecond)
log.Warnf("retry round #%d, cooling down for %s", retryRound+1, coolDownTime)
time.Sleep(coolDownTime)

// reset error index since it's a new retry
errIdxNext = nil

// iterate the error index and re-submit the order
log.Warnf("starting retry round #%d...", retryRound+1)
for _, idx := range errIdxNext {
submitOrder := submitOrders[idx]

Expand All @@ -370,9 +376,8 @@ func BatchRetryPlaceOrder(ctx context.Context, exchange types.Exchange, errIdx [
return err2
}

// if err2 := backoff.Retry(op, backoff.WithMaxRetries(backoff.NewExponentialBackOff(), 99)); err2 != nil {
var bo backoff.BackOff = backoff.NewExponentialBackOff()
bo = backoff.WithMaxRetries(bo, 99)
bo = backoff.WithMaxRetries(bo, backoffMaxRetries)
bo = backoff.WithContext(bo, timeoutCtx)
if err2 := backoff.Retry(op, bo); err2 != nil {
werr = multierr.Append(werr, err2)
Expand All @@ -385,5 +390,4 @@ func BatchRetryPlaceOrder(ctx context.Context, exchange types.Exchange, errIdx [
}

return createdOrders, errIdx, werr
// return BatchRetryPlaceOrder(ctx, exchange, errIdxNext, orderCallback, submitOrders...)
}

0 comments on commit 80ce316

Please sign in to comment.