forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ratelimit.go
41 lines (35 loc) · 1018 Bytes
/
ratelimit.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 [email protected].
// As per https://docs.poloniex.com/#http-api
func SetRateLimit() *RateLimit {
return &RateLimit{
Auth: request.NewRateLimit(poloniexRateInterval, poloniexAuthRate),
UnAuth: request.NewRateLimit(poloniexRateInterval, poloniexUnauthRate),
}
}