Merge pull request #8035 from freqtrade/enable_plotconfig_wsmode
Enable plotconfig wsmode
This commit is contained in:
commit
cd2a41e76e
@ -8,7 +8,7 @@ repos:
|
|||||||
# stages: [push]
|
# stages: [push]
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
rev: "v0.942"
|
rev: "v0.991"
|
||||||
hooks:
|
hooks:
|
||||||
- id: mypy
|
- id: mypy
|
||||||
exclude: build_helpers
|
exclude: build_helpers
|
||||||
|
@ -40,7 +40,8 @@ logger = logging.getLogger(__name__)
|
|||||||
# 2.20: Add websocket endpoints
|
# 2.20: Add websocket endpoints
|
||||||
# 2.21: Add new_candle messagetype
|
# 2.21: Add new_candle messagetype
|
||||||
# 2.22: Add FreqAI to backtesting
|
# 2.22: Add FreqAI to backtesting
|
||||||
API_VERSION = 2.22
|
# 2.23: Allow plot config request in webserver mode
|
||||||
|
API_VERSION = 2.23
|
||||||
|
|
||||||
# Public API, requires no auth.
|
# Public API, requires no auth.
|
||||||
router_public = APIRouter()
|
router_public = APIRouter()
|
||||||
@ -248,8 +249,18 @@ def pair_history(pair: str, timeframe: str, timerange: str, strategy: str,
|
|||||||
|
|
||||||
|
|
||||||
@router.get('/plot_config', response_model=PlotConfig, tags=['candle data'])
|
@router.get('/plot_config', response_model=PlotConfig, tags=['candle data'])
|
||||||
def plot_config(rpc: RPC = Depends(get_rpc)):
|
def plot_config(strategy: Optional[str] = None, config=Depends(get_config),
|
||||||
|
rpc: Optional[RPC] = Depends(get_rpc_optional)):
|
||||||
|
if not strategy:
|
||||||
|
if not rpc:
|
||||||
|
raise RPCException("Strategy is mandatory in webserver mode.")
|
||||||
return PlotConfig.parse_obj(rpc._rpc_plot_config())
|
return PlotConfig.parse_obj(rpc._rpc_plot_config())
|
||||||
|
else:
|
||||||
|
config1 = deepcopy(config)
|
||||||
|
config1.update({
|
||||||
|
'strategy': strategy
|
||||||
|
})
|
||||||
|
return PlotConfig.parse_obj(RPC._rpc_plot_config_with_strategy(config1))
|
||||||
|
|
||||||
|
|
||||||
@router.get('/strategies', response_model=StrategyListResponse, tags=['strategy'])
|
@router.get('/strategies', response_model=StrategyListResponse, tags=['strategy'])
|
||||||
|
@ -1127,12 +1127,12 @@ class RPC:
|
|||||||
return self._freqtrade.active_pair_whitelist
|
return self._freqtrade.active_pair_whitelist
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _rpc_analysed_history_full(config, pair: str, timeframe: str,
|
def _rpc_analysed_history_full(config: Config, pair: str, timeframe: str,
|
||||||
timerange: str, exchange) -> Dict[str, Any]:
|
timerange: str, exchange) -> Dict[str, Any]:
|
||||||
timerange_parsed = TimeRange.parse_timerange(timerange)
|
timerange_parsed = TimeRange.parse_timerange(timerange)
|
||||||
|
|
||||||
_data = load_data(
|
_data = load_data(
|
||||||
datadir=config.get("datadir"),
|
datadir=config["datadir"],
|
||||||
pairs=[pair],
|
pairs=[pair],
|
||||||
timeframe=timeframe,
|
timeframe=timeframe,
|
||||||
timerange=timerange_parsed,
|
timerange=timerange_parsed,
|
||||||
@ -1157,6 +1157,16 @@ class RPC:
|
|||||||
self._freqtrade.strategy.plot_config['subplots'] = {}
|
self._freqtrade.strategy.plot_config['subplots'] = {}
|
||||||
return self._freqtrade.strategy.plot_config
|
return self._freqtrade.strategy.plot_config
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _rpc_plot_config_with_strategy(config: Config) -> Dict[str, Any]:
|
||||||
|
|
||||||
|
from freqtrade.resolvers.strategy_resolver import StrategyResolver
|
||||||
|
strategy = StrategyResolver.load_strategy(config)
|
||||||
|
|
||||||
|
if (strategy.plot_config and 'subplots' not in strategy.plot_config):
|
||||||
|
strategy.plot_config['subplots'] = {}
|
||||||
|
return strategy.plot_config
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _rpc_sysinfo() -> Dict[str, Any]:
|
def _rpc_sysinfo() -> Dict[str, Any]:
|
||||||
return {
|
return {
|
||||||
|
@ -1417,7 +1417,7 @@ def test_api_pair_history(botclient, ohlcv_history):
|
|||||||
"No data for UNITTEST/BTC, 5m in 20200111-20200112 found.")
|
"No data for UNITTEST/BTC, 5m in 20200111-20200112 found.")
|
||||||
|
|
||||||
|
|
||||||
def test_api_plot_config(botclient):
|
def test_api_plot_config(botclient, mocker):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
|
|
||||||
rc = client_get(client, f"{BASE_URI}/plot_config")
|
rc = client_get(client, f"{BASE_URI}/plot_config")
|
||||||
@ -1441,6 +1441,21 @@ def test_api_plot_config(botclient):
|
|||||||
assert isinstance(rc.json()['main_plot'], dict)
|
assert isinstance(rc.json()['main_plot'], dict)
|
||||||
assert isinstance(rc.json()['subplots'], dict)
|
assert isinstance(rc.json()['subplots'], dict)
|
||||||
|
|
||||||
|
rc = client_get(client, f"{BASE_URI}/plot_config?strategy=freqai_test_classifier")
|
||||||
|
assert_response(rc)
|
||||||
|
res = rc.json()
|
||||||
|
assert 'target_roi' in res['subplots']
|
||||||
|
assert 'do_predict' in res['subplots']
|
||||||
|
|
||||||
|
rc = client_get(client, f"{BASE_URI}/plot_config?strategy=HyperoptableStrategy")
|
||||||
|
assert_response(rc)
|
||||||
|
assert rc.json()['subplots'] == {}
|
||||||
|
|
||||||
|
mocker.patch('freqtrade.rpc.api_server.api_v1.get_rpc_optional', return_value=None)
|
||||||
|
|
||||||
|
rc = client_get(client, f"{BASE_URI}/plot_config")
|
||||||
|
assert_response(rc)
|
||||||
|
|
||||||
|
|
||||||
def test_api_strategies(botclient, tmpdir):
|
def test_api_strategies(botclient, tmpdir):
|
||||||
ftbot, client = botclient
|
ftbot, client = botclient
|
||||||
|
@ -34,6 +34,11 @@ class HyperoptableStrategy(StrategyTestV3):
|
|||||||
protection_enabled = BooleanParameter(default=True)
|
protection_enabled = BooleanParameter(default=True)
|
||||||
protection_cooldown_lookback = IntParameter([0, 50], default=30)
|
protection_cooldown_lookback = IntParameter([0, 50], default=30)
|
||||||
|
|
||||||
|
# Invalid plot config ...
|
||||||
|
plot_config = {
|
||||||
|
"main_plot": {},
|
||||||
|
}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def protections(self):
|
def protections(self):
|
||||||
prot = []
|
prot = []
|
||||||
|
Loading…
Reference in New Issue
Block a user