2025.10.24

This commit is contained in:
Nicolás Sánchez 2025-10-24 20:17:46 -03:00
parent b69b0d2f15
commit 96d1cf6d78
4 changed files with 16 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2025.10.24:
. Toggling liquidate_after_switch now writes the config file to disk so the setting persists between trades.
. Manually switching to long now sets double_check_price to false.
. Added a few comments to switch_to_long.
2025.10.12:
. do_cleanup relocated after generating the safety orders' prices.

View File

@ -252,6 +252,7 @@ class ConfigHandler:
# self.broker.logger.log_this(f"liquidate_after_switch must be a boolean",1,self.get_pair())
# return 1
self.config_dictionary["liquidate_after_switch"] = liquidate_after_switch
self.save_to_file()
return 0
def set_tp_mode(self, tp_mode: int):

View File

@ -18,7 +18,7 @@ import exchange_wrapper
import trader
version = "2025.10.12"
version = "2025.10.24"
'''
Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@ -1642,7 +1642,7 @@ def unwrapped_switch_to_long(base,quote,calculate_profits):
for instance in running_traders:
if f"{base}/{quote}"==instance.status.get_pair():
instance.set_pause(True, "Switching to long mode")
if instance.switch_to_long(ignore_old_long=ignore_old_long)==1:
if instance.switch_to_long(ignore_old_long=ignore_old_long,double_check_price=False)==1:
return jsonify({"Error": "Error in switch_to_long()"})
if instance.start_trader()==1:
instance.quit = True

View File

@ -606,12 +606,14 @@ class trader:
if double_check_price:
#Waits a moment to see if the price has moved too much
self.broker.logger.log_this("Confirming price...",2,self.status.get_pair())
time.sleep(self.broker.get_wait_time()*4)
if not self.check_old_long(True):
self.broker.logger.log_this("False positive. Nothing to do.",1,self.status.get_pair())
return 2
#Check old_long data
self.broker.logger.log_this("Checking if old long data is valid.",2,self.status.get_pair())
if not ignore_old_long and self.status.get_old_long()=={}:
self.broker.logger.log_this("Can't find old long info on status_dict, searching for oldlong file",1,self.status.get_pair())
try:
@ -624,6 +626,7 @@ class trader:
return 1
#Cancel open orders
self.broker.logger.log_this("Cancelling open orders",2,self.status.get_pair())
for order in self.status.get_safety_orders():
self.broker.cancel_order(order["id"],self.status.get_pair())
if self.status.get_take_profit_order() is not None:
@ -632,14 +635,17 @@ class trader:
self.broker.logger.log_this("Safety order is None",1,self.status.get_pair())
#Sell all base currency
self.broker.logger.log_this(f"Selling {self.status.get_pair().split('/')[0]}",2,self.status.get_pair())
self.liquidate_base(ignore_profits=ignore_old_long, already_received_quote=already_received_quote)
if self.config.get_liquidate_after_switch():
self.broker.logger.log_this("Liquidate after switch active. Raising quit flag.",2,self.status.get_pair())
self.quit = True
return 1
return 0
#Rewrite config file (if it exists)
if path.isfile(f"configs/{self.base}{self.quote}.bak") and path.isfile(f"configs/{self.base}{self.quote}.json"):
self.broker.logger.log_this("Restoring config file from backup",2,self.status.get_pair())
with open(f"configs/{self.base}{self.quote}.bak") as c:
old_config = load(c)
with open(f"configs/{self.base}{self.quote}.json","w") as c:
@ -665,6 +671,7 @@ class trader:
self.status.set_so_amount(0)
#Done. Ready for start_trader
self.broker.logger.log_this("Finished setting up the switch to long.",2,self.status.get_pair())
return 0