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.

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

报告相同问题?

悬赏问题

  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换