switch from arrow to humanize

This commit is contained in:
Matthias 2024-04-21 15:29:11 +02:00
parent 4320c7a3cc
commit cc534c5000
4 changed files with 19 additions and 11 deletions

View File

@ -44,7 +44,7 @@ from freqtrade.misc import (chunks, deep_merge_dicts, file_dump_json, file_load_
safe_value_fallback2)
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.util import dt_from_ts, dt_now
from freqtrade.util.datetime_helpers import dt_humanize, dt_ts
from freqtrade.util.datetime_helpers import dt_humanize_delta, dt_ts
from freqtrade.util.periodic_cache import PeriodicCache
@ -2008,7 +2008,7 @@ class Exchange:
logger.debug(
"one_call: %s msecs (%s)",
one_call,
dt_humanize(dt_now() - timedelta(milliseconds=one_call), only_distance=True)
dt_humanize_delta(dt_now() - timedelta(milliseconds=one_call))
)
input_coroutines = [self._async_get_candle_history(
pair, timeframe, candle_type, since) for since in

View File

@ -30,8 +30,8 @@ from freqtrade.persistence.models import PairLock
from freqtrade.plugins.pairlist.pairlist_helpers import expand_pairlist
from freqtrade.rpc.fiat_convert import CryptoToFiatConverter
from freqtrade.rpc.rpc_types import RPCSendMsg
from freqtrade.util import (decimals_per_coin, dt_humanize, dt_now, dt_ts_def, format_date,
shorten_date)
from freqtrade.util import decimals_per_coin, dt_now, dt_ts_def, format_date, shorten_date
from freqtrade.util.datetime_helpers import dt_humanize_delta
from freqtrade.wallets import PositionWallet, Wallet
@ -307,7 +307,7 @@ class RPC:
detail_trade = [
f'{trade.id} {direction_str}',
trade.pair + active_attempt_side_symbols_str,
shorten_date(dt_humanize(trade.open_date, only_distance=True)),
shorten_date(dt_humanize_delta(trade.open_date_utc)),
profit_str
]
@ -599,10 +599,10 @@ class RPC:
'trade_count': len(trades),
'closed_trade_count': closed_trade_count,
'first_trade_date': format_date(first_date),
'first_trade_humanized': dt_humanize(first_date) if first_date else '',
'first_trade_humanized': dt_humanize_delta(first_date) if first_date else '',
'first_trade_timestamp': dt_ts_def(first_date, 0),
'latest_trade_date': format_date(last_date),
'latest_trade_humanized': dt_humanize(last_date) if last_date else '',
'latest_trade_humanized': dt_humanize_delta(last_date) if last_date else '',
'latest_trade_timestamp': dt_ts_def(last_date, 0),
'avg_duration': str(timedelta(seconds=sum(durations) / num)).split('.')[0],
'best_pair': best_pair[0] if best_pair else '',

View File

@ -3,6 +3,7 @@ from datetime import datetime, timezone
from typing import Optional, Union
import arrow
import humanize
from freqtrade.constants import DATETIME_PRINT_FORMAT
@ -76,6 +77,13 @@ def shorten_date(_date: str) -> str:
return new_date
def dt_humanize_delta(dt: datetime):
"""
Return a humanized string for the given timedelta.
"""
return humanize.naturaltime(dt)
def dt_humanize(dt: datetime, **kwargs) -> str:
"""
Return a humanized string for the given datetime.

View File

@ -221,7 +221,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
assert "Since" in headers
assert "Pair" in headers
assert 'instantly' == result[0][2]
assert 'now' == result[0][2]
assert 'ETH/BTC' in result[0][1]
assert '0.00 (0.00)' == result[0][3]
assert '0.00' == f'{fiat_profit_sum:.2f}'
@ -232,7 +232,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
assert "Since" in headers
assert "Pair" in headers
assert 'instantly' == result[0][2]
assert 'now' == result[0][2]
assert 'ETH/BTC' in result[0][1]
assert '-0.41% (-0.00)' == result[0][3]
assert '-0.00' == f'{fiat_profit_sum:.2f}'
@ -243,7 +243,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
assert "Since" in headers
assert "Pair" in headers
assert len(result[0]) == 4
assert 'instantly' == result[0][2]
assert 'now' == result[0][2]
assert 'ETH/BTC' in result[0][1]
assert '-0.41% (-0.06)' == result[0][3]
assert '-0.06' == f'{fiat_profit_sum:.2f}'
@ -260,7 +260,7 @@ def test_rpc_status_table(default_conf, ticker, fee, mocker) -> None:
mocker.patch(f'{EXMS}.get_rate',
MagicMock(side_effect=ExchangeError("Pair 'ETH/BTC' not available")))
result, headers, fiat_profit_sum = rpc._rpc_status_table(default_conf['stake_currency'], 'USD')
assert 'instantly' == result[0][2]
assert 'now' == result[0][2]
assert 'ETH/BTC' in result[0][1]
assert 'nan%' == result[0][3]
assert isnan(fiat_profit_sum)