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

@@ -13,6 +13,7 @@ import (
"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"
"github.com/thrasher-corp/gocryptotrader/exchanges/websocket/wshandler"
)
@@ -36,9 +37,6 @@ const (
gateioTickers = "tickers"
gateioOrderbook = "orderBook"
gateioAuthRate = 100
gateioUnauthRate = 100
gateioGenerateAddress = "New address is being generated for you, please wait a moment and refresh this page. "
)
@@ -311,16 +309,14 @@ func (g *Gateio) CancelExistingOrder(orderID int64, symbol string) (bool, error)
// SendHTTPRequest sends an unauthenticated HTTP request
func (g *Gateio) SendHTTPRequest(path string, result interface{}) error {
return g.SendPayload(http.MethodGet,
path,
nil,
nil,
result,
false,
false,
g.Verbose,
g.HTTPDebugging,
g.HTTPRecording)
return g.SendPayload(&request.Item{
Method: http.MethodGet,
Path: path,
Result: result,
Verbose: g.Verbose,
HTTPDebugging: g.HTTPDebugging,
HTTPRecording: g.HTTPRecording,
})
}
// CancelAllExistingOrders all orders for a given symbol and side
@@ -412,17 +408,17 @@ func (g *Gateio) SendAuthenticatedHTTPRequest(method, endpoint, param string, re
urlPath := fmt.Sprintf("%s/%s/%s", g.API.Endpoints.URL, gateioAPIVersion, endpoint)
var intermidiary json.RawMessage
err := g.SendPayload(method,
urlPath,
headers,
strings.NewReader(param),
&intermidiary,
true,
false,
g.Verbose,
g.HTTPDebugging,
g.HTTPRecording)
err := g.SendPayload(&request.Item{
Method: method,
Path: urlPath,
Headers: headers,
Body: strings.NewReader(param),
Result: &intermidiary,
AuthRequest: true,
Verbose: g.Verbose,
HTTPDebugging: g.HTTPDebugging,
HTTPRecording: g.HTTPRecording,
})
if err != nil {
return err
}

View File

@@ -114,9 +114,8 @@ func (g *Gateio) SetDefaults() {
}
g.Requester = request.New(g.Name,
request.NewRateLimit(time.Second*10, gateioAuthRate),
request.NewRateLimit(time.Second*10, gateioUnauthRate),
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout))
common.NewHTTPClientWithTimeout(exchange.DefaultHTTPTimeout),
nil)
g.API.Endpoints.URLDefault = gateioTradeURL
g.API.Endpoints.URL = g.API.Endpoints.URLDefault