mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-09-20 09:31:12 +00:00
Update to dt_humanize_delta for all usages
This commit is contained in:
parent
cc534c5000
commit
d48cff3b9a
|
@ -33,7 +33,7 @@ from freqtrade.misc import chunks, plural
|
|||
from freqtrade.persistence import Trade
|
||||
from freqtrade.rpc import RPC, RPCException, RPCHandler
|
||||
from freqtrade.rpc.rpc_types import RPCEntryMsg, RPCExitMsg, RPCOrderMsg, RPCSendMsg
|
||||
from freqtrade.util import dt_humanize, fmt_coin, format_date, round_value
|
||||
from freqtrade.util import dt_from_ts, dt_humanize_delta, fmt_coin, format_date, round_value
|
||||
|
||||
|
||||
MAX_MESSAGE_LENGTH = MessageLimit.MAX_TEXT_LENGTH
|
||||
|
@ -573,8 +573,7 @@ class Telegram(RPCHandler):
|
|||
# TODO: This calculation ignores fees.
|
||||
price_to_1st_entry = ((cur_entry_average - first_avg) / first_avg)
|
||||
if is_open:
|
||||
lines.append("({})".format(dt_humanize(order["order_filled_date"],
|
||||
granularity=["day", "hour", "minute"])))
|
||||
lines.append("({})".format(dt_humanize_delta(order["order_filled_date"])))
|
||||
lines.append(f"*Amount:* {round_value(cur_entry_amount, 8)} "
|
||||
f"({fmt_coin(order['cost'], quote_currency)})")
|
||||
lines.append(f"*Average {wording} Price:* {round_value(cur_entry_average, 8)} "
|
||||
|
@ -657,7 +656,7 @@ class Telegram(RPCHandler):
|
|||
position_adjust = self._config.get('position_adjustment_enable', False)
|
||||
max_entries = self._config.get('max_entry_position_adjustment', -1)
|
||||
for r in results:
|
||||
r['open_date_hum'] = dt_humanize(r['open_date'])
|
||||
r['open_date_hum'] = dt_humanize_delta(r['open_date'])
|
||||
r['num_entries'] = len([o for o in r['orders'] if o['ft_is_entry']])
|
||||
r['num_exits'] = len([o for o in r['orders'] if not o['ft_is_entry']
|
||||
and not o['ft_order_side'] == 'stoploss'])
|
||||
|
@ -1289,7 +1288,7 @@ class Telegram(RPCHandler):
|
|||
nrecent
|
||||
)
|
||||
trades_tab = tabulate(
|
||||
[[dt_humanize(trade['close_date']),
|
||||
[[dt_humanize_delta(dt_from_ts(trade['close_timestamp'])),
|
||||
trade['pair'] + " (#" + str(trade['trade_id']) + ")",
|
||||
f"{(trade['close_profit']):.2%} ({trade['close_profit_abs']})"]
|
||||
for trade in trades['trades']],
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from freqtrade.util.datetime_helpers import (dt_floor_day, dt_from_ts, dt_humanize, dt_now, dt_ts,
|
||||
dt_ts_def, dt_ts_none, dt_utc, format_date,
|
||||
format_ms_time, shorten_date)
|
||||
from freqtrade.util.datetime_helpers import (dt_floor_day, dt_from_ts, dt_humanize,
|
||||
dt_humanize_delta, dt_now, dt_ts, dt_ts_def,
|
||||
dt_ts_none, dt_utc, format_date, format_ms_time,
|
||||
shorten_date)
|
||||
from freqtrade.util.formatters import decimals_per_coin, fmt_coin, round_value
|
||||
from freqtrade.util.ft_precise import FtPrecise
|
||||
from freqtrade.util.measure_time import MeasureTime
|
||||
|
@ -12,6 +13,7 @@ __all__ = [
|
|||
'dt_floor_day',
|
||||
'dt_from_ts',
|
||||
'dt_humanize',
|
||||
'dt_humanize_delta',
|
||||
'dt_now',
|
||||
'dt_ts',
|
||||
'dt_ts_def',
|
||||
|
|
|
@ -1821,8 +1821,8 @@ async def test_edge_enabled(edge_conf, update, mocker) -> None:
|
|||
|
||||
|
||||
@pytest.mark.parametrize('is_short,regex_pattern',
|
||||
[(True, r"just now[ ]*XRP\/BTC \(#3\) -1.00% \("),
|
||||
(False, r"just now[ ]*XRP\/BTC \(#3\) 1.00% \(")])
|
||||
[(True, r"now[ ]*XRP\/BTC \(#3\) -1.00% \("),
|
||||
(False, r"now[ ]*XRP\/BTC \(#3\) 1.00% \(")])
|
||||
async def test_telegram_trades(mocker, update, default_conf, fee, is_short, regex_pattern):
|
||||
|
||||
telegram, _, msg_mock = get_telegram_testobject(mocker, default_conf)
|
||||
|
|
|
@ -3,8 +3,9 @@ from datetime import datetime, timedelta, timezone
|
|||
import pytest
|
||||
import time_machine
|
||||
|
||||
from freqtrade.util import (dt_floor_day, dt_from_ts, dt_humanize, dt_now, dt_ts, dt_ts_def,
|
||||
dt_ts_none, dt_utc, format_date, format_ms_time, shorten_date)
|
||||
from freqtrade.util import (dt_floor_day, dt_from_ts, dt_now, dt_ts, dt_ts_def, dt_ts_none, dt_utc,
|
||||
format_date, format_ms_time, shorten_date)
|
||||
from freqtrade.util.datetime_helpers import dt_humanize_delta
|
||||
|
||||
|
||||
def test_dt_now():
|
||||
|
@ -68,9 +69,12 @@ def test_shorten_date() -> None:
|
|||
|
||||
|
||||
def test_dt_humanize() -> None:
|
||||
assert dt_humanize(dt_now()) == 'just now'
|
||||
assert dt_humanize(dt_now(), only_distance=True) == 'instantly'
|
||||
assert dt_humanize(dt_now() - timedelta(hours=16), only_distance=True) == '16 hours'
|
||||
assert dt_humanize_delta(dt_now()) == 'now'
|
||||
assert dt_humanize_delta(dt_now() - timedelta(minutes=50)) == '50 minutes ago'
|
||||
assert dt_humanize_delta(dt_now() - timedelta(hours=16)) == '16 hours ago'
|
||||
assert dt_humanize_delta(dt_now() - timedelta(hours=16, minutes=30)) == '16 hours ago'
|
||||
assert dt_humanize_delta(dt_now() - timedelta(days=16, hours=10, minutes=25)) == '16 days ago'
|
||||
assert dt_humanize_delta(dt_now() - timedelta(minutes=50)) == '50 minutes ago'
|
||||
|
||||
|
||||
def test_format_ms_time() -> None:
|
||||
|
|
Loading…
Reference in New Issue
Block a user