0
我目前正试图连接到CEX.IO比特币交易所的websocket。 Websocket连接正常,但在进行身份验证时,出现错误:Timestamp is not in 20sec range
。我不知道这个错误是什么。Golang Gorilla CEX.IO Websocket验证错误
测试用例1 & 2 for createSignature OK(https://cex.io/websocket-api#authentication)。
验证Go代码:
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
}
'time.Now().Unix()' – LeMoussel
同样的错误检查你的系统时间是否正确。 –
Unix时间是自1970年1月1日(UTC)以来的秒数。我要求您检查系统中的时钟是否设置在正确时间的20秒内。 –