Adding the number of trades in the performance display

This commit is contained in:
Jean-Baptiste LE STANG 2018-01-02 14:32:13 +01:00
parent 0c11d4443f
commit 29987c3ff6
2 changed files with 7 additions and 5 deletions

View File

@ -469,17 +469,19 @@ def _performance(bot: Bot, update: Update) -> None:
send_msg('`trader is not running`', bot=bot) send_msg('`trader is not running`', bot=bot)
return return
pair_rates = Trade.session.query(Trade.pair, func.sum(Trade.close_profit).label('profit_sum')) \ pair_rates = Trade.session.query(Trade.pair, func.sum(Trade.close_profit).label('profit_sum'),
func.count(Trade.pair).label('count')) \
.filter(Trade.is_open.is_(False)) \ .filter(Trade.is_open.is_(False)) \
.group_by(Trade.pair) \ .group_by(Trade.pair) \
.order_by(text('profit_sum DESC')) \ .order_by(text('profit_sum DESC')) \
.all() .all()
stats = '\n'.join('{index}.\t<code>{pair}\t{profit:.2f}%</code>'.format( stats = '\n'.join('{index}.\t<code>{pair}\t{profit:.2f}% ({count})</code>'.format(
index=i + 1, index=i + 1,
pair=pair, pair=pair,
profit=round(rate * 100, 2) profit=round(rate * 100, 2),
) for i, (pair, rate) in enumerate(pair_rates)) count=count
) for i, (pair, rate, count) in enumerate(pair_rates))
message = '<b>Performance:</b>\n{}'.format(stats) message = '<b>Performance:</b>\n{}'.format(stats)
logger.debug(message) logger.debug(message)

View File

@ -404,7 +404,7 @@ def test_performance_handle(
_performance(bot=MagicMock(), update=update) _performance(bot=MagicMock(), update=update)
assert msg_mock.call_count == 1 assert msg_mock.call_count == 1
assert 'Performance' in msg_mock.call_args_list[0][0][0] assert 'Performance' in msg_mock.call_args_list[0][0][0]
assert '<code>BTC_ETH\t6.20%</code>' in msg_mock.call_args_list[0][0][0] assert '<code>BTC_ETH\t6.20% (1)</code>' in msg_mock.call_args_list[0][0][0]
def test_daily_handle( def test_daily_handle(