From 9556af1e6c82a7a739788967804794349a98fe1f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 10 Apr 2022 10:14:34 +0200 Subject: [PATCH] Improve documentation for config imports --- docs/configuration.md | 30 ++++++++++++++++++++++++++ freqtrade/configuration/load_config.py | 2 +- tests/test_configuration.py | 5 +++-- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 0c89bbbdd..369c4e2dd 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -80,6 +80,36 @@ This is similar to using multiple `--config` parameters, but simpler in usage as This is equivalent to the example above - but `config-private.json` is specified as cli argument. +??? Note "config collision handling" + If the same configuration setting takes place in both `config.json` and `config-import.json`, then the parent configuration wins. + In the below case, `max_open_trades` would be 3 after the merging - as the reusable "import" configuration has this key overwritten. + + ``` json title="user_data/config.json" + { + "max_open_trades": 3, + "stake_currency": "USDT", + "add_config_files": [ + "config-import.json" + ] + } + ``` + + ``` json title="user_data/config-import.json" + { + "max_open_trades": 10, + "stake_amount": "unlimited", + } + ``` + + Resulting combined configuration: + + ``` json title="Result" + { + "max_open_trades": 10, + "stake_currency": "USDT", + "stake_amount": "unlimited" + } + ``` ## Configuration parameters diff --git a/freqtrade/configuration/load_config.py b/freqtrade/configuration/load_config.py index 32c2ae0d9..4ef531c7a 100644 --- a/freqtrade/configuration/load_config.py +++ b/freqtrade/configuration/load_config.py @@ -103,7 +103,7 @@ def load_from_files(files: List[str], base_path: Path = None, level: int = 0) -> config_sub = load_from_files( config_tmp['add_config_files'], file.resolve().parent, level + 1) files_loaded.extend(config_sub.get('config_files', [])) - deep_merge_dicts(config_sub, config_tmp) + config_tmp = deep_merge_dicts(config_tmp, config_sub) files_loaded.insert(0, str(file)) diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 957468b86..db87c405f 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -219,8 +219,9 @@ def test_from_recursive_files(testdatadir) -> None: assert conf['entry_pricing'] assert conf['entry_pricing']['price_side'] == "same" assert conf['exit_pricing'] - # The other key comes from pricing2, which is imported by pricing.json - assert conf['exit_pricing']['price_side'] == "other" + # The other key comes from pricing2, which is imported by pricing.json. + # pricing.json is a level higher, therefore wins. + assert conf['exit_pricing']['price_side'] == "same" assert len(conf['config_files']) == 4 assert 'testconfig.json' in conf['config_files'][0]