def update_user( self, user_data={}, email=None, username=None, ): ''' Update user information :param user_data: optional :type user_data: dict :param email: optional :type email: str :param username: optional :type username: str :returns: User :raises: DydxAPIError ''' return self._put( 'users', { 'email': email, 'username': username, 'userData': json_stringify(user_data), }, )
def _request( self, method, endpoint, opt_ethereum_address, data={} ): ethereum_address = opt_ethereum_address or self.default_address request_path = '/'.join(['/v3', endpoint]) timestamp = generate_now_iso() signature = self.signer.sign( ethereum_address, method=method.upper(), request_path=request_path, body=json_stringify(data) if data else '{}', timestamp=timestamp, ) return request( self.host + request_path, method, { 'DYDX-SIGNATURE': signature, 'DYDX-TIMESTAMP': timestamp, 'DYDX-ETHEREUM-ADDRESS': ethereum_address, }, data, )
def sign( self, request_path, method, iso_timestamp, data, ): return SignableApiRequest( iso_timestamp=iso_timestamp, method=method, request_path=request_path, body=json_stringify(data) if data else '', ).sign(self.api_private_key)
def sign( self, request_path, method, iso_timestamp, data, ): message_string = (iso_timestamp + method + request_path + (json_stringify(data) if data else '')) hashed = hmac.new( base64.urlsafe_b64decode( (self.api_key_credentials['secret']).encode('utf-8'), ), msg=message_string.encode('utf-8'), digestmod=hashlib.sha256, ) return base64.urlsafe_b64encode(hashed.digest()).decode()
def generate_api_key_action( request_path, method, data={}, ): return (method + request_path + (json_stringify(data) if data else ''))