Updates after review to PerformanceFilter days param
This commit is contained in:
parent
457e738b4a
commit
54ef36a497
@ -832,43 +832,21 @@ class Trade(_DECL_BASE, LocalTrade):
|
|||||||
return total_open_stake_amount or 0
|
return total_open_stake_amount or 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_overall_performance() -> List[Dict[str, Any]]:
|
def get_overall_performance(days=None) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Returns List of dicts containing all Trades, including profit and trade count
|
Returns List of dicts containing all Trades, including profit and trade count
|
||||||
NOTE: Not supported in Backtesting.
|
NOTE: Not supported in Backtesting.
|
||||||
"""
|
"""
|
||||||
|
filters = [Trade.is_open.is_(False)]
|
||||||
|
if days:
|
||||||
|
start_date = datetime.today() - timedelta(days)
|
||||||
|
filters.append((Trade.close_date >= start_date))
|
||||||
pair_rates = Trade.query.with_entities(
|
pair_rates = Trade.query.with_entities(
|
||||||
Trade.pair,
|
Trade.pair,
|
||||||
func.sum(Trade.close_profit).label('profit_sum'),
|
func.sum(Trade.close_profit).label('profit_sum'),
|
||||||
func.sum(Trade.close_profit_abs).label('profit_sum_abs'),
|
func.sum(Trade.close_profit_abs).label('profit_sum_abs'),
|
||||||
func.count(Trade.pair).label('count')
|
func.count(Trade.pair).label('count')
|
||||||
).filter(Trade.is_open.is_(False))\
|
).filter(filters)\
|
||||||
.group_by(Trade.pair) \
|
|
||||||
.order_by(desc('profit_sum_abs')) \
|
|
||||||
.all()
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
'pair': pair,
|
|
||||||
'profit': profit,
|
|
||||||
'profit_abs': profit_abs,
|
|
||||||
'count': count
|
|
||||||
}
|
|
||||||
for pair, profit, profit_abs, count in pair_rates
|
|
||||||
]
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def get_performance(days: int) -> List[Dict[str, Any]]:
|
|
||||||
"""
|
|
||||||
Returns List of dicts containing all Trades, including profit and trade count
|
|
||||||
NOTE: Not supported in Backtesting.
|
|
||||||
"""
|
|
||||||
start_date = datetime.today() - timedelta(days)
|
|
||||||
pair_rates = Trade.query.with_entities(
|
|
||||||
Trade.pair,
|
|
||||||
func.sum(Trade.close_profit).label('profit_sum'),
|
|
||||||
func.sum(Trade.close_profit_abs).label('profit_sum_abs'),
|
|
||||||
func.count(Trade.pair).label('count')
|
|
||||||
).filter(Trade.is_open.is_(False) & (Trade.close_date >= start_date))\
|
|
||||||
.group_by(Trade.pair) \
|
.group_by(Trade.pair) \
|
||||||
.order_by(desc('profit_sum_abs')) \
|
.order_by(desc('profit_sum_abs')) \
|
||||||
.all()
|
.all()
|
||||||
|
@ -48,10 +48,7 @@ class PerformanceFilter(IPairList):
|
|||||||
"""
|
"""
|
||||||
# Get the trading performance for pairs from database
|
# Get the trading performance for pairs from database
|
||||||
try:
|
try:
|
||||||
if self._days > 0:
|
performance = pd.DataFrame(Trade.get_overall_performance(self._days))
|
||||||
performance = pd.DataFrame(Trade.get_performance(self._days))
|
|
||||||
else:
|
|
||||||
performance = pd.DataFrame(Trade.get_overall_performance())
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# Performancefilter does not work in backtesting.
|
# Performancefilter does not work in backtesting.
|
||||||
self.log_once("PerformanceFilter is not available in this mode.", logger.warning)
|
self.log_once("PerformanceFilter is not available in this mode.", logger.warning)
|
||||||
|
Loading…
Reference in New Issue
Block a user