Add nonce package for exchanges

This commit is contained in:
Adrian Gallagher
2017-08-21 15:57:41 +10:00
parent 0fea98857c
commit f3c1f4880d
20 changed files with 256 additions and 61 deletions

View File

@@ -276,8 +276,13 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, l.Name)
}
nonce := strconv.FormatInt(time.Now().UnixNano(), 10)
req := fmt.Sprintf("tonce=%s&accesskey=%s&requestmethod=post&id=1&method=%s&params=%s", nonce, l.APIKey, method, params)
if l.Nonce.Get() == 0 {
l.Nonce.Set(time.Now().UnixNano())
} else {
l.Nonce.Inc()
}
req := fmt.Sprintf("tonce=%s&accesskey=%s&requestmethod=post&id=1&method=%s&params=%s", l.Nonce.String(), l.APIKey, method, params)
hmac := common.GetHMAC(common.HashSHA1, []byte(req), []byte(l.APISecret))
if l.Verbose {
@@ -295,7 +300,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string, result int
}
headers := make(map[string]string)
headers["Json-Rpc-Tonce"] = nonce
headers["Json-Rpc-Tonce"] = l.Nonce.String()
headers["Authorization"] = "Basic " + common.Base64Encode([]byte(l.APIKey+":"+common.HexEncodeToString(hmac)))
headers["Content-Type"] = "application/json-rpc"