From 35c061cd10960ceb35ec5fce3bc148bb0a0fcabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Wed, 4 Dec 2024 16:51:50 -0300 Subject: [PATCH] None handling in switch_to_long --- trader.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/trader.py b/trader.py index ab85c44..e9fdb98 100755 --- a/trader.py +++ b/trader.py @@ -700,12 +700,12 @@ class trader: return 1 #Check if the orders are OK (Is this really necessary?) - if self.tp_order is None: - self.broker.logger.log_this("Take profit order is None, can't switch to short",1,self.pair) - return 1 - if self.so is None: - self.broker.logger.log_this("Safety order is None, can't switch to short",1,self.pair) - return 1 + # if self.tp_order is None: + # self.broker.logger.log_this("Take profit order is None, can't switch to short",1,self.pair) + # return 1 + # if self.so is None: + # self.broker.logger.log_this("Safety order is None, can't switch to short",1,self.pair) + # return 1 #Send Telegram message self.broker.logger.log_this("Attempting to switch to long bot",0,self.pair) @@ -718,15 +718,22 @@ class trader: except Exception as e: #self.write_to_log(time.strftime(f"[%Y/%m/%d %H:%M:%S] | {self.pair} | Can't find old long file")) self.broker.logger.log_this(f"Can't file oldlong file. Exception: {e}",1,self.pair) + self.quit = True return 1 #Cancel open orders try: - self.broker.cancel_order(self.so["id"],self.pair) + if self.so is not None: + self.broker.cancel_order(self.so["id"],self.pair) + else: + self.broker.logger.log_this("Take profit order is None",1,self.pair) except Exception as e: self.broker.logger.log_this(f"Error in cancel_order while cancelling safety order. Exception: {e}",1,self.pair) try: - self.broker.cancel_order(self.tp_order["id"],self.pair) + if self.tp_order is not None: + self.broker.cancel_order(self.tp_order["id"],self.pair) + else: + self.broker.logger.log_this("Safety order is None",1,self.pair) except Exception as e: self.broker.logger.log_this(f"Error in cancel_order while cancelling take profit order. Exception: {e}",1,self.pair)