async def create_minimalist_unconnected_octobot(): # import here to prevent later web interface import issues octobot_instance = octobot.OctoBot(test_config.load_test_config(dict_only=False)) octobot_instance.initialized = True tentacles_config = test_utils_config.load_test_tentacles_config() loaders.reload_tentacle_by_tentacle_class() octobot_instance.task_manager.async_loop = asyncio.get_event_loop() octobot_instance.task_manager.create_pool_executor() octobot_instance.tentacles_setup_config = tentacles_config octobot_instance.configuration_manager.add_element(octobot_constants.TENTACLES_SETUP_CONFIG_KEY, tentacles_config) octobot_instance.exchange_producer = trading_producers.ExchangeProducer(None, octobot_instance, None, False) octobot_instance.evaluator_producer = octobot_producers.EvaluatorProducer(None, octobot_instance) octobot_instance.evaluator_producer.matrix_id = await evaluator_api.initialize_evaluators(octobot_instance.config, tentacles_config) return octobot_instance
async def _init_bot(): # import here to prevent web interface import issues import octobot.octobot as octobot import octobot.constants as octobot_constants import octobot.producers as producers import octobot_commons.tests as test_config import octobot_tentacles_manager.loaders as loaders import octobot_evaluators.api as evaluators_api import tests.test_utils.config as config octobot = octobot.OctoBot(test_config.load_test_config(dict_only=False)) octobot.initialized = True tentacles_config = config.load_test_tentacles_config() loaders.reload_tentacle_by_tentacle_class() octobot.task_manager.async_loop = asyncio.get_event_loop() octobot.task_manager.create_pool_executor() octobot.tentacles_setup_config = tentacles_config octobot.configuration_manager.add_element(octobot_constants.TENTACLES_SETUP_CONFIG_KEY, tentacles_config) octobot.exchange_producer = producers.ExchangeProducer(None, octobot, None, False) octobot.evaluator_producer = producers.EvaluatorProducer(None, octobot) octobot.evaluator_producer.matrix_id = await evaluators_api.initialize_evaluators(octobot.config, tentacles_config) # Do not edit config file octobot.community_auth.edited_config = None return octobot
def start_octobot(args): logger = None try: if args.version: print(constants.LONG_VERSION) return logger = octobot_logger.init_logger() # Version logger.info("Version : {0}".format(constants.LONG_VERSION)) # Current running environment try: logger.debug( f"Running on {os_util.get_current_platform()} with {os_util.get_octobot_type()}" ) except Exception as e: logger.error( f"Impossible to identify the current running environment: {e}") # _check_public_announcements(logger) logger.info("Loading config files...") # configuration loading config_path = configuration.get_user_config() config = configuration.Configuration( config_path, common_constants.USER_PROFILES_FOLDER, constants.CONFIG_FILE_SCHEMA, constants.PROFILE_FILE_SCHEMA) if config.are_profiles_empty_or_missing(): logger.info("No profile found creating default profile...") configuration_manager.init_default_profile() if config.is_config_file_empty_or_missing(): logger.info( "No configuration found creating default configuration...") configuration_manager.init_config() config.read(should_raise=False) else: config.read(should_raise=False, fill_missing_fields=True) try: config.validate() except Exception as err: if configuration_manager.migrate_from_previous_config(config): logger.info( "Your configuration has been migrated into the newest format." ) else: logger.error( "OctoBot can't repair your config.json file: invalid format: " + str(err)) raise errors.ConfigError from err configuration_manager.config_health_check(config, args.backtesting) if not config.is_loaded(): raise errors.ConfigError # Handle utility methods before bot initializing if possible if args.encrypter: commands.exchange_keys_encrypter() return update_config_with_args(args, config, logger) if args.backtesting: bot = octobot_backtesting.OctoBotBacktestingFactory( config, run_on_common_part_only=not args.whole_data_range, enable_join_timeout=args.enable_backtesting_timeout) else: bot = octobot_class.OctoBot( config, reset_trading_history=args.reset_trading_history) octobot.set_bot(bot) if args.identifier: # set community identifier bot.community_auth.identifier = args.identifier[0] if args.update: return commands.update_bot(bot.octobot_api) _log_terms_if_unaccepted(config, logger) # Add tentacles folder to Python path sys.path.append(os.path.realpath(os.getcwd())) if not (os.path.isfile(tentacles_manager_constants. USER_REFERENCE_TENTACLE_CONFIG_FILE_PATH) and tentacles_manager_api.load_tentacles(verbose=True)): logger.info( "OctoBot tentacles can't be found or are damaged. Installing default tentacles ..." ) commands.run_tentacles_installation() # reload profiles config.load_profiles() # reload tentacles tentacles_manager_api.load_tentacles(verbose=True) # Clear community cache bot.community_auth.clear_cache() if args.strategy_optimizer: commands.start_strategy_optimizer(config, args.strategy_optimizer) return # In those cases load OctoBot _disable_interface_from_param("telegram", args.no_telegram, logger) _disable_interface_from_param("web", args.no_web, logger) commands.run_bot(bot, logger) except errors.ConfigError: logger.error("OctoBot can't start without a valid " + common_constants.CONFIG_FILE + " configuration file." + "\nYou can use " + constants.DEFAULT_CONFIG_FILE + " as an example to fix it.") os._exit(-1) except errors.NoProfileError: logger.error( "OctoBot can't start without a valid default profile configuration\nYou can use " + constants.DEFAULT_PROFILE_FILE + " as an example to fix it.") os._exit(-1) except ModuleNotFoundError as e: if 'tentacles' in str(e): logger.error( "Impossible to start OctoBot, tentacles are missing.\nTo install tentacles, " "please use the following command:\nstart.py tentacles --install --all" ) else: logger.exception(e) os._exit(-1) except errors.ConfigEvaluatorError: logger.error( "OctoBot can't start without a valid configuration file.\n" "This file is generated on tentacle " "installation using the following command:\nstart.py tentacles --install --all" ) os._exit(-1) except errors.ConfigTradingError: logger.error( "OctoBot can't start without a valid configuration file.\n" "This file is generated on tentacle " "installation using the following command:\nstart.py tentacles --install --all" ) os._exit(-1)
def start_octobot(args): logger = None try: if args.version: print(constants.LONG_VERSION) return logger = octobot_logger.init_logger() # Version logger.info("Version : {0}".format(constants.LONG_VERSION)) # Current running environment _log_environment(logger) # _check_public_announcements(logger) # load configuration config = _create_startup_config(logger) # check config loading if not config.is_loaded(): raise errors.ConfigError # Handle utility methods before bot initializing if possible if args.encrypter: commands.exchange_keys_encrypter() return # add args to config update_config_with_args(args, config, logger) # show terms _log_terms_if_unaccepted(config, logger) # tries to load, install or repair tentacles _load_or_create_tentacles(config, logger) # Can now perform config health check (some checks require a loaded profile) configuration_manager.config_health_check(config, args.backtesting) # Keep track of errors if any octobot_community.register_error_uploader( constants.ERRORS_POST_ENDPOINT, config) # create OctoBot instance if args.backtesting: bot = octobot_backtesting.OctoBotBacktestingFactory( config, run_on_common_part_only=not args.whole_data_range, enable_join_timeout=args.enable_backtesting_timeout) else: bot = octobot_class.OctoBot( config, reset_trading_history=args.reset_trading_history) # set global bot instance octobot.set_bot(bot) # Clear community cache bot.community_auth.clear_cache() if args.identifier: # set community identifier bot.community_auth.identifier = args.identifier[0] if args.update: return commands.update_bot(bot.octobot_api) if args.strategy_optimizer: commands.start_strategy_optimizer(config, args.strategy_optimizer) return # In those cases load OctoBot _disable_interface_from_param("telegram", args.no_telegram, logger) _disable_interface_from_param("web", args.no_web, logger) commands.run_bot(bot, logger) except errors.ConfigError: logger.error("OctoBot can't start without a valid " + common_constants.CONFIG_FILE + " configuration file." + "\nYou can use " + constants.DEFAULT_CONFIG_FILE + " as an example to fix it.") os._exit(-1) except errors.NoProfileError: logger.error( "OctoBot can't start without a valid default profile configuration." ) os._exit(-1) except ModuleNotFoundError as e: if 'tentacles' in str(e): logger.error( "Impossible to start OctoBot, tentacles are missing.\nTo install tentacles, " "please use the following command:\nstart.py tentacles --install --all" ) else: logger.exception(e) os._exit(-1) except errors.ConfigEvaluatorError: logger.error( "OctoBot can't start without a valid configuration file.\n" "This file is generated on tentacle " "installation using the following command:\nstart.py tentacles --install --all" ) os._exit(-1) except errors.ConfigTradingError: logger.error( "OctoBot can't start without a valid configuration file.\n" "This file is generated on tentacle " "installation using the following command:\nstart.py tentacles --install --all" ) os._exit(-1)