no suspect function calls in function headers . . .

This commit is contained in:
Matthias 2024-05-05 19:32:29 +02:00
parent 3f9019a1ad
commit 39613c0785

View File

@ -1900,17 +1900,21 @@ class Trade(ModelBase, LocalTrade):
return resp return resp
@staticmethod @staticmethod
def get_best_pair(start_date: datetime = datetime.fromtimestamp(0)): def get_best_pair(start_date: Optional[datetime] = None):
""" """
Get best pair with closed trade. Get best pair with closed trade.
NOTE: Not supported in Backtesting. NOTE: Not supported in Backtesting.
:returns: Tuple containing (pair, profit_sum) :returns: Tuple containing (pair, profit_sum)
""" """
filters: List = [Trade.is_open.is_(False)]
if start_date:
filters.append(Trade.close_date >= start_date)
best_pair = Trade.session.execute( best_pair = Trade.session.execute(
select( select(
Trade.pair, Trade.pair,
func.sum(Trade.close_profit).label('profit_sum') func.sum(Trade.close_profit).label('profit_sum')
).filter(Trade.is_open.is_(False) & (Trade.close_date >= start_date)) ).filter(*filters)
.group_by(Trade.pair) .group_by(Trade.pair)
.order_by(desc('profit_sum')) .order_by(desc('profit_sum'))
).first() ).first()
@ -1918,17 +1922,21 @@ class Trade(ModelBase, LocalTrade):
return best_pair return best_pair
@staticmethod @staticmethod
def get_trading_volume(start_date: datetime = datetime.fromtimestamp(0)) -> float: def get_trading_volume(start_date: Optional[datetime] = None) -> float:
""" """
Get Trade volume based on Orders Get Trade volume based on Orders
NOTE: Not supported in Backtesting. NOTE: Not supported in Backtesting.
:returns: Tuple containing (pair, profit_sum) :returns: Tuple containing (pair, profit_sum)
""" """
filters = [
Order.status == 'closed'
]
if start_date:
filters.append(Order.order_filled_date >= start_date)
trading_volume = Trade.session.execute( trading_volume = Trade.session.execute(
select( select(
func.sum(Order.cost).label('volume') func.sum(Order.cost).label('volume')
).filter( ).filter(
Order.order_filled_date >= start_date, *filters
Order.status == 'closed'
)).scalar_one() )).scalar_one()
return trading_volume or 0.0 return trading_volume or 0.0