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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失