예제 #1
0
def main(sysargv: List[str] = None) -> None:
    """
    This function will initiate the bot and start the trading loop.
    :return: None
    """

    return_code: Any = 1
    worker = None
    try:
        set_loggers()

        arguments = Arguments(sysargv, 'Free, open source crypto trading bot')
        args: Namespace = arguments.get_parsed_arg()

        # A subcommand has been issued.
        # Means if Backtesting or Hyperopt have been called we exit the bot
        if hasattr(args, 'func'):
            args.func(args)
            # TODO: fetch return_code as returned by the command function here
            return_code = 0
        else:
            # Load and run worker
            worker = Worker(args)
            worker.run()

    except SystemExit as e:
        return_code = e
    except KeyboardInterrupt:
        logger.info('SIGINT received, aborting ...')
        return_code = 0
    except OperationalException as e:
        logger.error(str(e))
        return_code = 2
    except Exception:
        logger.exception('Fatal exception!')
    finally:
        if worker:
            worker.exit()
        sys.exit(return_code)
def test_set_loggers() -> None:
    # Reset Logging to Debug, otherwise this fails randomly as it's set globally
    logging.getLogger('requests').setLevel(logging.DEBUG)
    logging.getLogger("urllib3").setLevel(logging.DEBUG)
    logging.getLogger('ccxt.base.exchange').setLevel(logging.DEBUG)
    logging.getLogger('telegram').setLevel(logging.DEBUG)

    previous_value1 = logging.getLogger('requests').level
    previous_value2 = logging.getLogger('ccxt.base.exchange').level
    previous_value3 = logging.getLogger('telegram').level

    set_loggers()

    value1 = logging.getLogger('requests').level
    assert previous_value1 is not value1
    assert value1 is logging.INFO

    value2 = logging.getLogger('ccxt.base.exchange').level
    assert previous_value2 is not value2
    assert value2 is logging.INFO

    value3 = logging.getLogger('telegram').level
    assert previous_value3 is not value3
    assert value3 is logging.INFO

    set_loggers(log_level=2)

    assert logging.getLogger('requests').level is logging.DEBUG
    assert logging.getLogger('ccxt.base.exchange').level is logging.INFO
    assert logging.getLogger('telegram').level is logging.INFO

    set_loggers(log_level=3)

    assert logging.getLogger('requests').level is logging.DEBUG
    assert logging.getLogger('ccxt.base.exchange').level is logging.DEBUG
    assert logging.getLogger('telegram').level is logging.INFO
예제 #3
0
파일: main.py 프로젝트: sprgn/freqtrade
        logger.exception('Fatal exception!')
    finally:
        if freqtrade:
            freqtrade.rpc.send_msg({
                'type': RPCMessageType.STATUS_NOTIFICATION,
                'status': 'process died'
            })
            freqtrade.cleanup()
        sys.exit(return_code)


def reconfigure(freqtrade: FreqtradeBot, args: Namespace) -> FreqtradeBot:
    """
    Cleans up current instance, reloads the configuration and returns the new instance
    """
    # Clean up current modules
    freqtrade.cleanup()

    # Create new instance
    freqtrade = FreqtradeBot(Configuration(args, None).get_config())
    freqtrade.rpc.send_msg({
        'type': RPCMessageType.STATUS_NOTIFICATION,
        'status': 'config reloaded'
    })
    return freqtrade


if __name__ == '__main__':
    set_loggers()
    main(sys.argv[1:])
import sys
from pathlib import Path
import arrow

from freqtrade import arguments
from freqtrade.arguments import TimeRange
from freqtrade.exchange import Exchange
from freqtrade.data.history import download_pair_history
from freqtrade.configuration import Configuration, set_loggers

import logging
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
)
set_loggers(0)

DEFAULT_DL_PATH = 'user_data/data'

arguments = arguments.Arguments(sys.argv[1:], 'download utility')
arguments.testdata_dl_options()
args = arguments.parse_args()

timeframes = args.timeframes

if args.config:
    configuration = Configuration(args)
    config = configuration._load_config_file(args.config)

    config['stake_currency'] = ''
    # Ensure we do not use Exchange credentials