new_so_routine now cancels the old take profit order after the new safety order is sent

This commit is contained in:
Nicolás Sánchez 2025-02-02 13:14:40 -03:00
parent 9dfc063e23
commit 8e02ad1477
3 changed files with 12 additions and 9 deletions

View File

@ -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: 2025.01.31:
. In check_status, when safety order = None it does not return 1 anymore. . In check_status, when safety order = None it does not return 1 anymore.

View File

@ -24,7 +24,7 @@ In case the permissions of the certificate changes, reset them this way:
# ll /etc/letsencrypt/ # 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 Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

View File

@ -955,7 +955,7 @@ class trader:
if self.tp_order is None: 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) self.broker.logger.log_this("Take profit order is None, can't send a new safety order",1,self.pair)
return 1 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) self.broker.logger.log_this("Safety order is None, can't send a new safety order",1,self.pair)
return 1 return 1
@ -965,13 +965,6 @@ class trader:
# Save the order # Save the order
self.status_dict["deal_order_history"].append(filled_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 # Add the amount filled in the last safety order to the totals
new_fees_base,new_fees_quote = self.parse_fees(filled_order) new_fees_base,new_fees_quote = self.parse_fees(filled_order)
self.fees_paid_in_quote += new_fees_quote self.fees_paid_in_quote += new_fees_quote
@ -993,6 +986,13 @@ class trader:
self.so = self.broker.get_empty_order() self.so = self.broker.get_empty_order()
self.safety_order_index+=1 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 # 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 # TODO: This should also be taken into account for the profit calculation
# Do the partial profit calculation and save it for later # Do the partial profit calculation and save it for later