Merge pull request #6665 from freqtrade/config_from_config
Allow recursive loading of configuration files
This commit is contained in:
@@ -18,7 +18,8 @@ from freqtrade.configuration.deprecated_settings import (check_conflicting_setti
|
||||
process_removed_setting,
|
||||
process_temporary_deprecated_settings)
|
||||
from freqtrade.configuration.environment_vars import flat_vars_to_nested_dict
|
||||
from freqtrade.configuration.load_config import load_config_file, load_file, log_config_error_range
|
||||
from freqtrade.configuration.load_config import (load_config_file, load_file, load_from_files,
|
||||
log_config_error_range)
|
||||
from freqtrade.constants import DEFAULT_DB_DRYRUN_URL, DEFAULT_DB_PROD_URL, ENV_VAR_PREFIX
|
||||
from freqtrade.enums import RunMode
|
||||
from freqtrade.exceptions import OperationalException
|
||||
@@ -206,6 +207,32 @@ def test_from_config(default_conf, mocker, caplog) -> None:
|
||||
assert isinstance(validated_conf['user_data_dir'], Path)
|
||||
|
||||
|
||||
def test_from_recursive_files(testdatadir) -> None:
|
||||
files = testdatadir / "testconfigs/testconfig.json"
|
||||
|
||||
conf = Configuration.from_files([files])
|
||||
|
||||
assert conf
|
||||
# Exchange comes from "the first config"
|
||||
assert conf['exchange']
|
||||
# Pricing comes from the 2nd config
|
||||
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"
|
||||
|
||||
assert len(conf['config_files']) == 4
|
||||
assert 'testconfig.json' in conf['config_files'][0]
|
||||
assert 'test_pricing_conf.json' in conf['config_files'][1]
|
||||
assert 'test_base_config.json' in conf['config_files'][2]
|
||||
assert 'test_pricing2_conf.json' in conf['config_files'][3]
|
||||
|
||||
files = testdatadir / "testconfigs/recursive.json"
|
||||
with pytest.raises(OperationalException, match="Config loop detected."):
|
||||
load_from_files([files])
|
||||
|
||||
|
||||
def test_print_config(default_conf, mocker, caplog) -> None:
|
||||
conf1 = deepcopy(default_conf)
|
||||
# Delete non-json elements from default_conf
|
||||
|
6
tests/testdata/testconfigs/recursive.json
vendored
Normal file
6
tests/testdata/testconfigs/recursive.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
// This file fails as it's loading itself over and over
|
||||
"add_config_files": [
|
||||
"./recursive.json"
|
||||
]
|
||||
}
|
12
tests/testdata/testconfigs/test_base_config.json
vendored
Normal file
12
tests/testdata/testconfigs/test_base_config.json
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"stake_currency": "",
|
||||
"dry_run": true,
|
||||
"exchange": {
|
||||
"name": "",
|
||||
"key": "",
|
||||
"secret": "",
|
||||
"pair_whitelist": [],
|
||||
"ccxt_async_config": {
|
||||
}
|
||||
}
|
||||
}
|
18
tests/testdata/testconfigs/test_pricing2_conf.json
vendored
Normal file
18
tests/testdata/testconfigs/test_pricing2_conf.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"entry_pricing": {
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1,
|
||||
"price_last_balance": 0.0,
|
||||
"check_depth_of_market": {
|
||||
"enabled": false,
|
||||
"bids_to_ask_delta": 1
|
||||
}
|
||||
},
|
||||
"exit_pricing":{
|
||||
"price_side": "other",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1,
|
||||
"price_last_balance": 0.0
|
||||
}
|
||||
}
|
21
tests/testdata/testconfigs/test_pricing_conf.json
vendored
Normal file
21
tests/testdata/testconfigs/test_pricing_conf.json
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"entry_pricing": {
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1,
|
||||
"price_last_balance": 0.0,
|
||||
"check_depth_of_market": {
|
||||
"enabled": false,
|
||||
"bids_to_ask_delta": 1
|
||||
}
|
||||
},
|
||||
"exit_pricing":{
|
||||
"price_side": "same",
|
||||
"use_order_book": true,
|
||||
"order_book_top": 1,
|
||||
"price_last_balance": 0.0
|
||||
},
|
||||
"add_config_files": [
|
||||
"./test_pricing2_conf.json"
|
||||
]
|
||||
}
|
6
tests/testdata/testconfigs/testconfig.json
vendored
Normal file
6
tests/testdata/testconfigs/testconfig.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"add_config_files": [
|
||||
"test_base_config.json",
|
||||
"test_pricing_conf.json"
|
||||
]
|
||||
}
|
Reference in New Issue
Block a user