【问题标题】:Coinbase Websocket, signature in authenticationCoinbase Websocket,身份验证中的签名
【发布时间】:2018-11-14 19:05:52
【问题描述】:

应该如何生成签名参数以打开与 Coinbase Websocket 的经过身份验证的连接?我在任何地方都找不到简明扼要的描述。

对于 GET/PUT API 调用,我使用以下代码成功生成了它,但是对于 Websocket,既没有“方法”也没有“path_url”,那么“消息”应该包含什么?

    timestamp = str(time.time())
    message = timestamp + request.method + request.path_url + (request.body or '')
    hmac_key = base64.b64decode(self.secret_key)
    signature = hmac.new(hmac_key, message.encode('utf-8'), hashlib.sha256)
    signature_b64 = base64.b64encode(signature.digest())

【问题讨论】:

  • 这里有同样的问题。您找到解决此问题的方法了吗?
  • 不,我没有找到解决方案,很遗憾我的问题没有答案。
  • 找到了解决方案。请参阅我发布的答案。

标签: coinbase-api


【解决方案1】:

我终于能够解决这个问题。当然,代码看起来并不那么有趣。

我将以下内容与CCXT 库结合使用。更具体地说,Websockets fork 实现here

const id = this.marketId (symbol)
const timestamp = Date.now() / 1000

const p_passphrase = this.safeValue(params, 'password')
const p_apiKey = this.safeValue(params, 'apiKey')
const p_secret = this.safeValue(params, 'secret')

const what = timestamp + 'GET' + '/users/self/verify'
const key = Buffer.from(p_secret, 'base64')
const hmac = require('crypto').createHmac('sha256', key)
const signature = hmac.update(what).digest('base64')

this.websocketSendJson({
  'type': 'subscribe',
  'product_ids': [id],
  'channels': ['user'],

  'key': p_apiKey,
  'signature': signature,
  'timestamp': timestamp,
  'passphrase': p_passphrase,
})

希望对您有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-04
    • 1970-01-01
    • 2022-06-28
    • 2020-10-31
    • 1970-01-01
    • 2021-08-22
    • 2021-10-04
    • 1970-01-01
    相关资源
    最近更新 更多