feat: add hyperopt-loss api endpoint

This commit is contained in:
Matthias 2024-10-22 06:36:21 +02:00
parent faac205464
commit 0bf30aaa6b
2 changed files with 34 additions and 1 deletions

View File

@ -456,6 +456,15 @@ class ExchangeListResponse(BaseModel):
exchanges: list[ValidExchangesType]
class HyperoptLoss(BaseModel):
name: str
description: str
class HyperoptLossListResponse(BaseModel):
loss_functions: list[HyperoptLoss]
class PairListResponse(BaseModel):
name: str
description: str

View File

@ -27,6 +27,7 @@ from freqtrade.rpc.api_server.api_schemas import (
ForceExitPayload,
FreqAIModelListResponse,
Health,
HyperoptLossListResponse,
Locks,
LocksPayload,
Logs,
@ -82,7 +83,8 @@ logger = logging.getLogger(__name__)
# 2.33: Additional weekly/monthly metrics
# 2.34: new entries/exits/mix_tags endpoints
# 2.35: pair_candles and pair_history endpoints as Post variant
API_VERSION = 2.35
# 2.40: Add hyperopt-loss endpoint
API_VERSION = 2.40
# Public API, requires no auth.
router_public = APIRouter()
@ -456,6 +458,28 @@ def list_exchanges(config=Depends(get_config)):
}
@router.get("/hyperopt-loss", response_model=HyperoptLossListResponse, tags=["strategy"])
def list_hyperoptloss(
config=Depends(get_config),
):
import textwrap
from freqtrade.resolvers.hyperopt_resolver import HyperOptLossResolver
loss_functions = HyperOptLossResolver.search_all_objects(config, False)
loss_functions = sorted(loss_functions, key=lambda x: x["name"])
return {
"loss_functions": [
{
"name": x["name"],
"description": textwrap.dedent((x["class"].__doc__ or "").strip()),
}
for x in loss_functions
]
}
@router.get("/freqaimodels", response_model=FreqAIModelListResponse, tags=["freqai"])
def list_freqaimodels(config=Depends(get_config)):
from freqtrade.resolvers.freqaimodel_resolver import FreqaiModelResolver