这类似于任何加密货币交换的标准,但是请求库中未涵盖此主题。 Poloniex的API文档:https://poloniex.com/support/api/#general_authentication
我正在尝试创建一个小的脚本,该脚本可以调用“ returnBalances”命令。我已经花了几个小时,但我能得到的最接近的响应是“无效的机密/签名”响应。
我认为问题是在签名中我需要使用包含参数的uri,但是我怎么知道带参数的url格式?这不应该被猜到吗?我对该请求会话的工作方式也不清楚。
key = '***'
sec = '***'
nonce = str(int(time.time() * 1000))
uri = 'https://poloniex.com/tradingApi'
payload = {'command': 'returnBalances', 'nonce': nonce}
s = Session()
req = Request('POST', uri, headers={'key': key, 'sign': signature})
signature = hmac.new(str.encode(self.sec, 'utf-8'), str.encode(uri, 'utf-8'), hashlib.sha512).hexdigest()
prepped = req.prepare()
prepped.body = requests.get(uri, params={'command': 'returnBalances', 'nonce': nonce})
prepped.headers = {'key': key, 'sign': signature}
resp = s.send(prepped, timeout=10)
print(resp.status_code)