refactor: simplify some date calculations

This commit is contained in:
Matthias
2025-01-04 14:35:51 +01:00
parent 37c10c9b06
commit 452358541b
3 changed files with 7 additions and 7 deletions

View File

@@ -10,6 +10,7 @@ from typing_extensions import Self
from freqtrade.constants import DATETIME_PRINT_FORMAT
from freqtrade.exceptions import ConfigurationError
from freqtrade.util import dt_from_ts
logger = logging.getLogger(__name__)
@@ -37,13 +38,13 @@ class TimeRange:
@property
def startdt(self) -> datetime | None:
if self.startts:
return datetime.fromtimestamp(self.startts, tz=timezone.utc)
return dt_from_ts(self.startts)
return None
@property
def stopdt(self) -> datetime | None:
if self.stopts:
return datetime.fromtimestamp(self.stopts, tz=timezone.utc)
return dt_from_ts(self.stopts)
return None
@property

View File

@@ -64,7 +64,7 @@ from freqtrade.rpc.rpc_types import (
)
from freqtrade.strategy.interface import IStrategy
from freqtrade.strategy.strategy_wrapper import strategy_safe_wrapper
from freqtrade.util import FtPrecise, MeasureTime
from freqtrade.util import FtPrecise, MeasureTime, dt_from_ts
from freqtrade.util.migrations.binance_mig import migrate_binance_futures_names
from freqtrade.wallets import Wallets
@@ -533,9 +533,8 @@ class FreqtradeBot(LoggingMixin):
logger.info(f"Found previously unknown order {order['id']} for {trade.pair}.")
order_obj = Order.parse_from_ccxt_object(order, trade.pair, order["side"])
order_obj.order_filled_date = datetime.fromtimestamp(
safe_value_fallback(order, "lastTradeTimestamp", "timestamp") // 1000,
tz=timezone.utc,
order_obj.order_filled_date = dt_from_ts(
safe_value_fallback(order, "lastTradeTimestamp", "timestamp")
)
trade.orders.append(order_obj)
Trade.commit()

View File

@@ -215,7 +215,7 @@ class Order(ModelBase):
self.stop_price = safe_value_fallback(order, "stopPrice", default_value=self.stop_price)
order_date = safe_value_fallback(order, "timestamp")
if order_date:
self.order_date = datetime.fromtimestamp(order_date / 1000, tz=timezone.utc)
self.order_date = dt_from_ts(order_date)
elif not self.order_date:
self.order_date = dt_now()