Improve type safety

This commit is contained in:
Matthias 2023-05-03 06:25:02 +00:00
parent 80930d72a6
commit 775ea1c8c6

View File

@ -1721,8 +1721,8 @@ class FreqtradeBot(LoggingMixin):
else: else:
trade.exit_order_status = reason trade.exit_order_status = reason
order = trade.select_order_by_order_id(order_id) order_or_none = trade.select_order_by_order_id(order_id)
self.order_obj_or_raise(order_id, order) order = self.order_obj_or_raise(order_id, order_or_none)
profit_rate: float = trade.safe_close_rate profit_rate: float = trade.safe_close_rate
profit_trade = trade.calc_profit(rate=profit_rate) profit_trade = trade.calc_profit(rate=profit_rate)
@ -1763,10 +1763,11 @@ class FreqtradeBot(LoggingMixin):
# Send the message # Send the message
self.rpc.send_msg(msg) self.rpc.send_msg(msg)
def order_obj_or_raise(self, order_id: str, order_obj: Order): def order_obj_or_raise(self, order_id: str, order_obj: Optional[Order]) -> Order:
if not order_obj: if not order_obj:
raise DependencyException( raise DependencyException(
f"Order_obj not found for {order_id}. This should not have happened.") f"Order_obj not found for {order_id}. This should not have happened.")
return order_obj
# #
# Common update trade state methods # Common update trade state methods
@ -1806,8 +1807,8 @@ class FreqtradeBot(LoggingMixin):
# Handling of this will happen in check_handle_timedout. # Handling of this will happen in check_handle_timedout.
return True return True
order_obj = trade.select_order_by_order_id(order_id) order_obj_or_none = trade.select_order_by_order_id(order_id)
self.order_obj_or_raise(order_id, order_obj) order_obj = self.order_obj_or_raise(order_id, order_obj_or_none)
self.handle_order_fee(trade, order_obj, order) self.handle_order_fee(trade, order_obj, order)