Merge pull request #294 from jblestang/add_trades_count_in_performance
Add trades count foreach pair in performance command
This commit is contained in:
commit
4a717f3df8
@ -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)
|
||||||
|
@ -400,11 +400,10 @@ def test_performance_handle(
|
|||||||
|
|
||||||
trade.close_date = datetime.utcnow()
|
trade.close_date = datetime.utcnow()
|
||||||
trade.is_open = False
|
trade.is_open = False
|
||||||
|
|
||||||
_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(
|
||||||
|
Loading…
Reference in New Issue
Block a user