【问题标题】:Golang Gorilla CEX.IO Websocket authentication errorGolang Gorilla CEX.IO Websocket 认证错误
【发布时间】: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
}

【问题讨论】:

    标签: go websocket gorilla


    【解决方案1】:

    错误信息告诉你时间戳距离当前时间超过 20 秒。

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

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

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

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

    【讨论】:

    • Unix 时间是自 1970 年 1 月 1 日 (UTC) 以来的秒数。我要求您检查系统上的时钟是否设置在正确时间的 20 秒以内。
    • 错误信息告诉你时间戳距离当前时间超过20秒。您的系统时间必须正确设置为秒。
    • 你是对的!我更新我的系统时间,没关系。感谢您的帮助。
    猜你喜欢
    • 2017-08-30
    • 1970-01-01
    • 2019-08-11
    • 2018-08-28
    • 1970-01-01
    • 2017-08-17
    • 2020-04-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多