def sign(self, request: Request) -> Request: """ Generate BINANCE signature. """ security = request.data["security"] if security == Security.NONE: request.data = None return request if request.params: path = request.path + "?" + urllib.parse.urlencode(request.params) else: request.params = dict() path = request.path if security == Security.SIGNED: timestamp = int(time.time() * 1000) if self.time_offset > 0: timestamp -= abs(self.time_offset) elif self.time_offset < 0: timestamp += abs(self.time_offset) request.params["timestamp"] = timestamp query = urllib.parse.urlencode(sorted(request.params.items())) signature = hmac.new(self.secret, query.encode("utf-8"), hashlib.sha256).hexdigest() query += "&signature={}".format(signature) path = request.path + "?" + query request.path = path request.params = {} request.data = {} # Add headers headers = { "Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json", "X-MBX-APIKEY": self.key, "Connection": "close" } if security in [Security.SIGNED, Security.API_KEY]: request.headers = headers return request
def sign(self, request: Request): request.headers = {"Content-Type": "application/json"} if request.method == "POST": if request.data: request.json_data = request.data request.data = json.dumps(request.data) return request
def sign(self, request: Request) -> Request: """ Generate OKEXo signature. """ # Sign timestamp = get_timestamp() request.data = json.dumps(request.data) if request.params: path = request.path + "?" + urlencode(request.params) else: path = request.path msg = timestamp + request.method + path + request.data signature = generate_signature(msg, self.secret) # Add headers request.headers = { "OK-ACCESS-KEY": self.key, "OK-ACCESS-SIGN": signature, "OK-ACCESS-TIMESTAMP": timestamp, "OK-ACCESS-PASSPHRASE": self.passphrase, "Content-Type": "application/json" } return request
def sign(self, request: Request) -> Request: """生成欧易V5签名""" # 签名 timestamp: str = generate_timestamp() request.data = json.dumps(request.data) if request.params: path: str = request.path + "?" + urlencode(request.params) else: path: str = request.path msg: str = timestamp + request.method + path + request.data signature: bytes = generate_signature(msg, self.secret) # 添加请求头 request.headers = { "OK-ACCESS-KEY": self.key, "OK-ACCESS-SIGN": signature, "OK-ACCESS-TIMESTAMP": timestamp, "OK-ACCESS-PASSPHRASE": self.passphrase, "Content-Type": "application/json" } if self.simulated: request.headers["x-simulated-trading"] = "1" return request
def sign(self, request: Request): """ Sign Bitstamp request. """ if request.method == "GET": return request timestamp = str(int(round(time.time() * 1000))) nonce = str(uuid.uuid4()) content_type = "application/x-www-form-urlencoded" # Empty post data leads to API0020 error, # so use this offset dict instead. if not request.data: request.data = {"offset": "1"} payload_str = urlencode(request.data) message = "BITSTAMP " + self.key + \ request.method + \ "www.bitstamp.net/api/v2" + \ request.path + \ "" + \ content_type + \ nonce + \ timestamp + \ "v2" + \ payload_str message = message.encode("utf-8") signature = hmac.new( self.secret, msg=message, digestmod=hashlib.sha256 ).hexdigest().upper() request.headers = { "X-Auth": "BITSTAMP " + self.key, "X-Auth-Signature": signature, "X-Auth-Nonce": nonce, "X-Auth-Timestamp": timestamp, "X-Auth-Version": "v2", "Content-Type": content_type } request.data = payload_str return request
def sign(self, request: Request) -> Request: """ Generate HUOBI signature. """ request.headers = { "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36" } params_with_signature = create_signature(self.key, request.method, self.host, request.path, self.secret, request.params) request.params = params_with_signature if request.method == "POST": request.headers["Content-Type"] = "application/json" if request.data: request.data = json.dumps(request.data) return request
def sign(self, request: Request) -> Request: """ Generate SUGAR signature. """ signature = self.create_signature(request.data) request_time = datetime.strftime(datetime.now(),"%Y-%m-%d %H:%M:%S.%f") request_data = { "requestHeader":{ "token": self.token, "sign": signature, "yqMemberId": self.open_account, "merRequestNo": request_time, "merRequestTime": request_time[:-7] }, "requestBody": request.data } request.headers = {"Content-Type": "application/json"} request.data = json.dumps(request_data) return request