mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-19 07:26:49 +00:00
* Initial rework of rework of requester - WIP * Implementing and checking rate limits - WIP * implemented coinbene rate limiting shenanigans * add in remaining WIP * fixy * use authenticated rate limit * drop ceiling as this can be done with a counter later * add functionality to struct * purge config options for rate limiting so as to keep things minimal * prepare futures and swap rate limiting for implementation * Address linter issues * Addressed nits, fixed race * fix linter issue * remove global var as this was only setting when newrequester was called * moved rate limit functionality into its own file * Update Bitfinex with correct rate limit and test endpoints (WIP) * finish off bitfinex adjustments * fixes * fix linter issues * slowed rate for coinbasepro * drop rate limit for huobi as the doc times have intermittent 429 issues. * Set MACOSX_DEPLOYMENT_TARGET to remove linking warning * Addr Thrasher nits * Addr glorious nits * unexport do request function * fixed nitorinos * Fixed something I missed * move disabled rate limiter into loadexchange and use interface functionality * Add temp quick fix
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package btcmarkets
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
|
|
"golang.org/x/time/rate"
|
|
)
|
|
|
|
// BTCMarkets Rate limit consts
|
|
const (
|
|
btcmarketsRateInterval = time.Second * 10
|
|
btcmarketsAuthLimit = 50
|
|
btcmarketsUnauthLimit = 50
|
|
btcmarketsOrderLimit = 30
|
|
btcmarketsBatchOrderLimit = 5
|
|
btcmarketsWithdrawLimit = 10
|
|
btcmarketsCreateNewReportLimit = 1
|
|
|
|
// Used to match endpints to rate limits
|
|
orderFunc request.EndpointLimit = iota
|
|
batchFunc
|
|
withdrawFunc
|
|
newReportFunc
|
|
)
|
|
|
|
// RateLimit implements the request.Limiter interface
|
|
type RateLimit struct {
|
|
Auth *rate.Limiter
|
|
UnAuth *rate.Limiter
|
|
OrderPlacement *rate.Limiter
|
|
BatchOrders *rate.Limiter
|
|
WithdrawRequest *rate.Limiter
|
|
CreateNewReport *rate.Limiter
|
|
}
|
|
|
|
// Limit limits the outbound requests
|
|
func (r *RateLimit) Limit(f request.EndpointLimit) error {
|
|
switch f {
|
|
case request.Auth:
|
|
time.Sleep(r.Auth.Reserve().Delay())
|
|
case orderFunc:
|
|
time.Sleep(r.OrderPlacement.Reserve().Delay())
|
|
case batchFunc:
|
|
time.Sleep(r.BatchOrders.Reserve().Delay())
|
|
case withdrawFunc:
|
|
time.Sleep(r.WithdrawRequest.Reserve().Delay())
|
|
case newReportFunc:
|
|
time.Sleep(r.CreateNewReport.Reserve().Delay())
|
|
default:
|
|
time.Sleep(r.UnAuth.Reserve().Delay())
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// SetRateLimit returns the rate limit for the exchange
|
|
func SetRateLimit() *RateLimit {
|
|
return &RateLimit{
|
|
Auth: request.NewRateLimit(btcmarketsRateInterval, btcmarketsAuthLimit),
|
|
UnAuth: request.NewRateLimit(btcmarketsRateInterval, btcmarketsUnauthLimit),
|
|
OrderPlacement: request.NewRateLimit(btcmarketsRateInterval, btcmarketsOrderLimit),
|
|
BatchOrders: request.NewRateLimit(btcmarketsRateInterval, btcmarketsBatchOrderLimit),
|
|
WithdrawRequest: request.NewRateLimit(btcmarketsRateInterval, btcmarketsWithdrawLimit),
|
|
CreateNewReport: request.NewRateLimit(btcmarketsRateInterval, btcmarketsCreateNewReportLimit),
|
|
}
|
|
}
|