def botclient(default_conf, mocker): setup_logging_pre() setup_logging(default_conf) default_conf['runmode'] = RunMode.DRY_RUN default_conf.update({ "api_server": { "enabled": True, "listen_ip_address": "127.0.0.1", "listen_port": 8080, "CORS_origins": ['http://example.com'], "username": _TEST_USER, "password": _TEST_PASS, } }) ftbot = get_patched_freqtradebot(mocker, default_conf) rpc = RPC(ftbot) mocker.patch('freqtrade.rpc.api_server.ApiServer.start_api', MagicMock()) try: apiserver = ApiServer(default_conf) apiserver.add_rpc_handler(rpc) yield ftbot, TestClient(apiserver.app) # Cleanup ... ? finally: ApiServer.shutdown()
def test_set_loggers_Filehandler(tmpdir): logger = logging.getLogger() orig_handlers = logger.handlers logger.handlers = [] logfile = Path(tmpdir) / 'ft_logfile.log' config = { 'verbosity': 2, 'logfile': str(logfile), } setup_logging_pre() setup_logging(config) assert len(logger.handlers) == 3 assert [ x for x in logger.handlers if type(x) == logging.handlers.RotatingFileHandler ] assert [x for x in logger.handlers if type(x) == logging.StreamHandler] assert [ x for x in logger.handlers if type(x) == logging.handlers.BufferingHandler ] # setting up logging again should NOT cause the loggers to be added a second time. setup_logging(config) assert len(logger.handlers) == 3 # reset handlers to not break pytest if logfile.exists: logfile.unlink() logger.handlers = orig_handlers
def test_set_loggers_syslog(): logger = logging.getLogger() orig_handlers = logger.handlers logger.handlers = [] config = { 'verbosity': 2, 'logfile': 'syslog:/dev/log', } setup_logging_pre() setup_logging(config) assert len(logger.handlers) == 3 assert [ x for x in logger.handlers if type(x) == logging.handlers.SysLogHandler ] assert [x for x in logger.handlers if type(x) == logging.StreamHandler] assert [ x for x in logger.handlers if type(x) == logging.handlers.BufferingHandler ] # setting up logging again should NOT cause the loggers to be added a second time. setup_logging(config) assert len(logger.handlers) == 3 # reset handlers to not break pytest logger.handlers = orig_handlers
def botclient(default_conf, mocker): setup_logging_pre() setup_logging(default_conf) default_conf['runmode'] = RunMode.DRY_RUN default_conf.update({"api_server": {"enabled": True, "listen_ip_address": "127.0.0.1", "listen_port": 8080, "CORS_origins": ['http://example.com'], "username": _TEST_USER, "password": _TEST_PASS, }}) ftbot = get_patched_freqtradebot(mocker, default_conf) mocker.patch('freqtrade.rpc.api_server.ApiServer.run', MagicMock()) apiserver = ApiServer(ftbot) yield ftbot, apiserver.app.test_client()
def main(sysargv: List[str] = None) -> None: """ This function will initiate the bot and start the trading loop. :return: None """ return_code: Any = 1 try: setup_logging_pre() arguments = Arguments(sysargv) args = arguments.get_parsed_arg() # Call subcommand. if 'func' in args: return_code = args['func'](args) else: # No subcommand was issued. raise OperationalException( "Usage of Freqtrade requires a subcommand to be specified.\n" "To have the bot executing trades in live/dry-run modes, " "depending on the value of the `dry_run` setting in the config, run Freqtrade " "as `freqtrade trade [options...]`.\n" "To see the full list of options available, please use " "`freqtrade --help` or `freqtrade <command> --help`." ) except SystemExit as e: return_code = e except KeyboardInterrupt: logger.info('SIGINT received, aborting ...') return_code = 0 except FreqtradeException as e: logger.error(str(e)) return_code = 2 except Exception: logger.exception('Fatal exception!') finally: sys.exit(return_code)
def test_set_loggers_syslog(mocker): logger = logging.getLogger() orig_handlers = logger.handlers logger.handlers = [] config = { 'verbosity': 2, 'logfile': 'syslog:/dev/log', } setup_logging_pre() setup_logging(config) assert len(logger.handlers) == 3 assert [ x for x in logger.handlers if type(x) == logging.handlers.SysLogHandler ] assert [x for x in logger.handlers if type(x) == logging.StreamHandler] assert [ x for x in logger.handlers if type(x) == logging.handlers.BufferingHandler ] # reset handlers to not break pytest logger.handlers = orig_handlers