Don't convert telegram chat_id

closes #5840
This commit is contained in:
Matthias 2021-11-05 19:27:54 +01:00
parent 781f8a059c
commit 60a5ded532
3 changed files with 16 additions and 2 deletions

View File

@ -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. 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=<telegramchatid>
FREQTRADE__TELEGRAM__TOKEN=<telegramToken>
FREQTRADE__EXCHANGE__KEY=<yourExchangeKey>
FREQTRADE__EXCHANGE__SECRET=<yourExchangeSecret>
```
!!! Note !!! 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. 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.

View File

@ -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__) :param prefix: Prefix to consider (usually FREQTRADE__)
:return: Nested dict based on available and relevant variables. :return: Nested dict based on available and relevant variables.
""" """
no_convert = ['CHAT_ID']
relevant_vars: Dict[str, Any] = {} relevant_vars: Dict[str, Any] = {}
for env_var, val in sorted(env_dict.items()): 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}'") logger.info(f"Loading variable '{env_var}'")
key = env_var.replace(prefix, '') key = env_var.replace(prefix, '')
for k in reversed(key.split('__')): 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) relevant_vars = deep_merge_dicts(val, relevant_vars)
return relevant_vars return relevant_vars

View File

@ -1359,6 +1359,7 @@ def test_flat_vars_to_nested_dict(caplog):
'FREQTRADE__ASK_STRATEGY__PRICE_SIDE': 'bid', 'FREQTRADE__ASK_STRATEGY__PRICE_SIDE': 'bid',
'FREQTRADE__ASK_STRATEGY__cccc': '500', 'FREQTRADE__ASK_STRATEGY__cccc': '500',
'FREQTRADE__STAKE_AMOUNT': '200.05', 'FREQTRADE__STAKE_AMOUNT': '200.05',
'FREQTRADE__TELEGRAM__CHAT_ID': '2151',
'NOT_RELEVANT': '200.0', # Will be ignored 'NOT_RELEVANT': '200.0', # Will be ignored
} }
expected = { expected = {
@ -1373,6 +1374,9 @@ def test_flat_vars_to_nested_dict(caplog):
}, },
'some_setting': True, 'some_setting': True,
'some_false_setting': False, 'some_false_setting': False,
},
'telegram': {
'chat_id': '2151'
} }
} }
res = flat_vars_to_nested_dict(test_args, ENV_VAR_PREFIX) res = flat_vars_to_nested_dict(test_args, ENV_VAR_PREFIX)