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

@@ -374,7 +374,12 @@ func (g *GDAX) SendAuthenticatedHTTPRequest(method, path string, params map[stri
return fmt.Errorf(exchange.WarningAuthenticatedRequestWithoutCredentialsSet, g.Name)
}
timestamp := strconv.FormatInt(time.Now().Unix(), 10)
if g.Nonce.Get() == 0 {
g.Nonce.Set(time.Now().Unix())
} else {
g.Nonce.Inc()
}
payload := []byte("")
if params != nil {
@@ -389,11 +394,11 @@ func (g *GDAX) SendAuthenticatedHTTPRequest(method, path string, params map[stri
}
}
message := timestamp + method + "/" + path + string(payload)
message := g.Nonce.String() + method + "/" + path + string(payload)
hmac := common.GetHMAC(common.HashSHA256, []byte(message), []byte(g.APISecret))
headers := make(map[string]string)
headers["CB-ACCESS-SIGN"] = common.Base64Encode([]byte(hmac))
headers["CB-ACCESS-TIMESTAMP"] = timestamp
headers["CB-ACCESS-TIMESTAMP"] = g.Nonce.String()
headers["CB-ACCESS-KEY"] = g.APIKey
headers["CB-ACCESS-PASSPHRASE"] = g.ClientID
headers["Content-Type"] = "application/json"