diff --git a/changelog.txt b/changelog.txt index 26fce96..42d0334 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2025.02.02: +. new_so_routine now cancels the old take profit order after the new safety order is sent. + 2025.01.31: . In check_status, when safety order = None it does not return 1 anymore. diff --git a/main.py b/main.py index f92c914..40e63c6 100644 --- a/main.py +++ b/main.py @@ -24,7 +24,7 @@ In case the permissions of the certificate changes, reset them this way: # ll /etc/letsencrypt/ ''' -version = "2025.01.31" +version = "2025.02.02" ''' Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors diff --git a/trader.py b/trader.py index 8192271..ac70e9f 100755 --- a/trader.py +++ b/trader.py @@ -955,7 +955,7 @@ class trader: if self.tp_order is None: self.broker.logger.log_this("Take profit order is None, can't send a new safety order",1,self.pair) return 1 - if self.so is None: + if self.so is None: #I don't think this is necessary self.broker.logger.log_this("Safety order is None, can't send a new safety order",1,self.pair) return 1 @@ -965,13 +965,6 @@ class trader: # Save the order self.status_dict["deal_order_history"].append(filled_order) - # Cancel the tp order - if self.broker.cancel_order(self.tp_order["id"],self.pair)==1: - error_string = f"{self.pair} | {self.tp_order['id']} | Old TP order probably filled. Can't cancel. This trader should be restarted" - self.broker.logger.log_this(f"Old take profit order is probably filled, can't cancel. This trader should be restarted. Order ID: {self.tp_order['id']}",1,self.pair) - self.status_dict["pause_reason"] = error_string - return 2 - # Add the amount filled in the last safety order to the totals new_fees_base,new_fees_quote = self.parse_fees(filled_order) self.fees_paid_in_quote += new_fees_quote @@ -993,6 +986,13 @@ class trader: self.so = self.broker.get_empty_order() self.safety_order_index+=1 + # Cancel the old tp order + if self.broker.cancel_order(self.tp_order["id"],self.pair)==1: + error_string = f"{self.pair} | {self.tp_order['id']} | Old TP order probably filled. Can't cancel. This trader should be restarted" + self.broker.logger.log_this(f"Old take profit order is probably filled, can't cancel. This trader should be restarted. Order ID: {self.tp_order['id']}",1,self.pair) + self.status_dict["pause_reason"] = error_string + return 2 + # Check if the old tp order was partially filled. If so, update the previous two variables accordingly # TODO: This should also be taken into account for the profit calculation # Do the partial profit calculation and save it for later