【发布时间】:2017-09-15 04:38:17
【问题描述】:
我正在尝试使用https://c-cex.com/ 的 api 为我的投资组合构建比特币交易应用程序,但在使用需要身份验证的私有函数时遇到了问题。它提供了一个如何连接的 php 示例,我尽我所能在 python 中重新创建它,但它返回我的密钥无效(尽管我直接从我的电子邮件中复制了 apikey
apikey='141FA9467F8EAC7917A9D6279AD96B4F';
apisecret='6A946F6A331F8CCDFA19EB2D73FD9B1D';
dt = datetime.datetime.now()
nonce= (dt - datetime.datetime(1970,1,1)).total_seconds()
uri='https://c-cex.com/t/api.html?a=getbalance¤cy=BTC&apikey=' + apikey + '&nonce=' + str(nonce);
sign = hmac.new(bytes(apisecret,encoding='utf-8'), uri.encode(encoding='utf-8'), hashlib.sha512).hexdigest()
headers = {'apisign': sign}
response = requests.get(uri,headers)
print(response.json())
返回的输出是
{'result': None, 'success': False, 'message': 'APIKEY_INVALID'}
我能做的最好的假设是我没有正确使用 hmac 函数我已经用 2 个单独的 API 密钥测试了它(我的实际 API 密钥和这个测试代码中的一个只能访问 GET 函数)
【问题讨论】: