我正在尝试使用 requests 模块与 python 交易币安期货。
我有以下代码:
import requests
import time
API_KEY ="your key"
SECRET_KEY="your secret key"
base_url = "https://fapi.binance.com"
api_path = "/fapi/v1/order"
headers={
'X-MBX-APIKEY': API_KEY
}
my_time=int(time.time() * 1000)
my_timestamp="timestamp="+str(my_time)
url_open=base_url+api_path+"?symbol=MATICUSDT&side=BUY&type=MARKET&quantity=40&"+my_timestamp+"&signature="+SECRET_KEY
response = requests.get(url_open,headers=headers)
此代码返回以下错误:{"code":-1022,"msg":"Signature for this request is not valid."}
我也试过散列签名:
import hmac
import hashlib
query_string="symbol=MATICUSDT&side=BUY&type=MARKET&quantity=40&"+my_timestamp
HashSig=hmac.new(SECRET_KEY.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest()
url_open=base_url+api_path+"?symbol=MATICUSDT&side=BUY&type=MARKET&quantity=40&"+my_timestamp+"&signature="+HashSig
response = requests.get(url_open,headers=headers)
这也返回错误: {"code":-1022,"msg":"Signature for this request is not valid."}
我已经尝试了以下代码:
query_string=my_timestamp
HashSig=hmac.new(SECRET_KEY.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest()
url_open=base_url+api_path+"?symbol=MATICUSDT&side=BUY&type=MARKET&quantity=40&"+my_timestamp+"&signature="+HashSig
response = requests.get(url_open,headers=headers)
这给出了同样的错误: {"code":-1022,"msg":"Signature for this request is not valid."}
我不知道如何制作签名,有人可以帮助我我在谷歌上搜索了很多,但我一直无法找到解决方案。我的目标是用 python 交易币安期货