【发布时间】:2021-09-07 10:53:51
【问题描述】:
在这里待了一周:每一天,每一天。没有任何工作。 最低限度的身份验证有多难?我敢打赌,很多人也在寻找这个答案。
这是我们目前所获得的草稿:
import cbpro, hmac, hashlib, time,
api_key = "[YOUR_API_KEY]"
secret_key = "[YOUR_B64SECRET]"
passphrase = "[YOUR_PASSPHRASE]"
message = message.encode('ascii')
hmac_key = base64.b64decode(secret_key)
signature = hmac.new(hmac_key, message, hashlib.sha256)
signature_b64 = base64.b64encode(signature.digest()).decode('utf-8')
auth_client = cbpro.AuthenticatedClient(api_key, signature_b64, passphrase)
auth_client.get_accounts()
或者在使用 websockets 订阅时,使用以下内容:
{
"type": "subscribe",
"product_ids": [
"BTC-USD"
],
"channels": ["full"],
"signature": "...",
"key": "...",
"passphrase": "...",
"timestamp": "..."
}
使用:
socket = "wss://ws-feed.pro.coinbase.com"
ws = websocket.WebSocketApp(socket, on_open=on_open, on_message=on_message)
ws.run_forever()
我不明白为什么简单的几行代码来验证和查看未结订单/帐户如此困难,而订阅 websocket 代码和接收价格变化却如此简单。对密钥进行编码应该不会太难吧?请帮助我们提供一个超级简短的示例(没有所有“init”和导入以及传递的不同函数)。嘘
【问题讨论】:
标签: python-3.x authentication websocket hmac coinbase-api