Код: Выделить всё
def create_listen_key(api_key, api_secret):
url = "https://api.mexc.com/api/v3/userDataStream"
timestamp = str(int(time.time() * 1000))
params = {"please_sign_it": None}
signature = generate_signature(api_key=api_key, api_secret=api_secret, ign_params=params,
req_time=timestamp)
paramsWithSignature = {
"please_sign_it": None,
"timestamp": timestamp,
"signature": signature
}
headers = {
"X-MEXC-APIKEY": api_key,
"Content-Type": "application/json",
}
response = requests.post(url, headers=headers, data=paramsWithSignature)
if response.status_code == 200:
return json.loads(response.content)
else:
raise Exception(f"Failed to create listen key: {response.text}")
Код: Выделить всё
def generate_signature(api_key, api_secret, req_time, sign_params=None):
ic("def generate_signature")
if sign_params:
sign_params = urlencode(sign_params, quote_via=quote)
ic(sign_params)
to_sign = f"{api_key}{req_time}{sign_params}"
else:
to_sign = f"{api_key}{req_time}"
sign = hmac.new(api_secret.encode('utf-8'), to_sign.encode('utf-8'), hashlib.sha256).hexdigest()
return sign
Код: Выделить всё
Exception: Failed to create listen key: {"code":700002,"msg":"Signature for this request is not valid."}
Подробнее здесь: https://stackoverflow.com/questions/792 ... ket-access
Мобильная версия