2018-07-29 14:09:44 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, protected-access, invalid-name
|
2019-07-14 22:44:25 +00:00
|
|
|
import json
|
2018-07-19 19:12:27 +00:00
|
|
|
import logging
|
2019-07-25 18:35:20 +00:00
|
|
|
import warnings
|
2019-02-24 12:29:22 +00:00
|
|
|
from copy import deepcopy
|
2019-03-29 19:16:52 +00:00
|
|
|
from pathlib import Path
|
2019-07-25 18:35:20 +00:00
|
|
|
from unittest.mock import MagicMock
|
2018-03-17 21:44:47 +00:00
|
|
|
|
|
|
|
import pytest
|
2019-02-24 12:29:22 +00:00
|
|
|
from jsonschema import Draft4Validator, ValidationError, validate
|
2018-02-04 06:42:03 +00:00
|
|
|
|
2019-02-24 12:29:22 +00:00
|
|
|
from freqtrade import OperationalException, constants
|
2019-08-18 14:10:10 +00:00
|
|
|
from freqtrade.configuration import Arguments, Configuration, validate_config_consistency
|
2019-07-11 18:23:23 +00:00
|
|
|
from freqtrade.configuration.check_exchange import check_exchange
|
2019-08-18 14:10:10 +00:00
|
|
|
from freqtrade.configuration.config_validation import validate_config_schema
|
2019-07-12 00:26:27 +00:00
|
|
|
from freqtrade.configuration.create_datadir import create_datadir
|
2019-08-10 12:15:09 +00:00
|
|
|
from freqtrade.configuration.load_config import load_config_file
|
2018-07-04 07:31:35 +00:00
|
|
|
from freqtrade.constants import DEFAULT_DB_DRYRUN_URL, DEFAULT_DB_PROD_URL
|
2019-07-06 21:31:48 +00:00
|
|
|
from freqtrade.loggers import _set_loggers
|
2018-12-25 13:35:48 +00:00
|
|
|
from freqtrade.state import RunMode
|
2019-07-14 22:44:25 +00:00
|
|
|
from freqtrade.tests.conftest import (log_has, log_has_re,
|
|
|
|
patched_configuration_load_config_file)
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
|
2019-04-24 07:30:59 +00:00
|
|
|
@pytest.fixture(scope="function")
|
|
|
|
def all_conf():
|
|
|
|
config_file = Path(__file__).parents[2] / "config_full.json.example"
|
|
|
|
print(config_file)
|
2019-08-10 12:15:09 +00:00
|
|
|
conf = load_config_file(str(config_file))
|
2019-04-24 07:30:59 +00:00
|
|
|
return conf
|
|
|
|
|
|
|
|
|
2018-03-30 20:14:35 +00:00
|
|
|
def test_load_config_invalid_pair(default_conf) -> None:
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf['exchange']['pair_whitelist'].append('ETH-BTC')
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=r'.*does not match.*'):
|
2019-07-11 18:23:23 +00:00
|
|
|
validate_config_schema(default_conf)
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
|
2018-03-30 20:14:35 +00:00
|
|
|
def test_load_config_missing_attributes(default_conf) -> None:
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf.pop('exchange')
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=r'.*\'exchange\' is a required property.*'):
|
2019-07-11 18:23:23 +00:00
|
|
|
validate_config_schema(default_conf)
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
|
2018-06-03 22:48:26 +00:00
|
|
|
def test_load_config_incorrect_stake_amount(default_conf) -> None:
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf['stake_amount'] = 'fake'
|
2018-06-03 22:48:26 +00:00
|
|
|
|
|
|
|
with pytest.raises(ValidationError, match=r'.*\'fake\' does not match \'unlimited\'.*'):
|
2019-07-11 18:23:23 +00:00
|
|
|
validate_config_schema(default_conf)
|
2018-06-03 22:48:26 +00:00
|
|
|
|
|
|
|
|
2018-02-04 06:42:03 +00:00
|
|
|
def test_load_config_file(default_conf, mocker, caplog) -> None:
|
2019-08-10 12:15:09 +00:00
|
|
|
file_mock = mocker.patch('freqtrade.configuration.load_config.open', mocker.mock_open(
|
2019-07-14 22:44:25 +00:00
|
|
|
read_data=json.dumps(default_conf)
|
|
|
|
))
|
2018-02-04 06:42:03 +00:00
|
|
|
|
2019-08-10 12:15:09 +00:00
|
|
|
validated_conf = load_config_file('somefile')
|
2018-02-04 06:42:03 +00:00
|
|
|
assert file_mock.call_count == 1
|
|
|
|
assert validated_conf.items() >= default_conf.items()
|
|
|
|
|
|
|
|
|
2019-07-25 18:35:20 +00:00
|
|
|
def test__args_to_config(caplog):
|
|
|
|
|
|
|
|
arg_list = ['--strategy-path', 'TestTest']
|
|
|
|
args = Arguments(arg_list, '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = {}
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
# No warnings ...
|
|
|
|
configuration._args_to_config(config, argname="strategy_path", logstring="DeadBeef")
|
|
|
|
assert len(w) == 0
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has("DeadBeef", caplog)
|
2019-07-25 18:35:20 +00:00
|
|
|
assert config['strategy_path'] == "TestTest"
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = {}
|
|
|
|
with warnings.catch_warnings(record=True) as w:
|
|
|
|
# Deprecation warnings!
|
|
|
|
configuration._args_to_config(config, argname="strategy_path", logstring="DeadBeef",
|
|
|
|
deprecated_msg="Going away soon!")
|
|
|
|
assert len(w) == 1
|
|
|
|
assert issubclass(w[-1].category, DeprecationWarning)
|
|
|
|
assert "DEPRECATED: Going away soon!" in str(w[-1].message)
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has("DeadBeef", caplog)
|
2019-07-25 18:35:20 +00:00
|
|
|
assert config['strategy_path'] == "TestTest"
|
|
|
|
|
|
|
|
|
2018-05-03 08:48:25 +00:00
|
|
|
def test_load_config_max_open_trades_zero(default_conf, mocker, caplog) -> None:
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf['max_open_trades'] = 0
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2018-05-03 08:48:25 +00:00
|
|
|
|
2019-02-20 14:54:20 +00:00
|
|
|
args = Arguments([], '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
|
|
|
|
assert validated_conf['max_open_trades'] == 0
|
|
|
|
assert 'internals' in validated_conf
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Validating configuration ...', caplog)
|
2018-05-03 08:48:25 +00:00
|
|
|
|
|
|
|
|
2019-02-24 12:29:22 +00:00
|
|
|
def test_load_config_combine_dicts(default_conf, mocker, caplog) -> None:
|
|
|
|
conf1 = deepcopy(default_conf)
|
|
|
|
conf2 = deepcopy(default_conf)
|
|
|
|
del conf1['exchange']['key']
|
|
|
|
del conf1['exchange']['secret']
|
|
|
|
del conf2['exchange']['name']
|
|
|
|
conf2['exchange']['pair_whitelist'] += ['NANO/BTC']
|
|
|
|
|
|
|
|
config_files = [conf1, conf2]
|
|
|
|
|
|
|
|
configsmock = MagicMock(side_effect=config_files)
|
2019-07-11 22:41:09 +00:00
|
|
|
mocker.patch(
|
2019-08-10 15:47:58 +00:00
|
|
|
'freqtrade.configuration.configuration.load_config_file',
|
2019-07-11 22:41:09 +00:00
|
|
|
configsmock
|
|
|
|
)
|
2019-02-24 12:29:22 +00:00
|
|
|
|
|
|
|
arg_list = ['-c', 'test_conf.json', '--config', 'test2_conf.json', ]
|
|
|
|
args = Arguments(arg_list, '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
|
|
|
|
exchange_conf = default_conf['exchange']
|
|
|
|
assert validated_conf['exchange']['name'] == exchange_conf['name']
|
|
|
|
assert validated_conf['exchange']['key'] == exchange_conf['key']
|
|
|
|
assert validated_conf['exchange']['secret'] == exchange_conf['secret']
|
|
|
|
assert validated_conf['exchange']['pair_whitelist'] != conf1['exchange']['pair_whitelist']
|
|
|
|
assert validated_conf['exchange']['pair_whitelist'] == conf2['exchange']['pair_whitelist']
|
|
|
|
|
|
|
|
assert 'internals' in validated_conf
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Validating configuration ...', caplog)
|
2019-02-24 12:29:22 +00:00
|
|
|
|
|
|
|
|
2019-08-10 18:02:11 +00:00
|
|
|
def test_from_config(default_conf, mocker, caplog) -> None:
|
|
|
|
conf1 = deepcopy(default_conf)
|
|
|
|
conf2 = deepcopy(default_conf)
|
|
|
|
del conf1['exchange']['key']
|
|
|
|
del conf1['exchange']['secret']
|
|
|
|
del conf2['exchange']['name']
|
|
|
|
conf2['exchange']['pair_whitelist'] += ['NANO/BTC']
|
|
|
|
conf2['fiat_display_currency'] = "EUR"
|
|
|
|
config_files = [conf1, conf2]
|
|
|
|
|
|
|
|
configsmock = MagicMock(side_effect=config_files)
|
|
|
|
mocker.patch(
|
|
|
|
'freqtrade.configuration.configuration.load_config_file',
|
|
|
|
configsmock
|
|
|
|
)
|
|
|
|
|
|
|
|
validated_conf = Configuration.from_files(['test_conf.json', 'test2_conf.json'])
|
|
|
|
|
|
|
|
exchange_conf = default_conf['exchange']
|
|
|
|
assert validated_conf['exchange']['name'] == exchange_conf['name']
|
|
|
|
assert validated_conf['exchange']['key'] == exchange_conf['key']
|
|
|
|
assert validated_conf['exchange']['secret'] == exchange_conf['secret']
|
|
|
|
assert validated_conf['exchange']['pair_whitelist'] != conf1['exchange']['pair_whitelist']
|
|
|
|
assert validated_conf['exchange']['pair_whitelist'] == conf2['exchange']['pair_whitelist']
|
|
|
|
assert validated_conf['fiat_display_currency'] == "EUR"
|
|
|
|
assert 'internals' in validated_conf
|
2019-08-12 04:49:41 +00:00
|
|
|
assert log_has('Validating configuration ...', caplog)
|
2019-02-24 12:29:22 +00:00
|
|
|
|
|
|
|
|
2018-11-14 10:37:53 +00:00
|
|
|
def test_load_config_max_open_trades_minus_one(default_conf, mocker, caplog) -> None:
|
|
|
|
default_conf['max_open_trades'] = -1
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2018-11-14 10:37:53 +00:00
|
|
|
|
|
|
|
args = Arguments([], '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
|
|
|
|
assert validated_conf['max_open_trades'] > 999999999
|
|
|
|
assert validated_conf['max_open_trades'] == float('inf')
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Validating configuration ...', caplog)
|
2018-12-25 13:35:48 +00:00
|
|
|
assert "runmode" in validated_conf
|
|
|
|
assert validated_conf['runmode'] == RunMode.DRY_RUN
|
2018-11-14 10:37:53 +00:00
|
|
|
|
|
|
|
|
2018-06-08 00:01:38 +00:00
|
|
|
def test_load_config_file_exception(mocker) -> None:
|
2018-03-06 03:44:27 +00:00
|
|
|
mocker.patch(
|
2019-07-11 21:39:42 +00:00
|
|
|
'freqtrade.configuration.configuration.open',
|
2018-03-06 03:44:27 +00:00
|
|
|
MagicMock(side_effect=FileNotFoundError('File not found'))
|
|
|
|
)
|
|
|
|
|
2018-06-08 00:01:38 +00:00
|
|
|
with pytest.raises(OperationalException, match=r'.*Config file "somefile" not found!*'):
|
2019-08-10 12:15:09 +00:00
|
|
|
load_config_file('somefile')
|
2018-03-06 03:44:27 +00:00
|
|
|
|
|
|
|
|
2018-02-04 06:42:03 +00:00
|
|
|
def test_load_config(default_conf, mocker) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
args = Arguments([], '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
2018-03-03 21:39:39 +00:00
|
|
|
validated_conf = configuration.load_config()
|
2018-02-04 06:42:03 +00:00
|
|
|
|
2018-03-27 16:29:51 +00:00
|
|
|
assert validated_conf.get('strategy') == 'DefaultStrategy'
|
|
|
|
assert validated_conf.get('strategy_path') is None
|
2018-12-03 19:31:25 +00:00
|
|
|
assert 'edge' not in validated_conf
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_load_config_with_params(default_conf, mocker) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2019-07-11 21:39:42 +00:00
|
|
|
|
2018-05-31 19:04:10 +00:00
|
|
|
arglist = [
|
2018-03-24 19:44:04 +00:00
|
|
|
'--strategy', 'TestStrategy',
|
2018-03-27 16:29:51 +00:00
|
|
|
'--strategy-path', '/some/path',
|
2018-06-07 03:27:55 +00:00
|
|
|
'--db-url', 'sqlite:///someurl',
|
2018-02-04 06:42:03 +00:00
|
|
|
]
|
2018-05-31 19:04:10 +00:00
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
2018-02-04 06:42:03 +00:00
|
|
|
configuration = Configuration(args)
|
2018-03-03 21:39:39 +00:00
|
|
|
validated_conf = configuration.load_config()
|
2018-02-04 06:42:03 +00:00
|
|
|
|
2018-03-27 16:29:51 +00:00
|
|
|
assert validated_conf.get('strategy') == 'TestStrategy'
|
|
|
|
assert validated_conf.get('strategy_path') == '/some/path'
|
2018-06-07 03:27:55 +00:00
|
|
|
assert validated_conf.get('db_url') == 'sqlite:///someurl'
|
2018-03-27 16:29:51 +00:00
|
|
|
|
2019-01-06 12:47:36 +00:00
|
|
|
# Test conf provided db_url prod
|
|
|
|
conf = default_conf.copy()
|
|
|
|
conf["dry_run"] = False
|
|
|
|
conf["db_url"] = "sqlite:///path/to/db.sqlite"
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, conf)
|
2019-01-06 12:47:36 +00:00
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--strategy', 'TestStrategy',
|
|
|
|
'--strategy-path', '/some/path'
|
|
|
|
]
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
assert validated_conf.get('db_url') == "sqlite:///path/to/db.sqlite"
|
|
|
|
|
|
|
|
# Test conf provided db_url dry_run
|
|
|
|
conf = default_conf.copy()
|
|
|
|
conf["dry_run"] = True
|
|
|
|
conf["db_url"] = "sqlite:///path/to/db.sqlite"
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, conf)
|
2019-01-06 12:47:36 +00:00
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--strategy', 'TestStrategy',
|
|
|
|
'--strategy-path', '/some/path'
|
|
|
|
]
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
assert validated_conf.get('db_url') == "sqlite:///path/to/db.sqlite"
|
|
|
|
|
|
|
|
# Test args provided db_url prod
|
2018-06-16 18:55:35 +00:00
|
|
|
conf = default_conf.copy()
|
|
|
|
conf["dry_run"] = False
|
|
|
|
del conf["db_url"]
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, conf)
|
2018-06-16 18:55:35 +00:00
|
|
|
|
|
|
|
arglist = [
|
2018-07-29 14:09:44 +00:00
|
|
|
'--strategy', 'TestStrategy',
|
|
|
|
'--strategy-path', '/some/path'
|
|
|
|
]
|
2018-06-16 18:55:35 +00:00
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
assert validated_conf.get('db_url') == DEFAULT_DB_PROD_URL
|
2018-12-25 13:35:48 +00:00
|
|
|
assert "runmode" in validated_conf
|
|
|
|
assert validated_conf['runmode'] == RunMode.LIVE
|
2018-06-16 18:55:35 +00:00
|
|
|
|
2019-01-06 12:47:36 +00:00
|
|
|
# Test args provided db_url dry_run
|
2018-06-16 18:55:35 +00:00
|
|
|
conf = default_conf.copy()
|
|
|
|
conf["dry_run"] = True
|
|
|
|
conf["db_url"] = DEFAULT_DB_PROD_URL
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, conf)
|
2018-06-16 18:55:35 +00:00
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--strategy', 'TestStrategy',
|
|
|
|
'--strategy-path', '/some/path'
|
|
|
|
]
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
assert validated_conf.get('db_url') == DEFAULT_DB_DRYRUN_URL
|
|
|
|
|
2018-03-27 16:29:51 +00:00
|
|
|
|
|
|
|
def test_load_custom_strategy(default_conf, mocker) -> None:
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf.update({
|
2018-03-27 16:29:51 +00:00
|
|
|
'strategy': 'CustomStrategy',
|
|
|
|
'strategy_path': '/tmp/strategies',
|
|
|
|
})
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2018-03-27 16:29:51 +00:00
|
|
|
|
|
|
|
args = Arguments([], '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
|
|
|
|
assert validated_conf.get('strategy') == 'CustomStrategy'
|
|
|
|
assert validated_conf.get('strategy_path') == '/tmp/strategies'
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_show_info(default_conf, mocker, caplog) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2019-07-11 21:39:42 +00:00
|
|
|
|
2018-05-31 19:04:10 +00:00
|
|
|
arglist = [
|
2018-03-24 19:44:04 +00:00
|
|
|
'--strategy', 'TestStrategy',
|
2018-06-07 03:27:55 +00:00
|
|
|
'--db-url', 'sqlite:///tmp/testdb',
|
2018-02-04 06:42:03 +00:00
|
|
|
]
|
2018-05-31 19:04:10 +00:00
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
2018-02-04 06:42:03 +00:00
|
|
|
|
|
|
|
configuration = Configuration(args)
|
2018-03-03 21:39:39 +00:00
|
|
|
configuration.get_config()
|
|
|
|
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Using DB: "sqlite:///tmp/testdb"', caplog)
|
|
|
|
assert log_has('Dry run is enabled', caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_setup_configuration_without_arguments(mocker, default_conf, caplog) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2019-07-11 21:39:42 +00:00
|
|
|
|
2018-05-31 19:04:10 +00:00
|
|
|
arglist = [
|
2018-02-09 07:35:38 +00:00
|
|
|
'--config', 'config.json',
|
2018-03-24 19:44:04 +00:00
|
|
|
'--strategy', 'DefaultStrategy',
|
2018-02-09 07:35:38 +00:00
|
|
|
'backtesting'
|
|
|
|
]
|
|
|
|
|
2018-05-31 19:04:10 +00:00
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
2018-02-09 07:35:38 +00:00
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = configuration.get_config()
|
|
|
|
assert 'max_open_trades' in config
|
|
|
|
assert 'stake_currency' in config
|
|
|
|
assert 'stake_amount' in config
|
|
|
|
assert 'exchange' in config
|
|
|
|
assert 'pair_whitelist' in config['exchange']
|
|
|
|
assert 'datadir' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Using data directory: {} ...'.format(config['datadir']), caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
assert 'ticker_interval' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert not log_has('Parameter -i/--ticker-interval detected ...', caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
2018-07-17 18:26:59 +00:00
|
|
|
assert 'position_stacking' not in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert not log_has('Parameter --enable-position-stacking detected ...', caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
|
|
|
assert 'refresh_pairs' not in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert not log_has('Parameter -r/--refresh-pairs-cached detected ...', caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
|
|
|
assert 'timerange' not in config
|
|
|
|
assert 'export' not in config
|
|
|
|
|
|
|
|
|
2019-08-18 05:18:21 +00:00
|
|
|
@pytest.mark.filterwarnings("ignore:DEPRECATED")
|
2018-02-09 07:35:38 +00:00
|
|
|
def test_setup_configuration_with_arguments(mocker, default_conf, caplog) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2019-07-11 22:41:09 +00:00
|
|
|
mocker.patch(
|
2019-07-12 00:26:27 +00:00
|
|
|
'freqtrade.configuration.configuration.create_datadir',
|
|
|
|
lambda c, x: x
|
2019-07-11 22:41:09 +00:00
|
|
|
)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
2018-05-31 19:04:10 +00:00
|
|
|
arglist = [
|
2018-02-09 07:35:38 +00:00
|
|
|
'--config', 'config.json',
|
2018-03-24 19:44:04 +00:00
|
|
|
'--strategy', 'DefaultStrategy',
|
2018-02-09 07:35:38 +00:00
|
|
|
'--datadir', '/foo/bar',
|
|
|
|
'backtesting',
|
2018-02-03 16:15:40 +00:00
|
|
|
'--ticker-interval', '1m',
|
2018-07-17 18:26:59 +00:00
|
|
|
'--enable-position-stacking',
|
2018-07-17 19:05:03 +00:00
|
|
|
'--disable-max-market-positions',
|
2018-02-09 07:35:38 +00:00
|
|
|
'--refresh-pairs-cached',
|
|
|
|
'--timerange', ':100',
|
|
|
|
'--export', '/bar/foo'
|
|
|
|
]
|
|
|
|
|
2018-05-31 19:04:10 +00:00
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
2018-02-09 07:35:38 +00:00
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = configuration.get_config()
|
|
|
|
assert 'max_open_trades' in config
|
|
|
|
assert 'stake_currency' in config
|
|
|
|
assert 'stake_amount' in config
|
|
|
|
assert 'exchange' in config
|
|
|
|
assert 'pair_whitelist' in config['exchange']
|
|
|
|
assert 'datadir' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Using data directory: {} ...'.format(config['datadir']), caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
assert 'ticker_interval' in config
|
2019-04-24 19:24:00 +00:00
|
|
|
assert log_has('Parameter -i/--ticker-interval detected ... Using ticker_interval: 1m ...',
|
2019-08-11 18:17:39 +00:00
|
|
|
caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
2018-07-17 18:26:59 +00:00
|
|
|
assert 'position_stacking'in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Parameter --enable-position-stacking detected ...', caplog)
|
2018-07-17 19:05:03 +00:00
|
|
|
|
|
|
|
assert 'use_max_market_positions' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Parameter --disable-max-market-positions detected ...', caplog)
|
|
|
|
assert log_has('max_open_trades set to unlimited ...', caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
|
|
|
assert 'refresh_pairs'in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Parameter -r/--refresh-pairs-cached detected ...', caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
assert 'timerange' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Parameter --timerange detected: {} ...'.format(config['timerange']), caplog)
|
2018-02-09 07:35:38 +00:00
|
|
|
|
|
|
|
assert 'export' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Parameter --export detected: {} ...'.format(config['export']), caplog)
|
2018-03-04 08:51:22 +00:00
|
|
|
|
|
|
|
|
2018-07-28 04:40:39 +00:00
|
|
|
def test_setup_configuration_with_stratlist(mocker, default_conf, caplog) -> None:
|
|
|
|
"""
|
|
|
|
Test setup_configuration() function
|
|
|
|
"""
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2018-07-28 04:40:39 +00:00
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'backtesting',
|
|
|
|
'--ticker-interval', '1m',
|
|
|
|
'--export', '/bar/foo',
|
|
|
|
'--strategy-list',
|
|
|
|
'DefaultStrategy',
|
|
|
|
'TestStrategy'
|
|
|
|
]
|
|
|
|
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
2018-12-25 13:35:48 +00:00
|
|
|
configuration = Configuration(args, RunMode.BACKTEST)
|
2018-07-28 04:40:39 +00:00
|
|
|
config = configuration.get_config()
|
2018-12-25 13:35:48 +00:00
|
|
|
assert config['runmode'] == RunMode.BACKTEST
|
2018-07-28 04:40:39 +00:00
|
|
|
assert 'max_open_trades' in config
|
|
|
|
assert 'stake_currency' in config
|
|
|
|
assert 'stake_amount' in config
|
|
|
|
assert 'exchange' in config
|
|
|
|
assert 'pair_whitelist' in config['exchange']
|
|
|
|
assert 'datadir' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Using data directory: {} ...'.format(config['datadir']), caplog)
|
2018-07-28 04:40:39 +00:00
|
|
|
assert 'ticker_interval' in config
|
2019-04-24 19:24:00 +00:00
|
|
|
assert log_has('Parameter -i/--ticker-interval detected ... Using ticker_interval: 1m ...',
|
2019-08-11 18:17:39 +00:00
|
|
|
caplog)
|
2018-07-28 04:40:39 +00:00
|
|
|
|
|
|
|
assert 'strategy_list' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Using strategy list of 2 Strategies', caplog)
|
2018-07-28 04:40:39 +00:00
|
|
|
|
|
|
|
assert 'position_stacking' not in config
|
|
|
|
|
|
|
|
assert 'use_max_market_positions' not in config
|
|
|
|
|
|
|
|
assert 'timerange' not in config
|
|
|
|
|
|
|
|
assert 'export' in config
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Parameter --export detected: {} ...'.format(config['export']), caplog)
|
2018-07-28 04:40:39 +00:00
|
|
|
|
|
|
|
|
2018-03-05 07:12:34 +00:00
|
|
|
def test_hyperopt_with_arguments(mocker, default_conf, caplog) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2019-07-11 21:39:42 +00:00
|
|
|
|
2018-05-31 19:04:10 +00:00
|
|
|
arglist = [
|
2018-03-04 08:51:22 +00:00
|
|
|
'hyperopt',
|
2018-03-05 07:12:34 +00:00
|
|
|
'--epochs', '10',
|
2018-03-04 08:51:22 +00:00
|
|
|
'--spaces', 'all',
|
|
|
|
]
|
2018-05-31 19:04:10 +00:00
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
2018-03-04 08:51:22 +00:00
|
|
|
|
2018-12-25 13:35:48 +00:00
|
|
|
configuration = Configuration(args, RunMode.HYPEROPT)
|
2018-03-04 08:51:22 +00:00
|
|
|
config = configuration.get_config()
|
2018-03-05 07:12:34 +00:00
|
|
|
|
|
|
|
assert 'epochs' in config
|
|
|
|
assert int(config['epochs']) == 10
|
2019-04-24 19:12:23 +00:00
|
|
|
assert log_has('Parameter --epochs detected ... Will run Hyperopt with for 10 epochs ...',
|
2019-08-11 18:17:39 +00:00
|
|
|
caplog)
|
2018-03-05 07:12:34 +00:00
|
|
|
|
2018-03-04 08:51:22 +00:00
|
|
|
assert 'spaces' in config
|
2018-03-04 08:58:20 +00:00
|
|
|
assert config['spaces'] == ['all']
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Parameter -s/--spaces detected: [\'all\']', caplog)
|
2018-12-25 13:35:48 +00:00
|
|
|
assert "runmode" in config
|
|
|
|
assert config['runmode'] == RunMode.HYPEROPT
|
2018-03-30 20:14:35 +00:00
|
|
|
|
|
|
|
|
2018-10-04 18:35:28 +00:00
|
|
|
def test_check_exchange(default_conf, caplog) -> None:
|
2019-06-14 15:40:25 +00:00
|
|
|
# Test an officially supported by Freqtrade team exchange
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf.get('exchange').update({'name': 'BITTREX'})
|
2019-07-11 18:23:23 +00:00
|
|
|
assert check_exchange(default_conf)
|
2019-06-15 11:14:07 +00:00
|
|
|
assert log_has_re(r"Exchange .* is officially supported by the Freqtrade development team\.",
|
2019-08-11 18:17:39 +00:00
|
|
|
caplog)
|
2019-06-15 11:14:07 +00:00
|
|
|
caplog.clear()
|
2018-03-30 20:14:35 +00:00
|
|
|
|
2019-06-14 15:40:25 +00:00
|
|
|
# Test an officially supported by Freqtrade team exchange
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf.get('exchange').update({'name': 'binance'})
|
2019-07-11 18:23:23 +00:00
|
|
|
assert check_exchange(default_conf)
|
2019-06-15 11:14:07 +00:00
|
|
|
assert log_has_re(r"Exchange .* is officially supported by the Freqtrade development team\.",
|
2019-08-11 18:17:39 +00:00
|
|
|
caplog)
|
2019-06-15 11:14:07 +00:00
|
|
|
caplog.clear()
|
2018-03-30 20:14:35 +00:00
|
|
|
|
2019-06-14 15:40:25 +00:00
|
|
|
# Test an available exchange, supported by ccxt
|
|
|
|
default_conf.get('exchange').update({'name': 'kraken'})
|
2019-07-11 18:23:23 +00:00
|
|
|
assert check_exchange(default_conf)
|
2019-06-15 11:14:07 +00:00
|
|
|
assert log_has_re(r"Exchange .* is supported by ccxt and .* not officially supported "
|
2019-08-11 18:17:39 +00:00
|
|
|
r"by the Freqtrade development team\. .*", caplog)
|
2019-06-15 11:14:07 +00:00
|
|
|
caplog.clear()
|
2019-06-14 15:40:25 +00:00
|
|
|
|
|
|
|
# Test a 'bad' exchange, which known to have serious problems
|
|
|
|
default_conf.get('exchange').update({'name': 'bitmex'})
|
2019-08-13 06:26:10 +00:00
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match=r"Exchange .* is known to not work with the bot yet.*"):
|
|
|
|
check_exchange(default_conf)
|
2019-06-15 11:14:07 +00:00
|
|
|
caplog.clear()
|
2019-06-14 15:40:25 +00:00
|
|
|
|
|
|
|
# Test a 'bad' exchange with check_for_bad=False
|
|
|
|
default_conf.get('exchange').update({'name': 'bitmex'})
|
2019-07-11 18:23:23 +00:00
|
|
|
assert check_exchange(default_conf, False)
|
2019-06-15 11:14:07 +00:00
|
|
|
assert log_has_re(r"Exchange .* is supported by ccxt and .* not officially supported "
|
2019-08-11 18:17:39 +00:00
|
|
|
r"by the Freqtrade development team\. .*", caplog)
|
2019-06-15 11:14:07 +00:00
|
|
|
caplog.clear()
|
2019-06-14 15:40:25 +00:00
|
|
|
|
|
|
|
# Test an invalid exchange
|
2018-07-30 12:40:52 +00:00
|
|
|
default_conf.get('exchange').update({'name': 'unknown_exchange'})
|
2018-03-30 20:14:35 +00:00
|
|
|
|
|
|
|
with pytest.raises(
|
|
|
|
OperationalException,
|
2019-06-12 20:03:16 +00:00
|
|
|
match=r'.*Exchange "unknown_exchange" is not supported by ccxt '
|
|
|
|
r'and therefore not available for the bot.*'
|
2018-03-30 20:14:35 +00:00
|
|
|
):
|
2019-07-11 18:23:23 +00:00
|
|
|
check_exchange(default_conf)
|
2018-07-19 19:12:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_cli_verbose_with_params(default_conf, mocker, caplog) -> None:
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2019-07-11 21:39:42 +00:00
|
|
|
|
2018-07-19 19:12:27 +00:00
|
|
|
# Prevent setting loggers
|
2019-07-06 21:31:48 +00:00
|
|
|
mocker.patch('freqtrade.loggers._set_loggers', MagicMock)
|
2018-07-19 19:12:27 +00:00
|
|
|
arglist = ['-vvv']
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
|
|
|
|
assert validated_conf.get('verbosity') == 3
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Verbosity set to 3', caplog)
|
2018-07-19 19:12:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-07-06 21:31:48 +00:00
|
|
|
_set_loggers()
|
2018-07-19 19:12:27 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-07-06 21:31:48 +00:00
|
|
|
_set_loggers(verbosity=2)
|
2018-07-19 19:12:27 +00:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-07-06 21:31:48 +00:00
|
|
|
_set_loggers(verbosity=3)
|
2018-07-19 19:12:27 +00:00
|
|
|
|
|
|
|
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
|
2018-07-30 11:57:51 +00:00
|
|
|
|
|
|
|
|
2019-03-29 19:16:52 +00:00
|
|
|
def test_set_logfile(default_conf, mocker):
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2019-03-29 19:16:52 +00:00
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--logfile', 'test_file.log',
|
|
|
|
]
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
|
|
|
|
assert validated_conf['logfile'] == "test_file.log"
|
|
|
|
f = Path("test_file.log")
|
|
|
|
assert f.is_file()
|
|
|
|
f.unlink()
|
|
|
|
|
|
|
|
|
2018-10-10 18:13:56 +00:00
|
|
|
def test_load_config_warn_forcebuy(default_conf, mocker, caplog) -> None:
|
|
|
|
default_conf['forcebuy_enable'] = True
|
2019-07-14 22:44:25 +00:00
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
2018-10-10 18:13:56 +00:00
|
|
|
|
|
|
|
args = Arguments([], '').get_parsed_arg()
|
|
|
|
configuration = Configuration(args)
|
|
|
|
validated_conf = configuration.load_config()
|
|
|
|
|
|
|
|
assert validated_conf.get('forcebuy_enable')
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('`forcebuy` RPC message enabled.', caplog)
|
2018-10-10 18:13:56 +00:00
|
|
|
|
|
|
|
|
2018-07-30 11:57:51 +00:00
|
|
|
def test_validate_default_conf(default_conf) -> None:
|
2018-12-06 05:57:07 +00:00
|
|
|
validate(default_conf, constants.CONF_SCHEMA, Draft4Validator)
|
2019-01-01 13:07:40 +00:00
|
|
|
|
|
|
|
|
2019-07-12 00:26:27 +00:00
|
|
|
def test_create_datadir(mocker, default_conf, caplog) -> None:
|
2019-07-17 18:53:29 +00:00
|
|
|
mocker.patch.object(Path, "is_dir", MagicMock(return_value=False))
|
|
|
|
md = mocker.patch.object(Path, 'mkdir', MagicMock())
|
|
|
|
|
2019-07-12 00:26:27 +00:00
|
|
|
create_datadir(default_conf, '/foo/bar')
|
2019-07-17 18:53:29 +00:00
|
|
|
assert md.call_args[1]['parents'] is True
|
2019-08-11 18:17:39 +00:00
|
|
|
assert log_has('Created data directory: /foo/bar', caplog)
|
2019-03-14 08:01:03 +00:00
|
|
|
|
|
|
|
|
2019-03-14 08:26:31 +00:00
|
|
|
def test_validate_tsl(default_conf):
|
2019-03-14 08:01:03 +00:00
|
|
|
default_conf['trailing_stop'] = True
|
|
|
|
default_conf['trailing_stop_positive'] = 0
|
|
|
|
default_conf['trailing_stop_positive_offset'] = 0
|
|
|
|
|
|
|
|
default_conf['trailing_only_offset_is_reached'] = True
|
|
|
|
with pytest.raises(OperationalException,
|
2019-03-16 09:38:25 +00:00
|
|
|
match=r'The config trailing_only_offset_is_reached needs '
|
2019-03-14 08:01:03 +00:00
|
|
|
'trailing_stop_positive_offset to be more than 0 in your config.'):
|
2019-08-18 14:10:10 +00:00
|
|
|
validate_config_consistency(default_conf)
|
2019-03-14 08:01:03 +00:00
|
|
|
|
|
|
|
default_conf['trailing_stop_positive_offset'] = 0.01
|
|
|
|
default_conf['trailing_stop_positive'] = 0.015
|
|
|
|
with pytest.raises(OperationalException,
|
2019-03-16 09:38:25 +00:00
|
|
|
match=r'The config trailing_stop_positive_offset needs '
|
2019-03-14 08:01:03 +00:00
|
|
|
'to be greater than trailing_stop_positive_offset in your config.'):
|
2019-08-18 14:10:10 +00:00
|
|
|
validate_config_consistency(default_conf)
|
2019-03-16 09:38:25 +00:00
|
|
|
|
|
|
|
default_conf['trailing_stop_positive'] = 0.01
|
|
|
|
default_conf['trailing_stop_positive_offset'] = 0.015
|
2019-08-18 14:10:10 +00:00
|
|
|
validate_config_consistency(default_conf)
|
2019-04-11 15:07:51 +00:00
|
|
|
|
|
|
|
|
2019-08-18 14:19:24 +00:00
|
|
|
def test_validate_edge(edge_conf):
|
|
|
|
edge_conf.update({"pairlist": {
|
|
|
|
"method": "VolumePairList",
|
|
|
|
}})
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException,
|
|
|
|
match="Edge and VolumePairList are incompatible, "
|
|
|
|
"Edge will override whatever pairs VolumePairlist selects."):
|
|
|
|
validate_config_consistency(edge_conf)
|
|
|
|
|
|
|
|
edge_conf.update({"pairlist": {
|
|
|
|
"method": "StaticPairList",
|
|
|
|
}})
|
|
|
|
validate_config_consistency(edge_conf)
|
2019-04-11 15:07:51 +00:00
|
|
|
|
|
|
|
|
2019-08-11 21:33:34 +00:00
|
|
|
def test_load_config_test_comments() -> None:
|
|
|
|
"""
|
|
|
|
Load config with comments
|
|
|
|
"""
|
|
|
|
config_file = Path(__file__).parents[0] / "config_test_comments.json"
|
|
|
|
print(config_file)
|
|
|
|
conf = load_config_file(str(config_file))
|
|
|
|
|
|
|
|
assert conf
|
|
|
|
|
|
|
|
|
2019-04-11 15:07:51 +00:00
|
|
|
def test_load_config_default_exchange(all_conf) -> None:
|
2019-04-11 19:22:33 +00:00
|
|
|
"""
|
|
|
|
config['exchange'] subtree has required options in it
|
|
|
|
so it cannot be omitted in the config
|
|
|
|
"""
|
2019-04-11 15:07:51 +00:00
|
|
|
del all_conf['exchange']
|
|
|
|
|
|
|
|
assert 'exchange' not in all_conf
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError,
|
|
|
|
match=r'\'exchange\' is a required property'):
|
2019-07-11 18:23:23 +00:00
|
|
|
validate_config_schema(all_conf)
|
2019-04-11 15:07:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_load_config_default_exchange_name(all_conf) -> None:
|
2019-04-11 19:22:33 +00:00
|
|
|
"""
|
|
|
|
config['exchange']['name'] option is required
|
|
|
|
so it cannot be omitted in the config
|
|
|
|
"""
|
2019-04-11 15:07:51 +00:00
|
|
|
del all_conf['exchange']['name']
|
|
|
|
|
|
|
|
assert 'name' not in all_conf['exchange']
|
|
|
|
|
|
|
|
with pytest.raises(ValidationError,
|
|
|
|
match=r'\'name\' is a required property'):
|
2019-07-11 18:23:23 +00:00
|
|
|
validate_config_schema(all_conf)
|
2019-04-11 15:07:51 +00:00
|
|
|
|
|
|
|
|
2019-04-24 07:48:25 +00:00
|
|
|
@pytest.mark.parametrize("keys", [("exchange", "sandbox", False),
|
|
|
|
("exchange", "key", ""),
|
|
|
|
("exchange", "secret", ""),
|
|
|
|
("exchange", "password", ""),
|
|
|
|
])
|
|
|
|
def test_load_config_default_subkeys(all_conf, keys) -> None:
|
2019-04-11 19:22:33 +00:00
|
|
|
"""
|
2019-04-24 07:48:25 +00:00
|
|
|
Test for parameters with default values in sub-paths
|
|
|
|
so they can be omitted in the config and the default value
|
2019-04-24 07:55:53 +00:00
|
|
|
should is added to the config.
|
2019-04-11 19:22:33 +00:00
|
|
|
"""
|
2019-04-24 07:48:25 +00:00
|
|
|
# Get first level key
|
|
|
|
key = keys[0]
|
|
|
|
# get second level key
|
|
|
|
subkey = keys[1]
|
2019-04-11 15:07:51 +00:00
|
|
|
|
2019-04-24 07:48:25 +00:00
|
|
|
del all_conf[key][subkey]
|
2019-04-11 15:07:51 +00:00
|
|
|
|
2019-04-24 07:48:25 +00:00
|
|
|
assert subkey not in all_conf[key]
|
2019-04-11 15:07:51 +00:00
|
|
|
|
2019-07-11 18:23:23 +00:00
|
|
|
validate_config_schema(all_conf)
|
2019-04-24 07:48:25 +00:00
|
|
|
assert subkey in all_conf[key]
|
|
|
|
assert all_conf[key][subkey] == keys[2]
|
2019-08-16 13:52:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_pairlist_resolving():
|
|
|
|
arglist = [
|
|
|
|
'download-data',
|
|
|
|
'--pairs', 'ETH/BTC', 'XRP/BTC',
|
|
|
|
'--exchange', 'binance'
|
|
|
|
]
|
|
|
|
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = configuration.get_config()
|
|
|
|
|
|
|
|
assert config['pairs'] == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
assert config['exchange']['name'] == 'binance'
|
|
|
|
|
|
|
|
|
|
|
|
def test_pairlist_resolving_with_config(mocker, default_conf):
|
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
|
|
|
arglist = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'download-data',
|
|
|
|
]
|
|
|
|
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = configuration.get_config()
|
|
|
|
|
|
|
|
assert config['pairs'] == default_conf['exchange']['pair_whitelist']
|
|
|
|
assert config['exchange']['name'] == default_conf['exchange']['name']
|
|
|
|
|
|
|
|
# Override pairs
|
|
|
|
arglist = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'download-data',
|
|
|
|
'--pairs', 'ETH/BTC', 'XRP/BTC',
|
|
|
|
]
|
|
|
|
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = configuration.get_config()
|
|
|
|
|
|
|
|
assert config['pairs'] == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
assert config['exchange']['name'] == default_conf['exchange']['name']
|
|
|
|
|
|
|
|
|
|
|
|
def test_pairlist_resolving_with_config_pl(mocker, default_conf):
|
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
|
|
|
load_mock = mocker.patch("freqtrade.configuration.configuration.json_load",
|
|
|
|
MagicMock(return_value=['XRP/BTC', 'ETH/BTC']))
|
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'download-data',
|
|
|
|
'--pairs-file', 'pairs.json',
|
|
|
|
]
|
|
|
|
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = configuration.get_config()
|
|
|
|
|
|
|
|
assert load_mock.call_count == 1
|
|
|
|
assert config['pairs'] == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
assert config['exchange']['name'] == default_conf['exchange']['name']
|
|
|
|
|
|
|
|
|
|
|
|
def test_pairlist_resolving_with_config_pl_not_exists(mocker, default_conf):
|
|
|
|
patched_configuration_load_config_file(mocker, default_conf)
|
|
|
|
mocker.patch("freqtrade.configuration.configuration.json_load",
|
|
|
|
MagicMock(return_value=['XRP/BTC', 'ETH/BTC']))
|
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=False))
|
|
|
|
|
|
|
|
arglist = [
|
|
|
|
'--config', 'config.json',
|
|
|
|
'download-data',
|
|
|
|
'--pairs-file', 'pairs.json',
|
|
|
|
]
|
|
|
|
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
with pytest.raises(OperationalException, match=r"No pairs file found with path.*"):
|
|
|
|
configuration = Configuration(args)
|
|
|
|
configuration.get_config()
|
2019-08-17 05:05:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_pairlist_resolving_fallback(mocker):
|
|
|
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
|
|
|
mocker.patch("freqtrade.configuration.configuration.json_load",
|
|
|
|
MagicMock(return_value=['XRP/BTC', 'ETH/BTC']))
|
|
|
|
arglist = [
|
|
|
|
'download-data',
|
|
|
|
'--exchange', 'binance'
|
|
|
|
]
|
|
|
|
|
|
|
|
args = Arguments(arglist, '').get_parsed_arg()
|
|
|
|
|
|
|
|
configuration = Configuration(args)
|
|
|
|
config = configuration.get_config()
|
|
|
|
|
|
|
|
assert config['pairs'] == ['ETH/BTC', 'XRP/BTC']
|
|
|
|
assert config['exchange']['name'] == 'binance'
|