async def test_run_bot(event_loop): # launch a bot config = load_test_config() config[CONFIG_CRYPTO_CURRENCIES] = {"Bitcoin": {"pairs": ["BTC/USDT"]}} bot = OctoBot(config) bot.time_frames = [TimeFrames.ONE_MINUTE] await bot.create_exchange_traders(ignore_config=True) bot.create_evaluation_tasks() await asyncio.sleep(5) await asyncio.get_event_loop().run_in_executor(None, bot.stop_threads)
def test_run_bot(): # launch a bot config = load_test_config() bot = OctoBot(config) bot.time_frames = [TimeFrames.ONE_MINUTE] bot.create_exchange_traders() bot.create_evaluation_threads() bot.start_threads() # let it start time.sleep(5) # stop the bot bot.stop_threads()
def test_run_bot(): # launch a bot config = load_test_config() bot = OctoBot(config) bot.time_frames = [TimeFrames.ONE_MINUTE] bot.create_exchange_traders() bot.create_evaluation_threads() bot.start_threads() # let it run 2 minutes: test will fail if an exception is raised # 1.9 to stop threads before the next time frame time.sleep(1.9 * 60) # stop the bot bot.stop_threads()
def test_create_bot(): # launch a bot config = load_test_config() bot = OctoBot(config) bot.stop_threads()
def start_octobot(starting_args): fileConfig(LOGGING_CONFIG_FILE) logger = logging.getLogger("OctoBot Launcher") # Force new log file creation not to log at the previous one's end. logger.parent.handlers[1].doRollover() sys.excepthook = _log_uncaught_exceptions try: if starting_args.version: print(LONG_VERSION) else: # Version logger.info("Version : {0}".format(LONG_VERSION)) logger.info("Loading config files...") config = load_config(error=False) if config is None: raise ConfigError # Handle utility methods before bot initializing if possible if starting_args.packager: Commands.package_manager(config, starting_args.packager) elif starting_args.creator: Commands.tentacle_creator(config, starting_args.creator) elif starting_args.encrypter: Commands.exchange_keys_encrypter() else: config[CONFIG_EVALUATOR] = load_config( CONFIG_EVALUATOR_FILE_PATH, False) if config[CONFIG_EVALUATOR] is None: raise ConfigEvaluatorError config[CONFIG_TRADING_TENTACLES] = load_config( CONFIG_TRADING_FILE_PATH, False) if config[CONFIG_TRADING_TENTACLES] is None: raise ConfigTradingError if starting_args.data_collector: Commands.data_collector(config) elif starting_args.strategy_optimizer: Commands.start_strategy_optimizer( config, starting_args.strategy_optimizer) else: # In those cases load OctoBot from octobot import OctoBot from interfaces.telegram.bot import TelegramApp from services import WebService TelegramApp.enable(config, starting_args.telegram) WebService.enable(config, not starting_args.no_web) update_config_with_args(starting_args, config) bot = OctoBot(config) import interfaces interfaces.__init__(bot, config) try: main.__init__(config) except NameError as e: logging.error( "{0}, impossible to display GUI".format(e)) if starting_args.start: Commands.start_bot(bot, logger) except ConfigError: logger.error("OctoBot can't start without " + CONFIG_FILE + " configuration file.") 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 -p install all") os._exit(-1) except ConfigEvaluatorError: logger.error( "OctoBot can't start without a valid " + CONFIG_EVALUATOR_FILE_PATH + " configuration file.\nThis file is generated on tentacle " "installation using the following command:\nstart.py -p install all" ) os._exit(-1) except ConfigTradingError: logger.error( "OctoBot can't start without a valid " + CONFIG_TRADING_FILE_PATH + " configuration file.\nThis file is generated on tentacle " "installation using the following command:\nstart.py -p install all" ) os._exit(-1)
def start_octobot(starting_args): fileConfig(LOGGING_CONFIG_FILE) logger = logging.getLogger("OctoBot Launcher") # Force new log file creation not to log at the previous one's end. logger.parent.handlers[1].doRollover() sys.excepthook = _log_uncaught_exceptions try: if starting_args.version: print(LONG_VERSION) else: # Version logger.info("Version : {0}".format(LONG_VERSION)) _check_public_announcements(logger) logger.info("Loading config files...") # configuration loading config = load_config(error=False) if config is None and is_config_empty_or_missing(): logger.info("No configuration found creating default...") init_config() config = load_config(error=False) if config is None: raise ConfigError # Handle utility methods before bot initializing if possible if starting_args.packager: Commands.package_manager(config, starting_args.packager) elif starting_args.creator: Commands.tentacle_creator(config, starting_args.creator) elif starting_args.encrypter: Commands.exchange_keys_encrypter() else: if not tentacles_arch_exists(): logger.info( "No tentacles found. Installing default tentacles ...") Commands.package_manager(config, ["install", "all"], force=True) config[CONFIG_EVALUATOR] = load_config( CONFIG_EVALUATOR_FILE_PATH, False) if config[CONFIG_EVALUATOR] is None: raise ConfigEvaluatorError config[CONFIG_TRADING_TENTACLES] = load_config( CONFIG_TRADING_FILE_PATH, False) if config[CONFIG_TRADING_TENTACLES] is None: raise ConfigTradingError if starting_args.data_collector: Commands.data_collector(config) elif starting_args.strategy_optimizer: Commands.start_strategy_optimizer( config, starting_args.strategy_optimizer) else: # In those cases load OctoBot from octobot import OctoBot from interfaces.bots.telegram.bot import TelegramApp from services import WebService TelegramApp.enable(config, starting_args.telegram) WebService.enable(config, not starting_args.no_web) update_config_with_args(starting_args, config) bot = OctoBot(config) import interfaces interfaces.__init__(bot, config) if not starting_args.no_open_web and not starting_args.no_web: Thread(target=_auto_open_web, args=(config, bot)).start() # set debug_mode = True to activate asyncio debug mode debug_mode = ConfigManager.is_in_dev_mode( config) or FORCE_ASYNCIO_DEBUG_OPTION asyncio.run(Commands.start_bot(bot, logger), debug=debug_mode) except ConfigError: logger.error("OctoBot can't start without " + CONFIG_FILE + " configuration file.") 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 -p install all") else: logger.exception(e) os._exit(-1) except ConfigEvaluatorError: logger.error( "OctoBot can't start without a valid " + CONFIG_EVALUATOR_FILE_PATH + " configuration file.\nThis file is generated on tentacle " "installation using the following command:\nstart.py -p install all" ) os._exit(-1) except ConfigTradingError: logger.error( "OctoBot can't start without a valid " + CONFIG_TRADING_FILE_PATH + " configuration file.\nThis file is generated on tentacle " "installation using the following command:\nstart.py -p install all" ) os._exit(-1)
elif args.update: Commands.update(logger) else: # In those cases load OctoBot from octobot import OctoBot config[CONFIG_EVALUATOR] = load_config(CONFIG_EVALUATOR_FILE_PATH, False) TelegramApp.enable(config, args.telegram) WebService.enable(config, args.web) bot = OctoBot(config) import interfaces interfaces.__init__(bot, config) if args.data_collector: Commands.data_collector(config) # start crypto bot options else: if args.backtesting: import backtesting backtesting.__init__(bot)
def create_backtesting_bot(config): bot = OctoBot(config) return bot
def create_backtesting_bot(config): return OctoBot(config)
async def test_create_bot(): # launch a bot config = load_test_config() bot = OctoBot(config) await asyncio.get_event_loop().run_in_executor(None, bot.stop_threads)
def start_octobot(starting_args): if starting_args.pause_time is not None: sleep(starting_args.pause_time) fileConfig('config/logging_config.ini') logger = logging.getLogger("OctoBot Launcher") # Force new log file creation not to log at the previous one's end. logger.parent.handlers[1].doRollover() sys.excepthook = _log_uncaught_exceptions # Version logger.info("Version : {0}".format(LONG_VERSION)) # Test update if starting_args.update: Commands.update(logger) else: Commands.check_bot_update(logger) logger.info("Loading config files...") config = load_config() # Handle utility methods before bot initializing if possible if starting_args.packager: Commands.package_manager(config, starting_args.packager) elif starting_args.creator: Commands.tentacle_creator(config, starting_args.creator) else: # In those cases load OctoBot from octobot import OctoBot config[CONFIG_EVALUATOR] = load_config(CONFIG_EVALUATOR_FILE_PATH, False) TelegramApp.enable(config, starting_args.telegram) WebService.enable(config, starting_args.web) bot = OctoBot(config) import interfaces interfaces.__init__(bot, config) if starting_args.data_collector: Commands.data_collector(config) # start crypto bot options else: if starting_args.backtesting: import backtesting backtesting.__init__(bot) config[CONFIG_BACKTESTING][CONFIG_ENABLED_OPTION] = True config[CONFIG_CATEGORY_NOTIFICATION][ CONFIG_ENABLED_OPTION] = False config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True if starting_args.simulate: config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False config[CONFIG_SIMULATOR][CONFIG_ENABLED_OPTION] = True if starting_args.risk is not None and 0 < starting_args.risk <= 1: config[CONFIG_TRADER][ CONFIG_TRADER_RISK] = starting_args.risk if starting_args.start: Commands.start_bot(bot, logger)