【发布时间】:2017-07-02 15:47:55
【问题描述】:
我目前正在尝试连接到 CEX.IO 比特币交易所的 websocket。
Websocket 连接正常,但在身份验证时出现错误:Timestamp is not in 20sec range。我不知道这是什么错误。
createSignature 的测试用例 1 和 2 正常 (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
}
【问题讨论】: