Merge pull request #4508 from Th0masL/fix_order_by

Change order_by from ID to close_date for /trades command
This commit is contained in:
Matthias 2021-03-09 20:20:04 +01:00 committed by GitHub
commit dd420a22e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 8 deletions

View File

@ -289,9 +289,10 @@ class RPC:
""" Returns the X last trades """
if limit > 0:
trades = Trade.get_trades([Trade.is_open.is_(False)]).order_by(
Trade.id.desc()).limit(limit)
Trade.close_date.desc()).limit(limit)
else:
trades = Trade.get_trades([Trade.is_open.is_(False)]).order_by(Trade.id.desc()).all()
trades = Trade.get_trades([Trade.is_open.is_(False)]).order_by(
Trade.close_date.desc()).all()
output = [trade.to_json() for trade in trades]

View File

@ -637,13 +637,13 @@ class Telegram(RPCHandler):
nrecent
)
trades_tab = tabulate(
[[arrow.get(trade['open_date']).humanize(),
trade['pair'],
[[arrow.get(trade['close_date']).humanize(),
trade['pair'] + " (#" + str(trade['trade_id']) + ")",
f"{(100 * trade['close_profit']):.2f}% ({trade['close_profit_abs']})"]
for trade in trades['trades']],
headers=[
'Open Date',
'Pair',
'Close Date',
'Pair (ID)',
f'Profit ({stake_cur})',
],
tablefmt='simple')

View File

@ -88,7 +88,7 @@ def mock_trade_2(fee):
timeframe=5,
sell_reason='sell_signal',
open_date=datetime.now(tz=timezone.utc) - timedelta(minutes=20),
close_date=datetime.now(tz=timezone.utc),
close_date=datetime.now(tz=timezone.utc) - timedelta(minutes=2),
)
o = Order.parse_from_ccxt_object(mock_order_2(), 'ETC/BTC', 'buy')
trade.orders.append(o)

View File

@ -1128,8 +1128,10 @@ def test_telegram_trades(mocker, update, default_conf, fee):
msg_mock.call_count == 1
assert "2 recent trades</b>:" in msg_mock.call_args_list[0][0][0]
assert "Profit (" in msg_mock.call_args_list[0][0][0]
assert "Open Date" in msg_mock.call_args_list[0][0][0]
assert "Close Date" in msg_mock.call_args_list[0][0][0]
assert "<pre>" in msg_mock.call_args_list[0][0][0]
assert bool(re.search("just now[ ]*XRP\\/BTC \\(#3\\) 1.00% \\(None\\)",
msg_mock.call_args_list[0][0][0]))
def test_telegram_delete_trade(mocker, update, default_conf, fee):