2017-07-02 54 views
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 
} 

回答

1

错误信息是告诉你,时间戳是从当前时间超过20秒的路程。

API需要的时间以秒为单位,而不是纳秒。使用Unix以秒为单位获得时间。

 nonce := time.Now().Unix() 

Unix时间是自1970年1月1日UTC以来的秒数。

如果失败,请检查您的系统时间设置是否正确。

+0

'time.Now().Unix()' – LeMoussel

+0

同样的错误检查你的系统时间是否正确。 –

+0

Unix时间是自1970年1月1日(UTC)以来的秒数。我要求您检查系统中的时钟是否设置在正确时间的20秒内。 –