【发布时间】:2023-02-17 06:53:35
【问题描述】:
我根据 coinbase 文档 coinbase doc 尝试了以下代码 该文档是为 Python2 提供的,但我已经修改并将其用于 Python3,因为我正在尝试连接到 Coinbase 中的高级交易 API Coinbase Advanced trade doc
import datetime
import time
import hmac
import hashlib
import http.client
secret_key='***' #hidden
api_key='***' #hidden
date_time = datetime.datetime.utcnow()
timestamp=int(time.mktime(date_time.timetuple())) # timestamp should be from UTC time and no decimal allowed
method = "GET" # method can be GET or POST. Only capital is allowed
request_path = 'api/v3/brokerage/accounts'
body=''
message= str(timestamp) + method + request_path + body
signature = hmac.new(secret_key.encode('utf-8'), message.encode('utf-8'), hashlib.sha256).hexdigest()
headers={
'accept':'application/json',
'CB-ACCESS-KEY': api_key,
'CB-ACCESS-TIMESTAMP': timestamp,
'CB-ACCESS-SIGN': signature
}
conn = http.client.HTTPSConnection("api.coinbase.com")
payload = ''
conn.request("GET", "/api/v3/brokerage/accounts", payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode("utf-8"))
执行此代码时,我期待帐户详细信息。但我越来越未经授权的错误API 返回错误代码 401。
我之前能够连接到 Coinbase Pro API,一切都很好,直到 coinbase 和 Coinbase Pro 合并。现在无法弄清楚如何连接到 coinbase 中的高级交易功能。
【问题讨论】:
-
欢迎来到堆栈溢出!请编辑您的问题以在问题正文中包含错误输出。这比包含图像更可取,尤其是分辨率如此低且缺乏上下文的图像。
-
我删除了图像,突出显示了错误消息并添加了错误代码。
标签: python-3.x cryptocurrency coinbase-api