time aggregate to only query for data necessary

improves the query by not creating a full trade object.
This commit is contained in:
Matthias 2022-06-10 07:26:53 +02:00
parent 2218313f5c
commit ad3c01736e

View File

@ -309,16 +309,18 @@ class RPC:
for day in range(0, timescale):
profitday = start_date - time_offset(day)
trades = Trade.get_trades(trade_filter=[
# Only query for necessary columns for performance reasons.
trades = Trade.query.session.query(Trade.close_profit_abs).filter(
Trade.is_open.is_(False),
Trade.close_date >= profitday,
Trade.close_date < (profitday + time_offset(1))
]).order_by(Trade.close_date).all()
).order_by(Trade.close_date).all()
curdayprofit = sum(
trade.close_profit_abs for trade in trades if trade.close_profit_abs is not None)
profit_units[profitday] = {
'amount': curdayprofit,
'trades': len(trades)
'trades': len(trades),
}
data = [