主要是报 You are not authorized to execute this request
或者{“code”:-1022,“msg”:“Signature for this request is not valid.”},反正就是signature整的不对,直接上代码
import hashlib
import hmac
import time
import requests
url = "https://api.binance.com/sapi/v1/capital/config/getall"
timestamp = int(round(time.time() * 1000))
api_key = "FOnOIyCgBKae0msn7EglXBFGeCieKHJWujxFPbo3Hv9g2ssTHWHPBBb4HUASBpwr"
secret_key = "d2W8tS53sX7O89ra1RX3BsHHvgHpFclabVAuy3CKZoMNfan7AiCreVWYK3eajBUG"
query_string = 'timestamp=%s' % str(timestamp)
secret = secret_key
def hashing(query_string):
return hmac.new(secret.encode('utf-8'), query_string.encode('utf-8'), hashlib.sha256).hexdigest()
# 用secret_key和秒级时间戳进行hmac sha256加密
signature = hashing(query_string)
print(signature)
params = {"timestamp":timestamp,"signature":signature}
headers = {"X-MBX-APIKEY":api_key}
res = requests.get(url,headers=headers,params=params)
print(res.status_code)
print(res.text)
这是请求账户数据的接口,返回一大堆东西。