From 1118032c1f9c46b3559e234ae2b46a133b61cb95 Mon Sep 17 00:00:00 2001 From: Matthias Date: Fri, 18 Jul 2025 20:17:11 +0200 Subject: [PATCH] feat: add /profit_all endpoint --- freqtrade/rpc/api_server/api_schemas.py | 6 ++++++ freqtrade/rpc/api_server/api_v1.py | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index 5f89b4a4f..dfc78daf6 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -173,6 +173,12 @@ class Profit(BaseModel): bot_start_date: str +class ProfitAll(BaseModel): + all: Profit + long: Profit | None = None + short: Profit | None = None + + class SellReason(BaseModel): wins: int losses: int diff --git a/freqtrade/rpc/api_server/api_v1.py b/freqtrade/rpc/api_server/api_v1.py index 9c4cf94e6..dc9682b09 100644 --- a/freqtrade/rpc/api_server/api_v1.py +++ b/freqtrade/rpc/api_server/api_v1.py @@ -43,6 +43,7 @@ from freqtrade.rpc.api_server.api_schemas import ( Ping, PlotConfig, Profit, + ProfitAll, ResultMsg, ShowConfig, Stats, @@ -89,7 +90,8 @@ logger = logging.getLogger(__name__) # 2.40: Add hyperopt-loss endpoint # 2.41: Add download-data endpoint # 2.42: Add /pair_history endpoint with live data -API_VERSION = 2.42 +# 2.43: Add /profit_all endpoint +API_VERSION = 2.43 # Public API, requires no auth. router_public = APIRouter() @@ -148,6 +150,24 @@ def profit(rpc: RPC = Depends(get_rpc), config=Depends(get_config)): return rpc._rpc_trade_statistics(config["stake_currency"], config.get("fiat_display_currency")) +@router.get("/profit_all", response_model=ProfitAll, tags=["info"]) +def profit_all(rpc: RPC = Depends(get_rpc), config=Depends(get_config)): + response = { + "all": rpc._rpc_trade_statistics( + config["stake_currency"], config.get("fiat_display_currency") + ), + } + if config.get("trading_mode", TradingMode.SPOT) != TradingMode.SPOT: + response["long"] = rpc._rpc_trade_statistics( + config["stake_currency"], config.get("fiat_display_currency"), direction="long" + ) + response["short"] = rpc._rpc_trade_statistics( + config["stake_currency"], config.get("fiat_display_currency"), direction="short" + ) + + return response + + @router.get("/stats", response_model=Stats, tags=["info"]) def stats(rpc: RPC = Depends(get_rpc)): return rpc._rpc_stats()