feat: add strategy-parameters to /strategy endpoint

This commit is contained in:
Matthias
2026-02-06 20:33:07 +01:00
parent 600b6a7d23
commit 5ab8338c3e
2 changed files with 56 additions and 4 deletions

View File

@@ -1,7 +1,7 @@
from datetime import date, datetime
from typing import Any
from typing import Annotated, Any, Literal
from pydantic import AwareDatetime, BaseModel, RootModel, SerializeAsAny, model_validator
from pydantic import AwareDatetime, BaseModel, Field, RootModel, SerializeAsAny, model_validator
from freqtrade.constants import DL_DATA_TIMEFRAMES, IntOrInf
from freqtrade.enums import MarginMode, OrderTypeValues, SignalDirection, TradingMode
@@ -527,10 +527,60 @@ class FreqAIModelListResponse(BaseModel):
freqaimodels: list[str]
class __StrategyParameter(BaseModel):
param_type: str
name: str
space: str
load: bool
optimize: bool
class __IntParameter(__StrategyParameter):
param_type: Literal["IntParameter"]
value: int
low: int
high: int
class __RealParameter(__StrategyParameter):
param_type: Literal["RealParameter"]
value: float
low: float
high: float
class __DecimalParameter(__RealParameter):
param_type: Literal["DecimalParameter"]
decimals: int
class __BooleanParameter(__StrategyParameter):
param_type: Literal["BooleanParameter"]
value: Any
opt_range: list[Any]
class __CategoricalParameter(__StrategyParameter):
param_type: Literal["CategoricalParameter"]
value: Any
opt_range: list[Any]
AllParameters = Annotated[
__BooleanParameter
| __CategoricalParameter
| __DecimalParameter
| __IntParameter
| __RealParameter,
Field(discriminator="param_type"),
]
class StrategyResponse(BaseModel):
strategy: str
code: str
timeframe: str | None
params: list[AllParameters] | None
code: str
class AvailablePairs(BaseModel):

View File

@@ -48,14 +48,16 @@ def get_strategy(strategy: str, config=Depends(get_config)):
strategy_obj = StrategyResolver._load_strategy(
strategy, config_, extra_dir=config_.get("strategy_path")
)
strategy_obj.ft_load_hyper_params()
except OperationalException:
raise HTTPException(status_code=404, detail="Strategy not found")
except Exception as e:
raise HTTPException(status_code=502, detail=str(e))
return {
"strategy": strategy_obj.get_strategy_name(),
"code": strategy_obj.__source__,
"timeframe": getattr(strategy_obj, "timeframe", None),
"code": strategy_obj.__source__,
"params": [p for _, p in strategy_obj.enumerate_parameters()],
}