From d0467b30ba8055ab347ab82cd899b11307e9a59f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 4 Dec 2021 14:49:45 +0100 Subject: [PATCH] Add strategy_version to API response --- freqtrade/rpc/api_server/api_schemas.py | 1 + freqtrade/rpc/api_server/api_v1.py | 4 +++- freqtrade/rpc/rpc.py | 4 +++- freqtrade/strategy/interface.py | 2 +- tests/rpc/test_rpc_apiserver.py | 1 + 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index f9389d810..d669600a2 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -145,6 +145,7 @@ class OrderTypes(BaseModel): class ShowConfig(BaseModel): version: str + strategy_version: Optional[str] api_version: float dry_run: bool stake_currency: str diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index 65b6941e2..721d5dbc0 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -121,9 +121,11 @@ def edge(rpc: RPC = Depends(get_rpc)): @router.get('/show_config', response_model=ShowConfig, tags=['info']) def show_config(rpc: Optional[RPC] = Depends(get_rpc_optional), config=Depends(get_config)): state = '' + strategy_version = None if rpc: state = rpc._freqtrade.state - resp = RPC._rpc_show_config(config, state) + strategy_version = rpc._freqtrade.strategy.version() + resp = RPC._rpc_show_config(config, state, strategy_version) resp['api_version'] = API_VERSION return resp diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index c21890b7d..b3728d67a 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -98,7 +98,8 @@ class RPC: self._fiat_converter = CryptoToFiatConverter() @staticmethod - def _rpc_show_config(config, botstate: Union[State, str]) -> Dict[str, Any]: + def _rpc_show_config(config, botstate: Union[State, str], + strategy_version: Optional[str] = None) -> Dict[str, Any]: """ Return a dict of config options. Explicitly does NOT return the full config to avoid leakage of sensitive @@ -106,6 +107,7 @@ class RPC: """ val = { 'version': __version__, + 'strategy_version': strategy_version, 'dry_run': config['dry_run'], 'stake_currency': config['stake_currency'], 'stake_currency_decimals': decimals_per_coin(config['stake_currency']), diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 088777654..05469317b 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -394,7 +394,7 @@ class IStrategy(ABC, HyperStrategyMixin): """ return [] - def version(self) -> str: + def version(self) -> Optional[str]: """ Returns version of the strategy. """ diff --git a/tests/rpc/test_rpc_apiserver.py b/tests/rpc/test_rpc_apiserver.py index 76372df55..883a33e38 100644 --- a/tests/rpc/test_rpc_apiserver.py +++ b/tests/rpc/test_rpc_apiserver.py @@ -533,6 +533,7 @@ def test_api_show_config(botclient): assert rc.json()['timeframe_min'] == 5 assert rc.json()['state'] == 'running' assert rc.json()['bot_name'] == 'freqtrade' + assert rc.json()['strategy_version'] is None assert not rc.json()['trailing_stop'] assert 'bid_strategy' in rc.json() assert 'ask_strategy' in rc.json()