Allow comments in pairs files
This commit is contained in:
parent
f1f79b9448
commit
56ef3af424
@ -11,10 +11,10 @@ from freqtrade import constants
|
|||||||
from freqtrade.configuration.check_exchange import check_exchange
|
from freqtrade.configuration.check_exchange import check_exchange
|
||||||
from freqtrade.configuration.deprecated_settings import process_temporary_deprecated_settings
|
from freqtrade.configuration.deprecated_settings import process_temporary_deprecated_settings
|
||||||
from freqtrade.configuration.directory_operations import create_datadir, create_userdata_dir
|
from freqtrade.configuration.directory_operations import create_datadir, create_userdata_dir
|
||||||
from freqtrade.configuration.load_config import load_config_file
|
from freqtrade.configuration.load_config import load_config_file, load_file
|
||||||
from freqtrade.exceptions import OperationalException
|
from freqtrade.exceptions import OperationalException
|
||||||
from freqtrade.loggers import setup_logging
|
from freqtrade.loggers import setup_logging
|
||||||
from freqtrade.misc import deep_merge_dicts, json_load
|
from freqtrade.misc import deep_merge_dicts
|
||||||
from freqtrade.state import NON_UTIL_MODES, TRADING_MODES, RunMode
|
from freqtrade.state import NON_UTIL_MODES, TRADING_MODES, RunMode
|
||||||
|
|
||||||
|
|
||||||
@ -454,8 +454,7 @@ class Configuration:
|
|||||||
# or if pairs file is specified explicitely
|
# or if pairs file is specified explicitely
|
||||||
if not pairs_file.exists():
|
if not pairs_file.exists():
|
||||||
raise OperationalException(f'No pairs file found with path "{pairs_file}".')
|
raise OperationalException(f'No pairs file found with path "{pairs_file}".')
|
||||||
with pairs_file.open('r') as f:
|
config['pairs'] = load_file(pairs_file)
|
||||||
config['pairs'] = json_load(f)
|
|
||||||
config['pairs'].sort()
|
config['pairs'].sort()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -466,7 +465,6 @@ class Configuration:
|
|||||||
# Fall back to /dl_path/pairs.json
|
# Fall back to /dl_path/pairs.json
|
||||||
pairs_file = config['datadir'] / 'pairs.json'
|
pairs_file = config['datadir'] / 'pairs.json'
|
||||||
if pairs_file.exists():
|
if pairs_file.exists():
|
||||||
with pairs_file.open('r') as f:
|
config['pairs'] = load_file(pairs_file)
|
||||||
config['pairs'] = json_load(f)
|
|
||||||
if 'pairs' in config:
|
if 'pairs' in config:
|
||||||
config['pairs'].sort()
|
config['pairs'].sort()
|
||||||
|
@ -38,6 +38,15 @@ def log_config_error_range(path: str, errmsg: str) -> str:
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
|
||||||
|
def load_file(path: Path) -> Dict[str, Any]:
|
||||||
|
try:
|
||||||
|
with path.open('r') as file:
|
||||||
|
config = rapidjson.load(file, parse_mode=CONFIG_PARSE_MODE)
|
||||||
|
except FileNotFoundError:
|
||||||
|
raise OperationalException(f'File file "{path}" not found!')
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def load_config_file(path: str) -> Dict[str, Any]:
|
def load_config_file(path: str) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Loads a config file from the given path
|
Loads a config file from the given path
|
||||||
|
@ -81,7 +81,7 @@ def json_load(datafile: IO) -> Any:
|
|||||||
"""
|
"""
|
||||||
load data with rapidjson
|
load data with rapidjson
|
||||||
Use this to have a consistent experience,
|
Use this to have a consistent experience,
|
||||||
sete number_mode to "NM_NATIVE" for greatest speed
|
set number_mode to "NM_NATIVE" for greatest speed
|
||||||
"""
|
"""
|
||||||
return rapidjson.load(datafile, number_mode=rapidjson.NM_NATIVE)
|
return rapidjson.load(datafile, number_mode=rapidjson.NM_NATIVE)
|
||||||
|
|
||||||
|
@ -1038,37 +1038,30 @@ def test_pairlist_resolving_with_config(mocker, default_conf):
|
|||||||
|
|
||||||
def test_pairlist_resolving_with_config_pl(mocker, default_conf):
|
def test_pairlist_resolving_with_config_pl(mocker, default_conf):
|
||||||
patched_configuration_load_config_file(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))
|
|
||||||
mocker.patch.object(Path, "open", MagicMock(return_value=MagicMock()))
|
|
||||||
|
|
||||||
arglist = [
|
arglist = [
|
||||||
'download-data',
|
'download-data',
|
||||||
'--config', 'config.json',
|
'--config', 'config.json',
|
||||||
'--pairs-file', 'pairs.json',
|
'--pairs-file', 'tests/testdata/pairs.json',
|
||||||
]
|
]
|
||||||
|
|
||||||
args = Arguments(arglist).get_parsed_arg()
|
args = Arguments(arglist).get_parsed_arg()
|
||||||
|
|
||||||
configuration = Configuration(args)
|
configuration = Configuration(args)
|
||||||
config = configuration.get_config()
|
config = configuration.get_config()
|
||||||
|
assert len(config['pairs']) == 23
|
||||||
assert load_mock.call_count == 1
|
assert 'ETH/BTC' in config['pairs']
|
||||||
assert config['pairs'] == ['ETH/BTC', 'XRP/BTC']
|
assert 'XRP/BTC' in config['pairs']
|
||||||
assert config['exchange']['name'] == default_conf['exchange']['name']
|
assert config['exchange']['name'] == default_conf['exchange']['name']
|
||||||
|
|
||||||
|
|
||||||
def test_pairlist_resolving_with_config_pl_not_exists(mocker, default_conf):
|
def test_pairlist_resolving_with_config_pl_not_exists(mocker, default_conf):
|
||||||
patched_configuration_load_config_file(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 = [
|
arglist = [
|
||||||
'download-data',
|
'download-data',
|
||||||
'--config', 'config.json',
|
'--config', 'config.json',
|
||||||
'--pairs-file', 'pairs.json',
|
'--pairs-file', 'tests/testdata/pairs_doesnotexist.json',
|
||||||
]
|
]
|
||||||
|
|
||||||
args = Arguments(arglist).get_parsed_arg()
|
args = Arguments(arglist).get_parsed_arg()
|
||||||
@ -1081,7 +1074,7 @@ def test_pairlist_resolving_with_config_pl_not_exists(mocker, default_conf):
|
|||||||
def test_pairlist_resolving_fallback(mocker):
|
def test_pairlist_resolving_fallback(mocker):
|
||||||
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
mocker.patch.object(Path, "exists", MagicMock(return_value=True))
|
||||||
mocker.patch.object(Path, "open", MagicMock(return_value=MagicMock()))
|
mocker.patch.object(Path, "open", MagicMock(return_value=MagicMock()))
|
||||||
mocker.patch("freqtrade.configuration.configuration.json_load",
|
mocker.patch("freqtrade.configuration.configuration.load_file",
|
||||||
MagicMock(return_value=['XRP/BTC', 'ETH/BTC']))
|
MagicMock(return_value=['XRP/BTC', 'ETH/BTC']))
|
||||||
arglist = [
|
arglist = [
|
||||||
'download-data',
|
'download-data',
|
||||||
|
Loading…
Reference in New Issue
Block a user