mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-13 23:16:45 +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:
@@ -347,7 +347,7 @@ func (b *Bittrex) SendHTTPRequest(ep exchange.URL, path string, result interface
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
requestItem := request.Item{
|
||||
item := &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
@@ -356,7 +356,7 @@ func (b *Bittrex) SendHTTPRequest(ep exchange.URL, path string, result interface
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
HeaderResponse: resultHeader,
|
||||
}
|
||||
return b.SendPayload(context.Background(), &requestItem)
|
||||
return b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) { return item, nil })
|
||||
}
|
||||
|
||||
// SendAuthHTTPRequest sends an authenticated request
|
||||
@@ -369,46 +369,50 @@ func (b *Bittrex) SendAuthHTTPRequest(ep exchange.URL, method, action string, pa
|
||||
return err
|
||||
}
|
||||
|
||||
ts := strconv.FormatInt(time.Now().UnixNano()/1000000, 10)
|
||||
newRequest := func() (*request.Item, error) {
|
||||
ts := strconv.FormatInt(time.Now().UnixNano()/1000000, 10)
|
||||
path := common.EncodeURLValues(action, params)
|
||||
|
||||
path := common.EncodeURLValues(action, params)
|
||||
|
||||
var body io.Reader
|
||||
var hmac, payload []byte
|
||||
var contentHash string
|
||||
if data == nil {
|
||||
payload = []byte("")
|
||||
} else {
|
||||
var err error
|
||||
payload, err = json.Marshal(data)
|
||||
if err != nil {
|
||||
return err
|
||||
var body io.Reader
|
||||
var hmac, payload []byte
|
||||
var contentHash string
|
||||
if data == nil {
|
||||
payload = []byte("")
|
||||
} else {
|
||||
var err error
|
||||
payload, err = json.Marshal(data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
body = bytes.NewBuffer(payload)
|
||||
contentHash = crypto.HexEncodeToString(crypto.GetSHA512(payload))
|
||||
sigPayload := ts + endpoint + path + method + contentHash
|
||||
hmac = crypto.GetHMAC(crypto.HashSHA512, []byte(sigPayload), []byte(b.API.Credentials.Secret))
|
||||
body = bytes.NewBuffer(payload)
|
||||
contentHash = crypto.HexEncodeToString(crypto.GetSHA512(payload))
|
||||
sigPayload := ts + endpoint + path + method + contentHash
|
||||
hmac = crypto.GetHMAC(crypto.HashSHA512, []byte(sigPayload), []byte(b.API.Credentials.Secret))
|
||||
|
||||
headers := make(map[string]string)
|
||||
headers["Api-Key"] = b.API.Credentials.Key
|
||||
headers["Api-Timestamp"] = ts
|
||||
headers["Api-Content-Hash"] = contentHash
|
||||
headers["Api-Signature"] = crypto.HexEncodeToString(hmac)
|
||||
headers["Content-Type"] = "application/json"
|
||||
headers["Accept"] = "application/json"
|
||||
return b.SendPayload(context.Background(), &request.Item{
|
||||
Method: method,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: body,
|
||||
Result: result,
|
||||
AuthRequest: true,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
HeaderResponse: resultHeader,
|
||||
})
|
||||
headers := make(map[string]string)
|
||||
headers["Api-Key"] = b.API.Credentials.Key
|
||||
headers["Api-Timestamp"] = ts
|
||||
headers["Api-Content-Hash"] = contentHash
|
||||
headers["Api-Signature"] = crypto.HexEncodeToString(hmac)
|
||||
headers["Content-Type"] = "application/json"
|
||||
headers["Accept"] = "application/json"
|
||||
|
||||
return &request.Item{
|
||||
Method: method,
|
||||
Path: endpoint + path,
|
||||
Headers: headers,
|
||||
Body: body,
|
||||
Result: result,
|
||||
AuthRequest: true,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
HeaderResponse: resultHeader,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return b.SendPayload(context.Background(), request.Unset, newRequest)
|
||||
}
|
||||
|
||||
// GetFee returns an estimate of fee based on type of transaction
|
||||
|
||||
@@ -132,13 +132,16 @@ func (b *Bittrex) WsSignalRHandshake(result interface{}) error {
|
||||
return err
|
||||
}
|
||||
path := "/negotiate?connectionData=[{name:\"c3\"}]&clientProtocol=1.5"
|
||||
return b.SendPayload(context.Background(), &request.Item{
|
||||
item := &request.Item{
|
||||
Method: http.MethodGet,
|
||||
Path: endpoint + path,
|
||||
Result: result,
|
||||
Verbose: b.Verbose,
|
||||
HTTPDebugging: b.HTTPDebugging,
|
||||
HTTPRecording: b.HTTPRecording,
|
||||
}
|
||||
return b.SendPayload(context.Background(), request.Unset, func() (*request.Item, error) {
|
||||
return item, nil
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user