2018-02-12 06:10:21 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, C0103
|
|
|
|
import argparse
|
2018-03-17 21:44:47 +00:00
|
|
|
|
2018-02-12 06:10:21 +00:00
|
|
|
import pytest
|
|
|
|
|
2019-07-11 18:23:23 +00:00
|
|
|
from freqtrade.configuration import Arguments, TimeRange
|
2019-07-14 22:55:35 +00:00
|
|
|
from freqtrade.configuration.arguments import ARGS_DOWNLOADER, ARGS_PLOT_DATAFRAME
|
2019-07-25 23:21:31 +00:00
|
|
|
from freqtrade.configuration.cli_options import check_int_positive
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Parse common command-line-arguments. Used for all tools
|
|
|
|
def test_parse_args_none() -> None:
|
|
|
|
arguments = Arguments([], '')
|
|
|
|
assert isinstance(arguments, Arguments)
|
|
|
|
assert isinstance(arguments.parser, argparse.ArgumentParser)
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_defaults() -> None:
|
|
|
|
args = Arguments([], '').get_parsed_arg()
|
2019-02-20 14:54:20 +00:00
|
|
|
assert args.config == ['config.json']
|
2018-12-03 19:31:25 +00:00
|
|
|
assert args.strategy_path is None
|
|
|
|
assert args.datadir is None
|
2019-07-06 23:53:13 +00:00
|
|
|
assert args.verbosity == 0
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_config() -> None:
|
|
|
|
args = Arguments(['-c', '/dev/null'], '').get_parsed_arg()
|
2019-02-20 14:54:20 +00:00
|
|
|
assert args.config == ['/dev/null']
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
args = Arguments(['--config', '/dev/null'], '').get_parsed_arg()
|
2019-02-20 14:54:20 +00:00
|
|
|
assert args.config == ['/dev/null']
|
|
|
|
|
|
|
|
args = Arguments(['--config', '/dev/null',
|
|
|
|
'--config', '/dev/zero'],
|
|
|
|
'').get_parsed_arg()
|
|
|
|
assert args.config == ['/dev/null', '/dev/zero']
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
|
2018-06-07 18:30:13 +00:00
|
|
|
def test_parse_args_db_url() -> None:
|
|
|
|
args = Arguments(['--db-url', 'sqlite:///test.sqlite'], '').get_parsed_arg()
|
|
|
|
assert args.db_url == 'sqlite:///test.sqlite'
|
|
|
|
|
|
|
|
|
2018-02-12 06:10:21 +00:00
|
|
|
def test_parse_args_verbose() -> None:
|
|
|
|
args = Arguments(['-v'], '').get_parsed_arg()
|
2019-07-06 23:53:13 +00:00
|
|
|
assert args.verbosity == 1
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
args = Arguments(['--verbose'], '').get_parsed_arg()
|
2019-07-06 23:53:13 +00:00
|
|
|
assert args.verbosity == 1
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
|
2019-06-18 22:53:38 +00:00
|
|
|
def test_common_scripts_options() -> None:
|
2018-02-03 16:15:40 +00:00
|
|
|
arguments = Arguments(['-p', 'ETH/BTC'], '')
|
2019-07-18 14:55:35 +00:00
|
|
|
arguments._build_args(ARGS_DOWNLOADER)
|
|
|
|
args = arguments._parse_args()
|
2019-01-23 18:11:05 +00:00
|
|
|
assert args.pairs == 'ETH/BTC'
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_version() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'0'):
|
|
|
|
Arguments(['--version'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['-c'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
2018-03-25 14:28:04 +00:00
|
|
|
def test_parse_args_strategy() -> None:
|
|
|
|
args = Arguments(['--strategy', 'SomeStrategy'], '').get_parsed_arg()
|
|
|
|
assert args.strategy == 'SomeStrategy'
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_strategy_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['--strategy'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_strategy_path() -> None:
|
|
|
|
args = Arguments(['--strategy-path', '/some/path'], '').get_parsed_arg()
|
|
|
|
assert args.strategy_path == '/some/path'
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_strategy_path_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['--strategy-path'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
2018-02-12 06:10:21 +00:00
|
|
|
def test_parse_timerange_incorrect() -> None:
|
2018-06-05 21:41:50 +00:00
|
|
|
assert TimeRange(None, 'line', 0, -200) == Arguments.parse_timerange('-200')
|
|
|
|
assert TimeRange('line', None, 200, 0) == Arguments.parse_timerange('200-')
|
|
|
|
assert TimeRange('index', 'index', 200, 500) == Arguments.parse_timerange('200-500')
|
2018-04-27 21:16:34 +00:00
|
|
|
|
2018-06-05 21:41:50 +00:00
|
|
|
assert TimeRange('date', None, 1274486400, 0) == Arguments.parse_timerange('20100522-')
|
|
|
|
assert TimeRange(None, 'date', 0, 1274486400) == Arguments.parse_timerange('-20100522')
|
2018-04-27 21:30:42 +00:00
|
|
|
timerange = Arguments.parse_timerange('20100522-20150730')
|
2018-06-05 21:41:50 +00:00
|
|
|
assert timerange == TimeRange('date', 'date', 1274486400, 1438214400)
|
2018-04-27 21:16:34 +00:00
|
|
|
|
2018-06-02 19:46:54 +00:00
|
|
|
# Added test for unix timestamp - BTC genesis date
|
2018-06-05 21:41:50 +00:00
|
|
|
assert TimeRange('date', None, 1231006505, 0) == Arguments.parse_timerange('1231006505-')
|
|
|
|
assert TimeRange(None, 'date', 0, 1233360000) == Arguments.parse_timerange('-1233360000')
|
2018-06-02 19:46:54 +00:00
|
|
|
timerange = Arguments.parse_timerange('1231006505-1233360000')
|
2018-06-05 21:41:50 +00:00
|
|
|
assert TimeRange('date', 'date', 1231006505, 1233360000) == timerange
|
|
|
|
|
|
|
|
# TODO: Find solution for the following case (passing timestamp in ms)
|
|
|
|
timerange = Arguments.parse_timerange('1231006505000-1233360000000')
|
|
|
|
assert TimeRange('date', 'date', 1231006505, 1233360000) != timerange
|
|
|
|
|
2018-02-12 06:10:21 +00:00
|
|
|
with pytest.raises(Exception, match=r'Incorrect syntax.*'):
|
|
|
|
Arguments.parse_timerange('-')
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_backtesting_invalid() -> None:
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['backtesting --ticker-interval'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
with pytest.raises(SystemExit, match=r'2'):
|
|
|
|
Arguments(['backtesting --ticker-interval', 'abc'], '').get_parsed_arg()
|
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_backtesting_custom() -> None:
|
|
|
|
args = [
|
|
|
|
'-c', 'test_conf.json',
|
|
|
|
'backtesting',
|
|
|
|
'--live',
|
2018-03-24 09:21:59 +00:00
|
|
|
'--ticker-interval', '1m',
|
2018-07-28 04:40:39 +00:00
|
|
|
'--refresh-pairs-cached',
|
|
|
|
'--strategy-list',
|
|
|
|
'DefaultStrategy',
|
|
|
|
'TestStrategy'
|
|
|
|
]
|
2018-02-12 06:10:21 +00:00
|
|
|
call_args = Arguments(args, '').get_parsed_arg()
|
2019-02-20 14:54:20 +00:00
|
|
|
assert call_args.config == ['test_conf.json']
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.live is True
|
2019-07-06 23:53:13 +00:00
|
|
|
assert call_args.verbosity == 0
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.subparser == 'backtesting'
|
|
|
|
assert call_args.func is not None
|
2018-03-24 09:21:59 +00:00
|
|
|
assert call_args.ticker_interval == '1m'
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.refresh_pairs is True
|
2018-07-28 04:40:39 +00:00
|
|
|
assert type(call_args.strategy_list) is list
|
|
|
|
assert len(call_args.strategy_list) == 2
|
2018-02-12 06:10:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_parse_args_hyperopt_custom() -> None:
|
2018-03-04 08:51:22 +00:00
|
|
|
args = [
|
|
|
|
'-c', 'test_conf.json',
|
|
|
|
'hyperopt',
|
|
|
|
'--epochs', '20',
|
|
|
|
'--spaces', 'buy'
|
|
|
|
]
|
2018-02-12 06:10:21 +00:00
|
|
|
call_args = Arguments(args, '').get_parsed_arg()
|
2019-02-20 14:54:20 +00:00
|
|
|
assert call_args.config == ['test_conf.json']
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.epochs == 20
|
2019-07-06 23:53:13 +00:00
|
|
|
assert call_args.verbosity == 0
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.subparser == 'hyperopt'
|
2018-03-04 08:58:20 +00:00
|
|
|
assert call_args.spaces == ['buy']
|
2018-02-12 06:10:21 +00:00
|
|
|
assert call_args.func is not None
|
2018-06-02 21:47:20 +00:00
|
|
|
|
|
|
|
|
2019-05-29 18:57:14 +00:00
|
|
|
def test_download_data_options() -> None:
|
2018-06-02 21:47:20 +00:00
|
|
|
args = [
|
|
|
|
'--pairs-file', 'file_with_pairs',
|
2019-07-04 17:56:48 +00:00
|
|
|
'--datadir', 'datadir/directory',
|
2018-06-02 21:47:20 +00:00
|
|
|
'--days', '30',
|
|
|
|
'--exchange', 'binance'
|
|
|
|
]
|
|
|
|
arguments = Arguments(args, '')
|
2019-07-18 14:55:35 +00:00
|
|
|
arguments._build_args(ARGS_DOWNLOADER)
|
|
|
|
args = arguments._parse_args()
|
2018-06-02 21:47:20 +00:00
|
|
|
assert args.pairs_file == 'file_with_pairs'
|
2019-07-04 17:56:48 +00:00
|
|
|
assert args.datadir == 'datadir/directory'
|
2018-06-02 21:47:20 +00:00
|
|
|
assert args.days == 30
|
|
|
|
assert args.exchange == 'binance'
|
2019-05-23 17:53:42 +00:00
|
|
|
|
|
|
|
|
2019-06-16 17:35:15 +00:00
|
|
|
def test_plot_dataframe_options() -> None:
|
|
|
|
args = [
|
|
|
|
'--indicators1', 'sma10,sma100',
|
|
|
|
'--indicators2', 'macd,fastd,fastk',
|
|
|
|
'--plot-limit', '30',
|
2019-06-16 11:19:06 +00:00
|
|
|
'-p', 'UNITTEST/BTC',
|
2019-06-16 17:35:15 +00:00
|
|
|
]
|
|
|
|
arguments = Arguments(args, '')
|
2019-07-18 14:55:35 +00:00
|
|
|
arguments._build_args(ARGS_PLOT_DATAFRAME)
|
|
|
|
pargs = arguments._parse_args()
|
2019-06-16 11:19:06 +00:00
|
|
|
assert pargs.indicators1 == "sma10,sma100"
|
|
|
|
assert pargs.indicators2 == "macd,fastd,fastk"
|
|
|
|
assert pargs.plot_limit == 30
|
|
|
|
assert pargs.pairs == "UNITTEST/BTC"
|
|
|
|
|
2019-06-16 17:35:15 +00:00
|
|
|
|
2019-05-23 17:53:42 +00:00
|
|
|
def test_check_int_positive() -> None:
|
2019-06-22 18:09:39 +00:00
|
|
|
assert check_int_positive("3") == 3
|
|
|
|
assert check_int_positive("1") == 1
|
|
|
|
assert check_int_positive("100") == 100
|
2019-05-25 11:16:00 +00:00
|
|
|
|
|
|
|
with pytest.raises(argparse.ArgumentTypeError):
|
2019-06-22 18:09:39 +00:00
|
|
|
check_int_positive("-2")
|
2019-05-25 11:16:00 +00:00
|
|
|
|
|
|
|
with pytest.raises(argparse.ArgumentTypeError):
|
2019-06-22 18:09:39 +00:00
|
|
|
check_int_positive("0")
|
2019-05-25 11:16:00 +00:00
|
|
|
|
2019-05-24 04:22:27 +00:00
|
|
|
with pytest.raises(argparse.ArgumentTypeError):
|
2019-06-22 18:09:39 +00:00
|
|
|
check_int_positive("3.5")
|
2019-05-24 04:22:27 +00:00
|
|
|
|
|
|
|
with pytest.raises(argparse.ArgumentTypeError):
|
2019-06-22 18:09:39 +00:00
|
|
|
check_int_positive("DeadBeef")
|