I'm currently trying to connect to the CEX.IO bitcoin exchange's websocket.
Websocket connection is OK but at the time of authentication, I have the error: Timestamp is not in 20sec range
. I don't know what this error.
Test case 1 & 2 for createSignature is OK (https://cex.io/websocket-api#authentication).
Authentication Go code :
func toHmac256(message string, secret string) string {
key := []byte(secret)
h := hmac.New(sha256.New, key)
h.Write([]byte(message))
return strings.ToUpper(hex.EncodeToString(h.Sum(nil)))
}
func Signature() (string, string) {
nonce := time.Now().Unix() // Edit with Cerise Limón answer
message := strconv.FormatInt(nonce, 10) + "API-KEY"
signature := api.toHmac256(message, "SECRET-KEY")
return signature, nonce
}