Files
gocryptotrader/exchanges/poloniex/ratelimit.go
Ryan O'Hara-Reid 232d6ebc1f rate limit: make context aware (#731)
* rate limits: Make context aware

* binance: rate limit allow for cancellation of reservation when deadline is exceeded

* request: add context.done() before initiating any bulk work.

* binance: update error return for rate limiting

* request: updated dealine check to remove after time.Now procedure as this will obfuscate a deadline which will be limited by the context check on every attempt, so no need to sleep with delay.
2021-08-10 12:08:27 +10:00

42 lines
1018 B
Go

package poloniex
import (
"context"
"time"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
"golang.org/x/time/rate"
)
const (
poloniexRateInterval = time.Second
poloniexAuthRate = 6
poloniexUnauthRate = 6
)
// RateLimit implements the request.Limiter interface
type RateLimit struct {
Auth *rate.Limiter
UnAuth *rate.Limiter
}
// Limit limits outbound calls
func (r *RateLimit) Limit(ctx context.Context, f request.EndpointLimit) error {
if f == request.Auth {
return r.Auth.Wait(ctx)
}
return r.UnAuth.Wait(ctx)
}
// SetRateLimit returns the rate limit for the exchange
// If your account's volume is over $5 million in 30 day volume,
// you may be eligible for an API rate limit increase.
// Please email poloniex@circle.com.
// As per https://docs.poloniex.com/#http-api
func SetRateLimit() *RateLimit {
return &RateLimit{
Auth: request.NewRateLimit(poloniexRateInterval, poloniexAuthRate),
UnAuth: request.NewRateLimit(poloniexRateInterval, poloniexUnauthRate),
}
}