mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-16 12:03:51 +00:00
20 lines
400 B
Go
20 lines
400 B
Go
package util
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"golang.org/x/time/rate"
|
|
)
|
|
|
|
func ShouldDelay(l *rate.Limiter, minInterval time.Duration) time.Duration {
|
|
return l.Reserve().Delay()
|
|
}
|
|
|
|
func NewValidLimiter(r rate.Limit, b int) (*rate.Limiter, error) {
|
|
if b <= 0 || r <= 0 {
|
|
return nil, fmt.Errorf("Bad rate limit config. Insufficient tokens. (rate=%f, b=%d)", r, b)
|
|
}
|
|
return rate.NewLimiter(r, b), nil
|
|
}
|