From 677078350f1fcdabdccc5162ad99e8f801808db5 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 23 Jun 2020 06:49:53 +0200 Subject: [PATCH] Add plot_config endpoint --- freqtrade/rpc/api_server.py | 10 ++++++++++ freqtrade/rpc/rpc.py | 6 +++++- tests/rpc/test_rpc_apiserver.py | 15 +++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/api_server.py b/freqtrade/rpc/api_server.py index a04452afd..5f84713f2 100644 --- a/freqtrade/rpc/api_server.py +++ b/freqtrade/rpc/api_server.py @@ -214,6 +214,8 @@ class ApiServer(RPC): view_func=self._trades_delete, methods=['DELETE']) self.app.add_url_rule(f'{BASE_URI}/pair_history', 'pair_history', view_func=self._analysed_history, methods=['GET']) + self.app.add_url_rule(f'{BASE_URI}/plot_config', 'plot_config', + view_func=self._plot_config, methods=['GET']) # Combined actions and infos self.app.add_url_rule(f'{BASE_URI}/blacklist', 'blacklist', view_func=self._blacklist, methods=['GET', 'POST']) @@ -521,3 +523,11 @@ class ApiServer(RPC): results = self._rpc_analysed_history(pair, timeframe, limit) return self.rest_dump(results) + + @require_login + @rpc_catch_errors + def _plot_config(self): + """ + Handler for /plot_config. + """ + return self.rest_dump(self._rpc_plot_config()) diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index 4b83a3da6..e8ec099e5 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -654,7 +654,7 @@ class RPC: raise RPCException('Edge is not enabled.') return self._freqtrade.edge.accepted_pairs() - def _rpc_analysed_history(self, pair, timeframe, limit): + def _rpc_analysed_history(self, pair, timeframe, limit) -> Dict[str, Any]: _data, last_analyzed = self._freqtrade.dataprovider.get_analyzed_dataframe(pair, timeframe) if limit: @@ -667,3 +667,7 @@ class RPC: 'length': len(_data), 'last_analyzed': last_analyzed, } + + def _rpc_plot_config(self) -> Dict[str, Any]: + + return self._freqtrade.strategy.plot_config diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index bb13531b5..9c814e1ac 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -835,3 +835,18 @@ def test_api_pair_history(botclient, ohlcv_history): [1511686500000, 8.88e-05, 8.942e-05, 8.88e-05, 8.893e-05, 0.05874751, 8.886500000000001e-05] ]) + + +def test_api_plot_config(botclient): + ftbot, client = botclient + + rc = client_get(client, f"{BASE_URI}/plot_config") + assert_response(rc) + assert rc.json == {} + + ftbot.strategy.plot_config = {'main_plot': {'sma': {}}, + 'subplots': {'RSI': {'rsi': {'color': 'red'}}}} + rc = client_get(client, f"{BASE_URI}/plot_config") + assert_response(rc) + assert rc.json == ftbot.strategy.plot_config + assert isinstance(rc.json['main_plot'], dict)