mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-06-04 07:26:47 +00:00
Add nonce package for exchanges
This commit is contained in:
@@ -290,8 +290,14 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf
|
||||
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, a.Name)
|
||||
}
|
||||
|
||||
if a.Nonce.Get() == 0 {
|
||||
a.Nonce.Set(time.Now().UnixNano())
|
||||
} else {
|
||||
a.Nonce.Inc()
|
||||
}
|
||||
|
||||
request := make(map[string]interface{})
|
||||
request["nonce"] = strconv.FormatInt(time.Now().UnixNano(), 10)[0:13]
|
||||
request["nonce"] = a.Nonce.String()[0:13]
|
||||
path = fmt.Sprintf("api/%s/%s", ANX_API_VERSION, path)
|
||||
|
||||
if params != nil {
|
||||
@@ -300,23 +306,23 @@ func (a *ANX) SendAuthenticatedHTTPRequest(path string, params map[string]interf
|
||||
}
|
||||
}
|
||||
|
||||
PayloadJson, err := common.JSONEncode(request)
|
||||
PayloadJSON, err := common.JSONEncode(request)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("SendAuthenticatedHTTPRequest: Unable to JSON request")
|
||||
}
|
||||
|
||||
if a.Verbose {
|
||||
log.Printf("Request JSON: %s\n", PayloadJson)
|
||||
log.Printf("Request JSON: %s\n", PayloadJSON)
|
||||
}
|
||||
|
||||
hmac := common.GetHMAC(common.HashSHA512, []byte(path+string("\x00")+string(PayloadJson)), []byte(a.APISecret))
|
||||
hmac := common.GetHMAC(common.HashSHA512, []byte(path+string("\x00")+string(PayloadJSON)), []byte(a.APISecret))
|
||||
headers := make(map[string]string)
|
||||
headers["Rest-Key"] = a.APIKey
|
||||
headers["Rest-Sign"] = common.Base64Encode([]byte(hmac))
|
||||
headers["Content-Type"] = "application/json"
|
||||
|
||||
resp, err := common.SendHTTPRequest("POST", ANX_API_URL+path, headers, bytes.NewBuffer(PayloadJson))
|
||||
resp, err := common.SendHTTPRequest("POST", ANX_API_URL+path, headers, bytes.NewBuffer(PayloadJSON))
|
||||
|
||||
if a.Verbose {
|
||||
log.Printf("Received raw: \n%s\n", resp)
|
||||
|
||||
Reference in New Issue
Block a user