code: def require_initialized(exception):
      
      def decorator(method):
          @wraps(method)
          def wrapped_method(self, *args, **kwargs):
              if not self.initialized:
                  raise exception
              return method(self, *args, **kwargs)
          return wrapped_method
      return decorator
docs: Decorator for API methods that should only be called after
      TradingAlgorithm.initialize.  `exception` will be raised if the method is
      called before initialize has completed.
  
      Examples
      --------
      @require_initialized(SomeException("Don't do that!"))
      def method(self):
          # Do stuff that should only be allowed after initialize.