Allow comments in pairs files

This commit is contained in:
Matthias
2021-04-06 11:59:58 +02:00
parent f1f79b9448
commit 56ef3af424
4 changed files with 21 additions and 21 deletions

View File

@@ -11,10 +11,10 @@ from freqtrade import constants
from freqtrade.configuration.check_exchange import check_exchange
from freqtrade.configuration.deprecated_settings import process_temporary_deprecated_settings
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.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
@@ -454,9 +454,8 @@ class Configuration:
# or if pairs file is specified explicitely
if not pairs_file.exists():
raise OperationalException(f'No pairs file found with path "{pairs_file}".')
with pairs_file.open('r') as f:
config['pairs'] = json_load(f)
config['pairs'].sort()
config['pairs'] = load_file(pairs_file)
config['pairs'].sort()
return
if 'config' in self.args and self.args['config']:
@@ -466,7 +465,6 @@ class Configuration:
# Fall back to /dl_path/pairs.json
pairs_file = config['datadir'] / 'pairs.json'
if pairs_file.exists():
with pairs_file.open('r') as f:
config['pairs'] = json_load(f)
config['pairs'] = load_file(pairs_file)
if 'pairs' in config:
config['pairs'].sort()

View File

@@ -38,6 +38,15 @@ def log_config_error_range(path: str, errmsg: str) -> str:
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]:
"""
Loads a config file from the given path

View File

@@ -81,7 +81,7 @@ def json_load(datafile: IO) -> Any:
"""
load data with rapidjson
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)