doubi8383 2017-07-02 15:47
浏览 105
已采纳

Golang Gorilla CEX.IO Websocket身份验证错误

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
}
  • 写回答

1条回答 默认 最新

  • duanjuan1103 2017-07-02 16:16
    关注

    The error message is telling you that the timestamp is more than 20 seconds away from the current time.

    The API expects time in seconds, not nanoseconds. Use Unix to get the time in seconds.

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

    Unix time is is seconds since Jan 01 1970 UTC.

    If this fails, then check that your system time is set correctly down to the second.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效