diff --git a/docs/rest-api.md b/docs/rest-api.md index b832b8b0c..44f0b07cf 100644 --- a/docs/rest-api.md +++ b/docs/rest-api.md @@ -133,6 +133,7 @@ python3 scripts/rest_client.py --config rest_config.json [optional par | `pair_history` | Returns an analyzed dataframe for a given timerange, analyzed by a given strategy. **Alpha** | `plot_config` | Get plot config from the strategy (or nothing if not configured). **Alpha** | `strategies` | List strategies in strategy directory. **Alpha** +| `strategy ` | Get specific Strategy content. **Alpha** | `available_pairs` | List available backtest data. **Alpha** | `version` | Show version @@ -239,6 +240,11 @@ stopbuy strategies Lists available strategies +strategy + Get strategy details + + :param strategy: Strategy class name + trades Return trades history. diff --git a/freqtrade/rpc/api_server.py b/freqtrade/rpc/api_server.py index 21c0e5629..489b8760a 100644 --- a/freqtrade/rpc/api_server.py +++ b/freqtrade/rpc/api_server.py @@ -1,3 +1,4 @@ +from freqtrade.exceptions import OperationalException import logging import threading from copy import deepcopy @@ -599,7 +600,11 @@ class ApiServer(RPC): """ config = deepcopy(self._config) from freqtrade.resolvers.strategy_resolver import StrategyResolver - strategy_obj = StrategyResolver._load_strategy(strategy, config, None) + try: + strategy_obj = StrategyResolver._load_strategy(strategy, config, + extra_dir=config.get('strategy_path')) + except OperationalException: + return self.rest_error("Strategy not found.", 404) return self.rest_dump({ 'strategy': strategy_obj.get_strategy_name(), diff --git a/scripts/rest_client.py b/scripts/rest_client.py index 8889b82c1..46966d447 100755 --- a/scripts/rest_client.py +++ b/scripts/rest_client.py @@ -231,6 +231,14 @@ class FtRestClient(): """ return self._get("strategies") + def strategy(self, strategy): + """Get strategy details + + :param strategy: Strategy class name + :return: json object + """ + return self._get(f"strategy/{strategy}") + def plot_config(self): """Return plot configuration if the strategy defines one. diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 8e1d09b95..4cc947159 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -3,6 +3,7 @@ Unit test file for rpc/api_server.py """ from datetime import datetime +from pathlib import Path from unittest.mock import ANY, MagicMock, PropertyMock import pytest @@ -945,6 +946,21 @@ def test_api_strategies(botclient): assert rc.json == {'strategies': ['DefaultStrategy', 'TestStrategyLegacy']} +def test_api_strategy(botclient): + ftbot, client = botclient + + rc = client_get(client, f"{BASE_URI}/strategy/DefaultStrategy") + + assert_response(rc) + assert rc.json['strategy'] == 'DefaultStrategy' + + data = (Path(__file__).parents[1] / "strategy/strats/default_strategy.py").read_text() + assert rc.json['code'] == data + + rc = client_get(client, f"{BASE_URI}/strategy/NoStrat") + assert_response(rc, 404) + + def test_list_available_pairs(botclient): ftbot, client = botclient