def _get_universe(self): universe = Environment.get_instance().universe if len(universe) == 0 and ACCOUNT_TYPE.STOCK not in self._account_list: error = CustomError() error.set_msg("Current universe is empty. Please use subscribe function before trade") raise patch_user_exc(CustomException(error)) return universe
def _get_universe(self): universe = self._env.get_universe() if len(universe) == 0 and ACCOUNT_TYPE.STOCK not in self._account_list: error = CustomError() error.set_msg("Current universe is empty. Please use subscribe function before trade") raise patch_user_exc(CustomException(error)) return universe
def _get_universe(self): universe = self._env.get_universe() if len(universe) == 0 and DEFAULT_ACCOUNT_TYPE.STOCK.name not in self._config.base.accounts: error = CustomError() error.set_msg("Current universe is empty. Please use subscribe function before trade") raise patch_user_exc(CustomException(error), force=True) return universe
def _get_universe(self): universe = self._env.get_universe() if len(universe) == 0 and DEFAULT_ACCOUNT_TYPE.STOCK.name not in self._config.base.accounts: error = CustomError() error.set_msg( "Current universe is empty. Please use subscribe function before trade") raise patch_user_exc(CustomException(error), force=True) return universe
def create_custom_exception(exc_type, exc_val, exc_tb, strategy_filename): try: msg = str(exc_val) except: msg = "" error = CustomError() error.set_msg(msg) error.set_exc(exc_type, exc_val, exc_tb) import linecache filename = '' tb = exc_tb while tb: co = tb.tb_frame.f_code filename = co.co_filename if filename != strategy_filename: tb = tb.tb_next continue lineno = tb.tb_lineno func_name = co.co_name code = linecache.getline(filename, lineno).strip() error.add_stack_info(filename, lineno, func_name, code, tb.tb_frame.f_locals) tb = tb.tb_next if filename == strategy_filename: error.error_type = EXC_TYPE.USER_EXC user_exc = CustomException(error) return user_exc
def create_custom_exception(exc_type, exc_val, exc_tb, strategy_filename): try: msg = str(exc_val) except: msg = "" error = CustomError() error.set_msg(msg) error.set_exc(exc_type, exc_val, exc_tb) import linecache filename = '' tb = exc_tb while tb: co = tb.tb_frame.f_code filename = co.co_filename if filename != strategy_filename: tb = tb.tb_next continue lineno = tb.tb_lineno func_name = co.co_name code = linecache.getline(filename, lineno).strip() error.add_stack_info(filename, lineno, func_name, code, tb.tb_frame.f_locals) tb = tb.tb_next if filename == strategy_filename: error.error_type = EXC_TYPE.USER_EXC user_exc = CustomException(error) return user_exc
def compile_strategy(source_code, strategy, scope): try: code = compile(source_code, strategy, 'exec') six.exec_(code, scope) return scope except Exception as e: exc_type, exc_val, exc_tb = sys.exc_info() exc_val = patch_user_exc(exc_val, force=True) try: msg = str(exc_val) except Exception as e1: msg = "" six.print_(e1) error = CustomError() error.set_msg(msg) error.set_exc(exc_type, exc_val, exc_tb) stackinfos = list(traceback.extract_tb(exc_tb)) if isinstance(e, (SyntaxError, IndentationError)): error.add_stack_info(exc_val.filename, exc_val.lineno, "", exc_val.text) else: for item in stackinfos: filename, lineno, func_name, code = item if strategy == filename: error.add_stack_info(*item) # avoid empty stack if error.stacks_length == 0: error.add_stack_info(*item) raise CustomException(error)
def compile_strategy(source_code, strategy, scope): try: code = compile(source_code, strategy, 'exec') six.exec_(code, scope) return scope except Exception as e: exc_type, exc_val, exc_tb = sys.exc_info() exc_val = patch_user_exc(exc_val, force=True) try: msg = str(exc_val) except Exception as e1: msg = "" six.print_(e1) error = CustomError() error.set_msg(msg) error.set_exc(exc_type, exc_val, exc_tb) stackinfos = list(traceback.extract_tb(exc_tb)) if isinstance(e, (SyntaxError, IndentationError)): error.add_stack_info(exc_val.filename, exc_val.lineno, "", exc_val.text) else: for item in stackinfos: filename, lineno, func_name, code = item if strategy == filename: error.add_stack_info(*item) # avoid empty stack if error.stacks_length == 0: error.add_stack_info(*item) raise CustomException(error)