mirror of
https://github.com/freqtrade/freqtrade.git
synced 2026-01-26 00:40:23 +00:00
Merge pull request #10979 from amalysh/develop
allow json in environment variables
This commit is contained in:
@@ -39,13 +39,19 @@ Please note that Environment variables will overwrite corresponding settings in
|
|||||||
|
|
||||||
Common example:
|
Common example:
|
||||||
|
|
||||||
```
|
``` bash
|
||||||
FREQTRADE__TELEGRAM__CHAT_ID=<telegramchatid>
|
FREQTRADE__TELEGRAM__CHAT_ID=<telegramchatid>
|
||||||
FREQTRADE__TELEGRAM__TOKEN=<telegramToken>
|
FREQTRADE__TELEGRAM__TOKEN=<telegramToken>
|
||||||
FREQTRADE__EXCHANGE__KEY=<yourExchangeKey>
|
FREQTRADE__EXCHANGE__KEY=<yourExchangeKey>
|
||||||
FREQTRADE__EXCHANGE__SECRET=<yourExchangeSecret>
|
FREQTRADE__EXCHANGE__SECRET=<yourExchangeSecret>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Json lists are parsed as json - so you can use the following to set a list of pairs:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
export FREQTRADE__EXCHANGE__PAIR_WHITELIST='["BTC/USDT", "ETH/USDT"]'
|
||||||
|
```
|
||||||
|
|
||||||
!!! 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.
|
||||||
|
|
||||||
@@ -54,7 +60,7 @@ FREQTRADE__EXCHANGE__SECRET=<yourExchangeSecret>
|
|||||||
|
|
||||||
??? Warning "Loading sequence"
|
??? Warning "Loading sequence"
|
||||||
Environment variables are loaded after the initial configuration. As such, you cannot provide the path to the configuration through environment variables. Please use `--config path/to/config.json` for that.
|
Environment variables are loaded after the initial configuration. As such, you cannot provide the path to the configuration through environment variables. Please use `--config path/to/config.json` for that.
|
||||||
This also applies to user_dir to some degree. while the user directory can be set through environment variables - the configuration will **not** be loaded from that location.
|
This also applies to `user_dir` to some degree. while the user directory can be set through environment variables - the configuration will **not** be loaded from that location.
|
||||||
|
|
||||||
### Multiple configuration files
|
### Multiple configuration files
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import logging
|
|||||||
import os
|
import os
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import rapidjson
|
||||||
|
|
||||||
from freqtrade.constants import ENV_VAR_PREFIX
|
from freqtrade.constants import ENV_VAR_PREFIX
|
||||||
from freqtrade.misc import deep_merge_dicts
|
from freqtrade.misc import deep_merge_dicts
|
||||||
|
|
||||||
@@ -20,6 +22,14 @@ def _get_var_typed(val):
|
|||||||
return True
|
return True
|
||||||
elif val.lower() in ("f", "false"):
|
elif val.lower() in ("f", "false"):
|
||||||
return False
|
return False
|
||||||
|
# try to convert from json
|
||||||
|
try:
|
||||||
|
value = rapidjson.loads(val)
|
||||||
|
# Limited to lists for now
|
||||||
|
if isinstance(value, list):
|
||||||
|
return value
|
||||||
|
except rapidjson.JSONDecodeError:
|
||||||
|
pass
|
||||||
# keep as string
|
# keep as string
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|||||||
@@ -1481,6 +1481,12 @@ def test_flat_vars_to_nested_dict(caplog):
|
|||||||
"FREQTRADE__STAKE_AMOUNT": "200.05",
|
"FREQTRADE__STAKE_AMOUNT": "200.05",
|
||||||
"FREQTRADE__TELEGRAM__CHAT_ID": "2151",
|
"FREQTRADE__TELEGRAM__CHAT_ID": "2151",
|
||||||
"NOT_RELEVANT": "200.0", # Will be ignored
|
"NOT_RELEVANT": "200.0", # Will be ignored
|
||||||
|
"FREQTRADE__ARRAY": '[{"name":"default","host":"xxx"}]',
|
||||||
|
"FREQTRADE__EXCHANGE__PAIR_WHITELIST": '["BTC/USDT", "ETH/USDT"]',
|
||||||
|
# Fails due to trailing comma
|
||||||
|
"FREQTRADE__ARRAY_TRAIL_COMMA": '[{"name":"default","host":"xxx",}]',
|
||||||
|
# Object fails
|
||||||
|
"FREQTRADE__OBJECT": '{"name":"default","host":"xxx"}',
|
||||||
}
|
}
|
||||||
expected = {
|
expected = {
|
||||||
"stake_amount": 200.05,
|
"stake_amount": 200.05,
|
||||||
@@ -1494,8 +1500,12 @@ def test_flat_vars_to_nested_dict(caplog):
|
|||||||
},
|
},
|
||||||
"some_setting": True,
|
"some_setting": True,
|
||||||
"some_false_setting": False,
|
"some_false_setting": False,
|
||||||
|
"pair_whitelist": ["BTC/USDT", "ETH/USDT"],
|
||||||
},
|
},
|
||||||
"telegram": {"chat_id": "2151"},
|
"telegram": {"chat_id": "2151"},
|
||||||
|
"array": [{"name": "default", "host": "xxx"}],
|
||||||
|
"object": '{"name":"default","host":"xxx"}',
|
||||||
|
"array_trail_comma": '[{"name":"default","host":"xxx",}]',
|
||||||
}
|
}
|
||||||
res = _flat_vars_to_nested_dict(test_args, ENV_VAR_PREFIX)
|
res = _flat_vars_to_nested_dict(test_args, ENV_VAR_PREFIX)
|
||||||
assert res == expected
|
assert res == expected
|
||||||
|
|||||||
Reference in New Issue
Block a user