diff --git a/freqtrade/rpc/api_server.py b/freqtrade/rpc/api_server.py index 3b59c9592..0426eb598 100644 --- a/freqtrade/rpc/api_server.py +++ b/freqtrade/rpc/api_server.py @@ -169,6 +169,8 @@ class ApiServer(RPC): view_func=self._status, methods=['GET']) self.app.add_url_rule(f'{BASE_URI}/version', 'version', view_func=self._version, methods=['GET']) + self.app.add_url_rule(f'{BASE_URI}/show_config', 'show_config', + view_func=self._show_config, methods=['GET']) self.app.add_url_rule(f'{BASE_URI}/ping', 'ping', view_func=self._ping, methods=['GET']) @@ -241,6 +243,14 @@ class ApiServer(RPC): """ return self.rest_dump({"version": __version__}) + @require_login + @rpc_catch_errors + def _show_config(self): + """ + Prints the bot's version + """ + return self.rest_dump(self._rpc_show_config()) + @require_login @rpc_catch_errors def _reload_conf(self): diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 5ab92cf33..c78951a6d 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -80,6 +80,26 @@ class RPC: def send_msg(self, msg: Dict[str, str]) -> None: """ Sends a message to all registered rpc modules """ + def _rpc_show_config(self) -> Dict: + """ + Return a dict of config options. + Explicitly does NOT return the full config to avoid leakage of sensitive + information via rpc. + """ + config = self._freqtrade.config + val = { + 'dry_run': config.get('dry_run', False), + 'stake_currency': config['stake_currency'], + 'stake_amount': config['stake_amount'], + 'minimal_roi': config['minimal_roi'].copy(), + 'stoploss': config['stoploss'], + 'trailing_stop': config['trailing_stop'], + 'ticker_interval': config['ticker_interval'], + 'exchange': config['exchange']['name'], + 'strategy': config['strategy'], + } + return val + def _rpc_trade_status(self) -> List[Dict[str, Any]]: """ Below follows the RPC backend it is prefixed with rpc_ to raise awareness that it is diff --git a/scripts/rest_client.py b/scripts/rest_client.py index a46b3ebfb..7408acab8 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -147,6 +147,13 @@ class FtRestClient(): """ return self._get("version") + def show_config(self): + """ + Returns part of the configuration, relevant for trading operations. + :return: json object containing the version + """ + return self._get("show_config") + def whitelist(self): """ Show the current whitelist diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 6e65cf934..d1ebe961b 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -284,6 +284,18 @@ def test_api_count(botclient, mocker, ticker, fee, markets): assert rc.json["max"] == 1.0 +def test_api_show_config(botclient, mocker): + ftbot, client = botclient + patch_get_signal(ftbot, (True, False)) + + rc = client_get(client, f"{BASE_URI}/show_config") + assert_response(rc) + assert 'dry_run' in rc.json + assert rc.json['exchange'] == 'bittrex' + assert rc.json['ticker_interval'] == '5m' + assert not rc.json['trailing_stop'] + + def test_api_daily(botclient, mocker, ticker, fee, markets): ftbot, client = botclient patch_get_signal(ftbot, (True, False))