Request package update & rate limit system expansion (#413)

* 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
This commit is contained in:
Ryan O'Hara-Reid
2020-02-06 11:44:28 +11:00
committed by GitHub
parent 4625ef9b94
commit 0a84c5d97a
103 changed files with 3906 additions and 2581 deletions

View File

@@ -7,11 +7,13 @@ import (
"net/url"
"strconv"
"strings"
"time"
"github.com/thrasher-corp/gocryptotrader/common"
"github.com/thrasher-corp/gocryptotrader/common/crypto"
"github.com/thrasher-corp/gocryptotrader/currency"
exchange "github.com/thrasher-corp/gocryptotrader/exchanges"
"github.com/thrasher-corp/gocryptotrader/exchanges/request"
log "github.com/thrasher-corp/gocryptotrader/logger"
)
@@ -40,8 +42,8 @@ const (
exmoWalletHistory = "wallet_history"
// Rate limit: 180 per/minute
exmoAuthRate = 180
exmoUnauthRate = 180
exmoRateInterval = time.Minute
exmoRequestRate = 180
)
// EXMO exchange struct
@@ -303,16 +305,14 @@ func (e *EXMO) GetWalletHistory(date int64) (WalletHistory, error) {
// SendHTTPRequest sends an unauthenticated HTTP request
func (e *EXMO) SendHTTPRequest(path string, result interface{}) error {
return e.SendPayload(http.MethodGet,
path,
nil,
nil,
result,
false,
false,
e.Verbose,
e.HTTPDebugging,
e.HTTPRecording)
return e.SendPayload(&request.Item{
Method: http.MethodGet,
Path: path,
Result: result,
Verbose: e.Verbose,
HTTPDebugging: e.HTTPDebugging,
HTTPRecording: e.HTTPRecording,
})
}
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request
@@ -344,16 +344,18 @@ func (e *EXMO) SendAuthenticatedHTTPRequest(method, endpoint string, vals url.Va
path := fmt.Sprintf("%s/v%s/%s", e.API.Endpoints.URL, exmoAPIVersion, endpoint)
return e.SendPayload(method,
path,
headers,
strings.NewReader(payload),
result,
true,
true,
e.Verbose,
e.HTTPDebugging,
e.HTTPRecording)
return e.SendPayload(&request.Item{
Method: method,
Path: path,
Headers: headers,
Body: strings.NewReader(payload),
Result: result,
AuthRequest: true,
NonceEnabled: true,
Verbose: e.Verbose,
HTTPDebugging: e.HTTPDebugging,
HTTPRecording: e.HTTPRecording,
})
}
// GetFee returns an estimate of fee based on type of transaction

View File

@@ -106,9 +106,8 @@ func (e *EXMO) SetDefaults() {
}
e.Requester = request.New(e.Name,
request.NewRateLimit(time.Minute, exmoAuthRate),
request.NewRateLimit(time.Minute, exmoUnauthRate),
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
request.NewBasicRateLimit(exmoRateInterval, exmoRequestRate))
e.API.Endpoints.URLDefault = exmoAPIURL
e.API.Endpoints.URL = e.API.Endpoints.URLDefault