尝试向crypto.com进行身份验证,但似乎无法使其正常工作...已经尝试了几天了,真的很沮丧,有什么帮助吗?他们的api文档@ https://exchange-docs.crypto.com/?python#digital-signature
下面是怎么做的+示例代码,我卡住了..
身份验证基于API密钥的配对,以及使用API Secret作为密钥的请求参数的HMAC-SHA256散列。
生成HMAC-SHA256签名的算法如下:
如果请求中存在params,请对请求参数key进行升序排序。
将所有有序的参数键组合为key + value (没有空格,没有分隔符)。让我们将其称为参数字符串
接下来,执行以下操作: method + id + api_key +参数字符串+ nonce
使用HMAC-SHA256,使用API Secret作为密钥对上述内容进行哈希处理
将输出编码为十六进制字符串--这是您的数字签名
import hmac
import hashlib
import json
import requests
import time
API_KEY = "API_KEY"
SECRET_KEY = "SECRET_KEY"
req = {
"id": 11,
"method": "private/get-order-detail",
"api_key": API_KEY,
"params": {
"order_id": "337843775021233500",
},
"nonce": int(time.time() * 1000)
};
# First ensure the params are alphabetically sorted by key
paramString = ""
if "params" in req:
for key in req['params']:
paramString += key
paramString += str(req['params'][key])
sigPayload = req['method'] + str(req['id']) + req['api_key'] + paramString + str(req['nonce'])
request['sig'] = hmac.new(
bytes(str(SECRET_KEY), 'utf-8'),
msg=bytes(sigPayload, 'utf-8'),
digestmod=hashlib.sha256
).hexdigest()发布于 2020-12-07 03:55:16
我今天遇到了同样的问题。总的来说,我发现来自crypto.com的API文档非常糟糕。
更改代码的最后一部分,以便在"req“字典中添加一个字段:
req['sig'] = hmac.new(
bytes(str(SECRET_KEY), 'utf-8'),
msg=bytes(sigPayload, 'utf-8'),
digestmod=hashlib.sha256
).hexdigest()要获取订单详细信息(如示例所示),可以使用POST请求进行API调用,如下所示:
api_url = f"https://api.crypto.com/v2/{req["method"]}"
response = requests.post(api_url, json=req)
order_detail = response.json()https://stackoverflow.com/questions/62876646
复制相似问题