chore: align interface of get_overall_performance

This commit is contained in:
Matthias
2025-01-26 17:54:11 +01:00
parent 33549a6cef
commit 1aac8dfa59
2 changed files with 7 additions and 5 deletions

View File

@@ -6,7 +6,7 @@ import logging
from collections import defaultdict
from collections.abc import Sequence
from dataclasses import dataclass
from datetime import datetime, timedelta, timezone
from datetime import datetime, timezone
from math import isclose
from typing import Any, ClassVar, Optional, cast
@@ -1914,14 +1914,13 @@ class Trade(ModelBase, LocalTrade):
return total_open_stake_amount or 0
@staticmethod
def get_overall_performance(minutes=None) -> list[dict[str, Any]]:
def get_overall_performance(start_date: datetime | None = None) -> list[dict[str, Any]]:
"""
Returns List of dicts containing all Trades, including profit and trade count
NOTE: Not supported in Backtesting.
"""
filters: list = [Trade.is_open.is_(False)]
if minutes:
start_date = datetime.now(timezone.utc) - timedelta(minutes=minutes)
if start_date:
filters.append(Trade.close_date >= start_date)
pair_costs = (

View File

@@ -3,12 +3,14 @@ Performance pair list filter
"""
import logging
from datetime import timedelta
import pandas as pd
from freqtrade.exchange.exchange_types import Tickers
from freqtrade.persistence import Trade
from freqtrade.plugins.pairlist.IPairList import IPairList, PairlistParameter, SupportsBacktesting
from freqtrade.util.datetime_helpers import dt_now
logger = logging.getLogger(__name__)
@@ -69,7 +71,8 @@ class PerformanceFilter(IPairList):
"""
# Get the trading performance for pairs from database
try:
performance = pd.DataFrame(Trade.get_overall_performance(self._minutes))
start_date = dt_now() - timedelta(minutes=self._minutes)
performance = pd.DataFrame(Trade.get_overall_performance(start_date))
except AttributeError:
# Performancefilter does not work in backtesting.
self.log_once("PerformanceFilter is not available in this mode.", logger.warning)