Merge pull request #3470 from Theagainmen/Telegram_emojis_V2

reload_conf -> reload_config both supported
This commit is contained in:
Matthias 2020-06-10 19:55:12 +02:00 committed by GitHub
commit 06799b13cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 42 additions and 41 deletions

View File

@ -110,7 +110,7 @@ python3 scripts/rest_client.py --config rest_config.json <command> [optional par
| `start` | | Starts the trader | `start` | | Starts the trader
| `stop` | | Stops the trader | `stop` | | Stops the trader
| `stopbuy` | | Stops the trader from opening new trades. Gracefully closes open trades according to their rules. | `stopbuy` | | Stops the trader from opening new trades. Gracefully closes open trades according to their rules.
| `reload_conf` | | Reloads the configuration file | `reload_config` | | Reloads the configuration file
| `show_config` | | Shows part of the current configuration with relevant settings to operation | `show_config` | | Shows part of the current configuration with relevant settings to operation
| `status` | | Lists all open trades | `status` | | Lists all open trades
| `count` | | Displays number of trades used and available | `count` | | Displays number of trades used and available
@ -174,7 +174,7 @@ profit
Returns the profit summary Returns the profit summary
:returns: json object :returns: json object
reload_conf reload_config
Reload configuration Reload configuration
:returns: json object :returns: json object
@ -196,7 +196,7 @@ stop
stopbuy stopbuy
Stop buying (but handle sells gracefully). Stop buying (but handle sells gracefully).
use reload_conf to reset use reload_config to reset
:returns: json object :returns: json object
version version

View File

@ -101,7 +101,7 @@ Simplified example:
## Changing stoploss on open trades ## Changing stoploss on open trades
A stoploss on an open trade can be changed by changing the value in the configuration or strategy and use the `/reload_conf` command (alternatively, completely stopping and restarting the bot also works). A stoploss on an open trade can be changed by changing the value in the configuration or strategy and use the `/reload_config` command (alternatively, completely stopping and restarting the bot also works).
The new stoploss value will be applied to open trades (and corresponding log-messages will be generated). The new stoploss value will be applied to open trades (and corresponding log-messages will be generated).

View File

@ -557,7 +557,7 @@ Locks can also be lifted manually, by calling `self.unlock_pair(pair)`.
To verify if a pair is currently locked, use `self.is_pair_locked(pair)`. To verify if a pair is currently locked, use `self.is_pair_locked(pair)`.
!!! Note !!! Note
Locked pairs are not persisted, so a restart of the bot, or calling `/reload_conf` will reset locked pairs. Locked pairs are not persisted, so a restart of the bot, or calling `/reload_config` will reset locked pairs.
!!! Warning !!! Warning
Locking pairs is not functioning during backtesting. Locking pairs is not functioning during backtesting.

View File

@ -52,7 +52,7 @@ official commands. You can ask at any moment for help with `/help`.
| `/start` | | Starts the trader | `/start` | | Starts the trader
| `/stop` | | Stops the trader | `/stop` | | Stops the trader
| `/stopbuy` | | Stops the trader from opening new trades. Gracefully closes open trades according to their rules. | `/stopbuy` | | Stops the trader from opening new trades. Gracefully closes open trades according to their rules.
| `/reload_conf` | | Reloads the configuration file | `/reload_config` | | Reloads the configuration file
| `/show_config` | | Shows part of the current configuration with relevant settings to operation | `/show_config` | | Shows part of the current configuration with relevant settings to operation
| `/status` | | Lists all open trades | `/status` | | Lists all open trades
| `/status table` | | List all open trades in a table format. Pending buy orders are marked with an asterisk (*) Pending sell orders are marked with a double asterisk (**) | `/status table` | | List all open trades in a table format. Pending buy orders are marked with an asterisk (*) Pending sell orders are marked with a double asterisk (**)
@ -85,14 +85,14 @@ Below, example of Telegram message you will receive for each command.
### /stopbuy ### /stopbuy
> **status:** `Setting max_open_trades to 0. Run /reload_conf to reset.` > **status:** `Setting max_open_trades to 0. Run /reload_config to reset.`
Prevents the bot from opening new trades by temporarily setting "max_open_trades" to 0. Open trades will be handled via their regular rules (ROI / Sell-signal, stoploss, ...). Prevents the bot from opening new trades by temporarily setting "max_open_trades" to 0. Open trades will be handled via their regular rules (ROI / Sell-signal, stoploss, ...).
After this, give the bot time to close off open trades (can be checked via `/status table`). After this, give the bot time to close off open trades (can be checked via `/status table`).
Once all positions are sold, run `/stop` to completely stop the bot. Once all positions are sold, run `/stop` to completely stop the bot.
`/reload_conf` resets "max_open_trades" to the value set in the configuration and resets this command. `/reload_config` resets "max_open_trades" to the value set in the configuration and resets this command.
!!! Warning !!! Warning
The stop-buy signal is ONLY active while the bot is running, and is not persisted anyway, so restarting the bot will cause this to reset. The stop-buy signal is ONLY active while the bot is running, and is not persisted anyway, so restarting the bot will cause this to reset.
@ -209,7 +209,7 @@ Shows the current whitelist
Shows the current blacklist. Shows the current blacklist.
If Pair is set, then this pair will be added to the pairlist. If Pair is set, then this pair will be added to the pairlist.
Also supports multiple pairs, seperated by a space. Also supports multiple pairs, seperated by a space.
Use `/reload_conf` to reset the blacklist. Use `/reload_config` to reset the blacklist.
> Using blacklist `StaticPairList` with 2 pairs > Using blacklist `StaticPairList` with 2 pairs
>`DODGE/BTC`, `HOT/BTC`. >`DODGE/BTC`, `HOT/BTC`.

View File

@ -172,8 +172,8 @@ class ApiServer(RPC):
self.app.add_url_rule(f'{BASE_URI}/stop', 'stop', view_func=self._stop, methods=['POST']) self.app.add_url_rule(f'{BASE_URI}/stop', 'stop', view_func=self._stop, methods=['POST'])
self.app.add_url_rule(f'{BASE_URI}/stopbuy', 'stopbuy', self.app.add_url_rule(f'{BASE_URI}/stopbuy', 'stopbuy',
view_func=self._stopbuy, methods=['POST']) view_func=self._stopbuy, methods=['POST'])
self.app.add_url_rule(f'{BASE_URI}/reload_conf', 'reload_conf', self.app.add_url_rule(f'{BASE_URI}/reload_config', 'reload_config',
view_func=self._reload_conf, methods=['POST']) view_func=self._reload_config, methods=['POST'])
# Info commands # Info commands
self.app.add_url_rule(f'{BASE_URI}/balance', 'balance', self.app.add_url_rule(f'{BASE_URI}/balance', 'balance',
view_func=self._balance, methods=['GET']) view_func=self._balance, methods=['GET'])
@ -304,12 +304,12 @@ class ApiServer(RPC):
@require_login @require_login
@rpc_catch_errors @rpc_catch_errors
def _reload_conf(self): def _reload_config(self):
""" """
Handler for /reload_conf. Handler for /reload_config.
Triggers a config file reload Triggers a config file reload
""" """
msg = self._rpc_reload_conf() msg = self._rpc_reload_config()
return self.rest_dump(msg) return self.rest_dump(msg)
@require_login @require_login

View File

@ -418,9 +418,9 @@ class RPC:
return {'status': 'already stopped'} return {'status': 'already stopped'}
def _rpc_reload_conf(self) -> Dict[str, str]: def _rpc_reload_config(self) -> Dict[str, str]:
""" Handler for reload_conf. """ """ Handler for reload_config. """
self._freqtrade.state = State.RELOAD_CONF self._freqtrade.state = State.RELOAD_CONFIG
return {'status': 'reloading config ...'} return {'status': 'reloading config ...'}
def _rpc_stopbuy(self) -> Dict[str, str]: def _rpc_stopbuy(self) -> Dict[str, str]:
@ -431,7 +431,7 @@ class RPC:
# Set 'max_open_trades' to 0 # Set 'max_open_trades' to 0
self._freqtrade.config['max_open_trades'] = 0 self._freqtrade.config['max_open_trades'] = 0
return {'status': 'No more buy will occur from now. Run /reload_conf to reset.'} return {'status': 'No more buy will occur from now. Run /reload_config to reset.'}
def _rpc_forcesell(self, trade_id: str) -> Dict[str, str]: def _rpc_forcesell(self, trade_id: str) -> Dict[str, str]:
""" """

View File

@ -95,8 +95,8 @@ class Telegram(RPC):
CommandHandler('performance', self._performance), CommandHandler('performance', self._performance),
CommandHandler('daily', self._daily), CommandHandler('daily', self._daily),
CommandHandler('count', self._count), CommandHandler('count', self._count),
CommandHandler('reload_conf', self._reload_conf), CommandHandler(['reload_config', 'reload_conf'], self._reload_config),
CommandHandler('show_config', self._show_config), CommandHandler(['show_config', 'show_conf'], self._show_config),
CommandHandler('stopbuy', self._stopbuy), CommandHandler('stopbuy', self._stopbuy),
CommandHandler('whitelist', self._whitelist), CommandHandler('whitelist', self._whitelist),
CommandHandler('blacklist', self._blacklist), CommandHandler('blacklist', self._blacklist),
@ -436,15 +436,15 @@ class Telegram(RPC):
self._send_msg('Status: `{status}`'.format(**msg)) self._send_msg('Status: `{status}`'.format(**msg))
@authorized_only @authorized_only
def _reload_conf(self, update: Update, context: CallbackContext) -> None: def _reload_config(self, update: Update, context: CallbackContext) -> None:
""" """
Handler for /reload_conf. Handler for /reload_config.
Triggers a config file reload Triggers a config file reload
:param bot: telegram bot :param bot: telegram bot
:param update: message update :param update: message update
:return: None :return: None
""" """
msg = self._rpc_reload_conf() msg = self._rpc_reload_config()
self._send_msg('Status: `{status}`'.format(**msg)) self._send_msg('Status: `{status}`'.format(**msg))
@authorized_only @authorized_only
@ -617,7 +617,7 @@ class Telegram(RPC):
"\n" "\n"
"*/balance:* `Show account balance per currency`\n" "*/balance:* `Show account balance per currency`\n"
"*/stopbuy:* `Stops buying, but handles open trades gracefully` \n" "*/stopbuy:* `Stops buying, but handles open trades gracefully` \n"
"*/reload_conf:* `Reload configuration file` \n" "*/reload_config:* `Reload configuration file` \n"
"*/show_config:* `Show running configuration` \n" "*/show_config:* `Show running configuration` \n"
"*/whitelist:* `Show current whitelist` \n" "*/whitelist:* `Show current whitelist` \n"
"*/blacklist [pair]:* `Show current blacklist, or adds one or more pairs " "*/blacklist [pair]:* `Show current blacklist, or adds one or more pairs "

View File

@ -12,7 +12,7 @@ class State(Enum):
""" """
RUNNING = 1 RUNNING = 1
STOPPED = 2 STOPPED = 2
RELOAD_CONF = 3 RELOAD_CONFIG = 3
def __str__(self): def __str__(self):
return f"{self.name.lower()}" return f"{self.name.lower()}"

View File

@ -71,7 +71,7 @@ class Worker:
state = None state = None
while True: while True:
state = self._worker(old_state=state) state = self._worker(old_state=state)
if state == State.RELOAD_CONF: if state == State.RELOAD_CONFIG:
self._reconfigure() self._reconfigure()
def _worker(self, old_state: Optional[State]) -> State: def _worker(self, old_state: Optional[State]) -> State:

View File

@ -80,18 +80,18 @@ class FtRestClient():
return self._post("stop") return self._post("stop")
def stopbuy(self): def stopbuy(self):
"""Stop buying (but handle sells gracefully). Use `reload_conf` to reset. """Stop buying (but handle sells gracefully). Use `reload_config` to reset.
:return: json object :return: json object
""" """
return self._post("stopbuy") return self._post("stopbuy")
def reload_conf(self): def reload_config(self):
"""Reload configuration. """Reload configuration.
:return: json object :return: json object
""" """
return self._post("reload_conf") return self._post("reload_config")
def balance(self): def balance(self):
"""Get the account balance. """Get the account balance.

View File

@ -592,7 +592,7 @@ def test_rpc_stopbuy(mocker, default_conf) -> None:
assert freqtradebot.config['max_open_trades'] != 0 assert freqtradebot.config['max_open_trades'] != 0
result = rpc._rpc_stopbuy() result = rpc._rpc_stopbuy()
assert {'status': 'No more buy will occur from now. Run /reload_conf to reset.'} == result assert {'status': 'No more buy will occur from now. Run /reload_config to reset.'} == result
assert freqtradebot.config['max_open_trades'] == 0 assert freqtradebot.config['max_open_trades'] == 0

View File

@ -251,10 +251,10 @@ def test_api_cleanup(default_conf, mocker, caplog):
def test_api_reloadconf(botclient): def test_api_reloadconf(botclient):
ftbot, client = botclient ftbot, client = botclient
rc = client_post(client, f"{BASE_URI}/reload_conf") rc = client_post(client, f"{BASE_URI}/reload_config")
assert_response(rc) assert_response(rc)
assert rc.json == {'status': 'reloading config ...'} assert rc.json == {'status': 'reloading config ...'}
assert ftbot.state == State.RELOAD_CONF assert ftbot.state == State.RELOAD_CONFIG
def test_api_stopbuy(botclient): def test_api_stopbuy(botclient):
@ -263,7 +263,7 @@ def test_api_stopbuy(botclient):
rc = client_post(client, f"{BASE_URI}/stopbuy") rc = client_post(client, f"{BASE_URI}/stopbuy")
assert_response(rc) assert_response(rc)
assert rc.json == {'status': 'No more buy will occur from now. Run /reload_conf to reset.'} assert rc.json == {'status': 'No more buy will occur from now. Run /reload_config to reset.'}
assert ftbot.config['max_open_trades'] == 0 assert ftbot.config['max_open_trades'] == 0

View File

@ -73,8 +73,9 @@ def test_init(default_conf, mocker, caplog) -> None:
message_str = ("rpc.telegram is listening for following commands: [['status'], ['profit'], " message_str = ("rpc.telegram is listening for following commands: [['status'], ['profit'], "
"['balance'], ['start'], ['stop'], ['forcesell'], ['forcebuy'], " "['balance'], ['start'], ['stop'], ['forcesell'], ['forcebuy'], "
"['performance'], ['daily'], ['count'], ['reload_conf'], ['show_config'], " "['performance'], ['daily'], ['count'], ['reload_config', 'reload_conf'], "
"['stopbuy'], ['whitelist'], ['blacklist'], ['edge'], ['help'], ['version']]") "['show_config', 'show_conf'], ['stopbuy'], ['whitelist'], ['blacklist'], "
"['edge'], ['help'], ['version']]")
assert log_has(message_str, caplog) assert log_has(message_str, caplog)
@ -666,11 +667,11 @@ def test_stopbuy_handle(default_conf, update, mocker) -> None:
telegram._stopbuy(update=update, context=MagicMock()) telegram._stopbuy(update=update, context=MagicMock())
assert freqtradebot.config['max_open_trades'] == 0 assert freqtradebot.config['max_open_trades'] == 0
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'No more buy will occur from now. Run /reload_conf to reset.' \ assert 'No more buy will occur from now. Run /reload_config to reset.' \
in msg_mock.call_args_list[0][0][0] in msg_mock.call_args_list[0][0][0]
def test_reload_conf_handle(default_conf, update, mocker) -> None: def test_reload_config_handle(default_conf, update, mocker) -> None:
msg_mock = MagicMock() msg_mock = MagicMock()
mocker.patch.multiple( mocker.patch.multiple(
'freqtrade.rpc.telegram.Telegram', 'freqtrade.rpc.telegram.Telegram',
@ -683,8 +684,8 @@ def test_reload_conf_handle(default_conf, update, mocker) -> None:
freqtradebot.state = State.RUNNING freqtradebot.state = State.RUNNING
assert freqtradebot.state == State.RUNNING assert freqtradebot.state == State.RUNNING
telegram._reload_conf(update=update, context=MagicMock()) telegram._reload_config(update=update, context=MagicMock())
assert freqtradebot.state == State.RELOAD_CONF assert freqtradebot.state == State.RELOAD_CONFIG
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'reloading config' in msg_mock.call_args_list[0][0][0] assert 'reloading config' in msg_mock.call_args_list[0][0][0]

View File

@ -141,12 +141,12 @@ def test_main_operational_exception1(mocker, default_conf, caplog) -> None:
assert log_has_re(r'SIGINT.*', caplog) assert log_has_re(r'SIGINT.*', caplog)
def test_main_reload_conf(mocker, default_conf, caplog) -> None: def test_main_reload_config(mocker, default_conf, caplog) -> None:
patch_exchange(mocker) patch_exchange(mocker)
mocker.patch('freqtrade.freqtradebot.FreqtradeBot.cleanup', MagicMock()) mocker.patch('freqtrade.freqtradebot.FreqtradeBot.cleanup', MagicMock())
# Simulate Running, reload, running workflow # Simulate Running, reload, running workflow
worker_mock = MagicMock(side_effect=[State.RUNNING, worker_mock = MagicMock(side_effect=[State.RUNNING,
State.RELOAD_CONF, State.RELOAD_CONFIG,
State.RUNNING, State.RUNNING,
OperationalException("Oh snap!")]) OperationalException("Oh snap!")])
mocker.patch('freqtrade.worker.Worker._worker', worker_mock) mocker.patch('freqtrade.worker.Worker._worker', worker_mock)