mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-29 15:10:37 +00:00
requester: defer execution of request.Item generation in closure (#723)
* requester: defer execution of request.Item generation in closure. * bithumb: fix issue * coinut/itbit: fix linter issues * binance: fix bug on recvWindow setting * requester: standardize sendpayload + add readme update * nonce: remove inc() function * request: defer unlockiflocked * binance: revert changes for open orders * btcmarkets: defer auth generation functionality, rm context deadline as this will be created just before sending HTTP request. * binance: move const to top * exmo: remove debug output as its generated in the requester function * ftx: defer auth functionality * requester: move error to top * bittrex: defer auth functionality * bitmex: defer auth functionality and remove deadline as generation occurs after rate limiting. * btse: defer auth functionality * coinbasepro: defer auth functionality and removed context deadline as this is generated after rate limiting * coinbene: defer auth functionality and remove context deadline as this is generated after rate limiting * huobi: defer auth functionality and remove context deadline as this is generated after rate limiting * huobi-futures: defer auth functionality and remove context deadline as this is generated after rate limiting * kraken: defer auth functionality and remove context deadline as this is generated after rate limiting * kraken: remove deadline protection for timestamp generation * okgroup: defer auth functionality and remove context deadline as this is generated after rate limiting * poloniex: defer auth functionality * zb: defer auth functionality and remove context deadline as this is generated after rate limiting * exchanges: clean up log output which are done and inspected in the requester package * binance: fix path bug on every retry, rm timeout context as this is not needed * coinbene: fix path bug on retry * binance: consolidate functionality * coinbene: fix linter issues * poloniex: linter fix * kraken: change add -> set * bitstamp: fix path bug for retry * BTSE: fix retry path bug * coinbene: fix path bug whoopsie by me * gateio: fix bug where on retry it does not reset reader * localbitcoins: fix path bug on retry * zb: change domain to land * exchanges: make sure io.Reader is generated every request * exchanges: move reader generation into function scope * wrapper_issues: setup exchange manager * engine: expand withdraw manager test * engine: dont look for environment * bitstamp: fix pathing bug (@thrasher-) * engine/withdraw_manager: purge tests as this is covered in repository withdraw
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package bitmex
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -807,35 +806,24 @@ func (b *Bitmex) SendHTTPRequest(ep exchange.URL, path string, params Parameter,
|
||||
return err
|
||||
}
|
||||
path = endpoint + path
|
||||
if params != nil {
|
||||
var encodedPath string
|
||||
if !params.IsNil() {
|
||||
encodedPath, err = params.ToURLVals(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = b.SendPayload(context.Background(), &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: encodedPath,
|
||||
Result: &respCheck,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return b.CaptureError(respCheck, result)
|
||||
if params != nil && !params.IsNil() {
|
||||
path, err = params.ToURLVals(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
err = b.SendPayload(context.Background(), &request.Item{
|
||||
item := &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: path,
|
||||
Result: &respCheck,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
}
|
||||
|
||||
err = b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -853,52 +841,52 @@ func (b *Bitmex) SendAuthenticatedHTTPRequest(ep exchange.URL, verb, path string
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
expires := time.Now().Add(time.Second * 10)
|
||||
timestamp := expires.UnixNano()
|
||||
timestampStr := strconv.FormatInt(timestamp, 10)
|
||||
timestampNew := timestampStr[:13]
|
||||
|
||||
headers := make(map[string]string)
|
||||
headers["Content-Type"] = "application/json"
|
||||
headers["api-expires"] = timestampNew
|
||||
headers["api-key"] = b.API.Credentials.Key
|
||||
|
||||
var payload string
|
||||
if params != nil {
|
||||
err = params.VerifyData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var data []byte
|
||||
data, err = json.Marshal(params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
payload = string(data)
|
||||
}
|
||||
|
||||
hmac := crypto.GetHMAC(crypto.HashSHA256,
|
||||
[]byte(verb+"/api/v1"+path+timestampNew+payload),
|
||||
[]byte(b.API.Credentials.Secret))
|
||||
|
||||
headers["api-signature"] = crypto.HexEncodeToString(hmac)
|
||||
|
||||
var respCheck interface{}
|
||||
newRequest := func() (*request.Item, error) {
|
||||
expires := time.Now().Add(time.Second * 10)
|
||||
timestamp := expires.UnixNano()
|
||||
timestampStr := strconv.FormatInt(timestamp, 10)
|
||||
timestampNew := timestampStr[:13]
|
||||
|
||||
ctx, cancel := context.WithDeadline(context.Background(), expires)
|
||||
defer cancel()
|
||||
err = b.SendPayload(ctx, &request.Item{
|
||||
Method: verb,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: bytes.NewBuffer([]byte(payload)),
|
||||
Result: &respCheck,
|
||||
AuthRequest: true,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
Endpoint: request.Auth,
|
||||
})
|
||||
headers := make(map[string]string)
|
||||
headers["Content-Type"] = "application/json"
|
||||
headers["api-expires"] = timestampNew
|
||||
headers["api-key"] = b.API.Credentials.Key
|
||||
|
||||
var payload string
|
||||
if params != nil {
|
||||
err = params.VerifyData()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var data []byte
|
||||
data, err = json.Marshal(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
payload = string(data)
|
||||
}
|
||||
|
||||
hmac := crypto.GetHMAC(crypto.HashSHA256,
|
||||
[]byte(verb+"/api/v1"+path+timestampNew+payload),
|
||||
[]byte(b.API.Credentials.Secret))
|
||||
|
||||
headers["api-signature"] = crypto.HexEncodeToString(hmac)
|
||||
|
||||
return &request.Item{
|
||||
Method: verb,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: strings.NewReader(payload),
|
||||
Result: &respCheck,
|
||||
AuthRequest: true,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
}, nil
|
||||
}
|
||||
err = b.SendPayload(context.Background(), request.Auth, newRequest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user