我对Python编码和编码一般都很陌生,我正在尝试为Binance API创建一个经过身份验证的购买功能。
从我收集到的内容通常是在Linux上使用curl方法完成的,我尝试在Python库中使用requests
,并且我不断从API获取错误400代码,所以显然我在这里做错了。
我会使用python-binance包装器来获取灵感,但不幸的是我几乎无法掌握该代码的功能。
有人能解释我在这里做错了吗?
以下是binance API文档的链接:
https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md
def makeBuy(side, symbol, quantity, price):
timestamp = int(round(time.time() * 1000))
queryS = "symbol=" + symbol + "&side=" + side + "&type=LIMIT&timeInForce=GTC&quantity=" + \
str(quantity) + "&price=" + str(price) + "×tamp=" + str(timestamp)
m = hmac.new(api_secret.encode('utf-8'), queryS.encode('utf-8'), hashlib.sha256)
url = 'https://api.binance.com/api/v3/order?' + queryS + '&signature=' + str(m.hexdigest())
response2 = requests.get(url, headers={'X-MBX-APIKEY': api_key})
print(response2)
答案 0 :(得分:0)
我建议你通过网络浏览器访问api,并使用浏览器的网络高级选项(最好是chrome)来查看get请求的确切cookie和结构,并尝试使用python实现相同的功能。 我上周遇到了类似的问题,这就是我如何解决它的问题。