Add 404 when strategy is not found

This commit is contained in:
Matthias 2020-09-17 07:53:22 +02:00
parent becccca3d1
commit b38f68b3b0
4 changed files with 36 additions and 1 deletions

View File

@ -133,6 +133,7 @@ python3 scripts/rest_client.py --config rest_config.json <command> [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 <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.

View File

@ -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(),

View File

@ -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.

View File

@ -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