From 1b1216fc87b49050ab81e64f41ee346cbcaee04b Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 10 Feb 2022 19:18:19 +0100 Subject: [PATCH] Rename update_trade method --- freqtrade/freqtradebot.py | 3 ++- freqtrade/persistence/models.py | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/freqtrade/freqtradebot.py b/freqtrade/freqtradebot.py index 9166f43e9..b8dfc6b08 100644 --- a/freqtrade/freqtradebot.py +++ b/freqtrade/freqtradebot.py @@ -1362,7 +1362,8 @@ class FreqtradeBot(LoggingMixin): if not order_obj: # TODO: this can't happen! raise OperationalException("order-obj not found!") - trade.update(order_obj) + trade.update_trade(order_obj) + # TODO: is the below necessary? it's already done in update_trade for filled buys trade.recalc_trade_from_orders() Trade.commit() diff --git a/freqtrade/persistence/models.py b/freqtrade/persistence/models.py index e6daa08ba..52aea387f 100644 --- a/freqtrade/persistence/models.py +++ b/freqtrade/persistence/models.py @@ -151,7 +151,7 @@ class Order(_DECL_BASE): return (f'Order(id={self.id}, order_id={self.order_id}, trade_id={self.ft_trade_id}, ' f'side={self.side}, order_type={self.order_type}, status={self.status})') - def update_from_ccxt_object(self, order): + def update_from_ccxt_object(self, order) -> 'Order': """ Update Order from ccxt response Only updates if fields are available from ccxt - @@ -178,6 +178,7 @@ class Order(_DECL_BASE): if (order.get('filled', 0.0) or 0.0) > 0: self.order_filled_date = datetime.now(timezone.utc) self.order_update_date = datetime.now(timezone.utc) + return self def to_json(self) -> Dict[str, Any]: return { @@ -462,14 +463,14 @@ class LocalTrade(): f"Trailing stoploss saved us: " f"{float(self.stop_loss) - float(self.initial_stop_loss):.8f}.") - def update(self, order: Order) -> None: + def update_trade(self, order: Order) -> None: """ Updates this entity with amount and actual open/close rates. :param order: order retrieved by exchange.fetch_order() :return: None """ # Ignore open and cancelled orders - if order.status == 'open' or safe_value_fallback(order, 'average', 'price') is None: + if order.status == 'open' or order.safe_price is None: return logger.info(f'Updating trade (id={self.id}) ...')