mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-02 15:10:46 +00:00
Update request.go to fix concurrency nonce issues (#285)
* Updates nonce generation to adhere to fifo channel buffer before request executes by routine * removed unused variables, lns etc * Fix requested changes and added in timer that disengages lock if out of scope error occurs * Fixed woopsy daisy issue * Add benchmark, reduce time in force to unlock before stack insertion, add nil check for edge case * Remove unusued waitgroup field * use return nonce.Value and method, rm redundant nonce code, fix tests. * Fix linter issue: unnecessary conversion
This commit is contained in:
committed by
Adrian Gallagher
parent
1967507d40
commit
35b94268e0
@@ -543,7 +543,7 @@ func (b *Bithumb) MarketSellOrder(currency string, units float64) (MarketSell, e
|
||||
|
||||
// SendHTTPRequest sends an unauthenticated HTTP request
|
||||
func (b *Bithumb) SendHTTPRequest(path string, result interface{}) error {
|
||||
return b.SendPayload(http.MethodGet, path, nil, nil, result, false, b.Verbose)
|
||||
return b.SendPayload(http.MethodGet, path, nil, nil, result, false, false, b.Verbose)
|
||||
}
|
||||
|
||||
// SendAuthenticatedHTTPRequest sends an authenticated HTTP request to bithumb
|
||||
@@ -556,15 +556,11 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
|
||||
params = url.Values{}
|
||||
}
|
||||
|
||||
if b.Nonce.Get() == 0 {
|
||||
b.Nonce.Set(time.Now().UnixNano() / int64(time.Millisecond))
|
||||
} else {
|
||||
b.Nonce.Inc()
|
||||
}
|
||||
n := b.Requester.GetNonceMilli().String()
|
||||
|
||||
params.Set("endpoint", path)
|
||||
payload := params.Encode()
|
||||
hmacPayload := path + string(0) + payload + string(0) + b.Nonce.String()
|
||||
hmacPayload := path + string(0) + payload + string(0) + n
|
||||
hmac := common.GetHMAC(common.HashSHA512,
|
||||
[]byte(hmacPayload),
|
||||
[]byte(b.APISecret))
|
||||
@@ -573,7 +569,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
|
||||
headers := make(map[string]string)
|
||||
headers["Api-Key"] = b.APIKey
|
||||
headers["Api-Sign"] = common.Base64Encode([]byte(hmacStr))
|
||||
headers["Api-Nonce"] = b.Nonce.String()
|
||||
headers["Api-Nonce"] = n
|
||||
headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
|
||||
var intermediary json.RawMessage
|
||||
@@ -589,6 +585,7 @@ func (b *Bithumb) SendAuthenticatedHTTPRequest(path string, params url.Values, r
|
||||
bytes.NewBufferString(payload),
|
||||
&intermediary,
|
||||
true,
|
||||
true,
|
||||
b.Verbose)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user