From 347295ecafcce2f7e341754ad0b030b0b5ec0ea8 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 15:18:02 +0100 Subject: [PATCH] feat: Expand pair_candles with plot_annotations call --- freqtrade/rpc/api_server/api_schemas.py | 3 ++- freqtrade/rpc/rpc.py | 16 ++++++++++++++-- freqtrade/strategy/__init__.py | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/freqtrade/rpc/api_server/api_schemas.py b/freqtrade/rpc/api_server/api_schemas.py index 97770ba13..02c19ef71 100644 --- a/freqtrade/rpc/api_server/api_schemas.py +++ b/freqtrade/rpc/api_server/api_schemas.py @@ -5,7 +5,7 @@ from pydantic import AwareDatetime, BaseModel, RootModel, SerializeAsAny, model_ from freqtrade.constants import DL_DATA_TIMEFRAMES, IntOrInf from freqtrade.enums import MarginMode, OrderTypeValues, SignalDirection, TradingMode -from freqtrade.ft_types import ValidExchangesType +from freqtrade.ft_types import MarkArea, ValidExchangesType from freqtrade.rpc.api_server.webserver_bgwork import ProgressTask @@ -537,6 +537,7 @@ class PairHistory(BaseModel): columns: list[str] all_columns: list[str] = [] data: SerializeAsAny[list[Any]] + mark_areas: list[MarkArea] | None = None length: int buy_signals: int sell_signals: int diff --git a/freqtrade/rpc/rpc.py b/freqtrade/rpc/rpc.py index ce19299f9..a3181e6c1 100644 --- a/freqtrade/rpc/rpc.py +++ b/freqtrade/rpc/rpc.py @@ -1299,7 +1299,8 @@ class RPC: timeframe: str, dataframe: DataFrame, last_analyzed: datetime, - selected_cols: list[str] | None, + selected_cols: list[str], + mark_areas: list[dict[str, Any]] = None, ) -> dict[str, Any]: has_content = len(dataframe) != 0 dataframe_columns = list(dataframe.columns) @@ -1355,6 +1356,7 @@ class RPC: "data_start_ts": 0, "data_stop": "", "data_stop_ts": 0, + "mark_areas": mark_areas, } if has_content: res.update( @@ -1373,8 +1375,16 @@ class RPC: """Analyzed dataframe in Dict form""" _data, last_analyzed = self.__rpc_analysed_dataframe_raw(pair, timeframe, limit) + mark_areas = self._freqtrade.strategy.ft_plot_annotations(pair=pair, dataframe=_data) + return RPC._convert_dataframe_to_dict( - self._freqtrade.config["strategy"], pair, timeframe, _data, last_analyzed, selected_cols + self._freqtrade.config["strategy"], + pair, + timeframe, + _data, + last_analyzed, + selected_cols, + mark_areas, ) def __rpc_analysed_dataframe_raw( @@ -1458,6 +1468,7 @@ class RPC: df_analyzed = strategy.analyze_ticker(_data[pair], {"pair": pair}) df_analyzed = trim_dataframe(df_analyzed, timerange_parsed, startup_candles=startup_candles) + mark_areas = strategy.ft_plot_annotations(pair=pair, dataframe=df_analyzed) return RPC._convert_dataframe_to_dict( strategy.get_strategy_name(), @@ -1466,6 +1477,7 @@ class RPC: df_analyzed.copy(), dt_now(), selected_cols, + mark_areas, ) def _rpc_plot_config(self) -> dict[str, Any]: diff --git a/freqtrade/strategy/__init__.py b/freqtrade/strategy/__init__.py index e99473b4e..de7e49a94 100644 --- a/freqtrade/strategy/__init__.py +++ b/freqtrade/strategy/__init__.py @@ -6,6 +6,7 @@ from freqtrade.exchange import ( timeframe_to_prev_date, timeframe_to_seconds, ) +from freqtrade.ft_types import MarkArea from freqtrade.persistence import Order, PairLocks, Trade from freqtrade.strategy.informative_decorator import informative from freqtrade.strategy.interface import IStrategy @@ -44,4 +45,5 @@ __all__ = [ "merge_informative_pair", "stoploss_from_absolute", "stoploss_from_open", + "MarkArea", ]