1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| async def sign(self, request: RhinoRequest) -> NoReturn: try: cex_key = request.extra.get("key") cex_secret = request.extra.get("secret") encode_str = "" if request.method == "GET" or request.method == "DELETE": if len(request.params) > 0: for key, value in request.params.items(): encode_str += str(key) + "=" + str(value) + "&" elif request.method == "POST": aa = urllib.parse.urlencode(request.data) if len(request.data) > 0: encode_str = urllib.parse.urlencode(request.data) + "&" encode_str = bytes(encode_str[:-1], encoding="utf8") signature = hmac.new(cex_secret.encode( if request.method == "GET" or request.method == "DELETE": request.params["signature"] = signature elif request.method == "POST": request.data["signature"] = signature headers = { "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json", "X-MBX-APIKEY": cex_key } request.headers = headers return request except Exception as e: self.gateway.logger.error(f"{self.gateway.exchange_sub} sign is error") self.gateway.logger.error(traceback.format_exc())
|