diff --git a/docs/configuration.md b/docs/configuration.md index bc8a40dcb..24198b44c 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -37,6 +37,15 @@ Using this scheme, all configuration settings will also be available as environm Please note that Environment variables will overwrite corresponding settings in your configuration, but command line Arguments will always win. +Common example: + +``` +FREQTRADE__TELEGRAM__CHAT_ID= +FREQTRADE__TELEGRAM__TOKEN= +FREQTRADE__EXCHANGE__KEY= +FREQTRADE__EXCHANGE__SECRET= +``` + !!! Note Environment variables detected are logged at startup - so if you can't find why a value is not what you think it should be based on the configuration, make sure it's not loaded from an environment variable. diff --git a/freqtrade/configuration/environment_vars.py b/freqtrade/configuration/environment_vars.py index 4c190ed04..473758fe1 100644 --- a/freqtrade/configuration/environment_vars.py +++ b/freqtrade/configuration/environment_vars.py @@ -32,6 +32,7 @@ def flat_vars_to_nested_dict(env_dict: Dict[str, Any], prefix: str) -> Dict[str, :param prefix: Prefix to consider (usually FREQTRADE__) :return: Nested dict based on available and relevant variables. """ + no_convert = ['CHAT_ID'] relevant_vars: Dict[str, Any] = {} for env_var, val in sorted(env_dict.items()): @@ -39,9 +40,9 @@ def flat_vars_to_nested_dict(env_dict: Dict[str, Any], prefix: str) -> Dict[str, logger.info(f"Loading variable '{env_var}'") key = env_var.replace(prefix, '') for k in reversed(key.split('__')): - val = {k.lower(): get_var_typed(val) if type(val) != dict else val} + val = {k.lower(): get_var_typed(val) + if type(val) != dict and k not in no_convert else val} relevant_vars = deep_merge_dicts(val, relevant_vars) - return relevant_vars diff --git a/tests/test_configuration.py b/tests/test_configuration.py index 1ce45e4d5..57add66bf 100644 --- a/tests/test_configuration.py +++ b/tests/test_configuration.py @@ -1359,6 +1359,7 @@ def test_flat_vars_to_nested_dict(caplog): 'FREQTRADE__ASK_STRATEGY__PRICE_SIDE': 'bid', 'FREQTRADE__ASK_STRATEGY__cccc': '500', 'FREQTRADE__STAKE_AMOUNT': '200.05', + 'FREQTRADE__TELEGRAM__CHAT_ID': '2151', 'NOT_RELEVANT': '200.0', # Will be ignored } expected = { @@ -1373,6 +1374,9 @@ def test_flat_vars_to_nested_dict(caplog): }, 'some_setting': True, 'some_false_setting': False, + }, + 'telegram': { + 'chat_id': '2151' } } res = flat_vars_to_nested_dict(test_args, ENV_VAR_PREFIX)