2025.10.24
This commit is contained in:
parent
b69b0d2f15
commit
96d1cf6d78
|
|
@ -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:
|
2025.10.12:
|
||||||
. do_cleanup relocated after generating the safety orders' prices.
|
. do_cleanup relocated after generating the safety orders' prices.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -252,6 +252,7 @@ class ConfigHandler:
|
||||||
# self.broker.logger.log_this(f"liquidate_after_switch must be a boolean",1,self.get_pair())
|
# self.broker.logger.log_this(f"liquidate_after_switch must be a boolean",1,self.get_pair())
|
||||||
# return 1
|
# return 1
|
||||||
self.config_dictionary["liquidate_after_switch"] = liquidate_after_switch
|
self.config_dictionary["liquidate_after_switch"] = liquidate_after_switch
|
||||||
|
self.save_to_file()
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def set_tp_mode(self, tp_mode: int):
|
def set_tp_mode(self, tp_mode: int):
|
||||||
|
|
|
||||||
4
main.py
4
main.py
|
|
@ -18,7 +18,7 @@ import exchange_wrapper
|
||||||
import trader
|
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
|
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:
|
for instance in running_traders:
|
||||||
if f"{base}/{quote}"==instance.status.get_pair():
|
if f"{base}/{quote}"==instance.status.get_pair():
|
||||||
instance.set_pause(True, "Switching to long mode")
|
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()"})
|
return jsonify({"Error": "Error in switch_to_long()"})
|
||||||
if instance.start_trader()==1:
|
if instance.start_trader()==1:
|
||||||
instance.quit = True
|
instance.quit = True
|
||||||
|
|
|
||||||
|
|
@ -606,12 +606,14 @@ class trader:
|
||||||
|
|
||||||
if double_check_price:
|
if double_check_price:
|
||||||
#Waits a moment to see if the price has moved too much
|
#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)
|
time.sleep(self.broker.get_wait_time()*4)
|
||||||
if not self.check_old_long(True):
|
if not self.check_old_long(True):
|
||||||
self.broker.logger.log_this("False positive. Nothing to do.",1,self.status.get_pair())
|
self.broker.logger.log_this("False positive. Nothing to do.",1,self.status.get_pair())
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
#Check old_long data
|
#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()=={}:
|
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())
|
self.broker.logger.log_this("Can't find old long info on status_dict, searching for oldlong file",1,self.status.get_pair())
|
||||||
try:
|
try:
|
||||||
|
|
@ -624,6 +626,7 @@ class trader:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#Cancel open orders
|
#Cancel open orders
|
||||||
|
self.broker.logger.log_this("Cancelling open orders",2,self.status.get_pair())
|
||||||
for order in self.status.get_safety_orders():
|
for order in self.status.get_safety_orders():
|
||||||
self.broker.cancel_order(order["id"],self.status.get_pair())
|
self.broker.cancel_order(order["id"],self.status.get_pair())
|
||||||
if self.status.get_take_profit_order() is not None:
|
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())
|
self.broker.logger.log_this("Safety order is None",1,self.status.get_pair())
|
||||||
|
|
||||||
#Sell all base currency
|
#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)
|
self.liquidate_base(ignore_profits=ignore_old_long, already_received_quote=already_received_quote)
|
||||||
|
|
||||||
if self.config.get_liquidate_after_switch():
|
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
|
self.quit = True
|
||||||
return 1
|
return 0
|
||||||
|
|
||||||
#Rewrite config file (if it exists)
|
#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"):
|
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:
|
with open(f"configs/{self.base}{self.quote}.bak") as c:
|
||||||
old_config = load(c)
|
old_config = load(c)
|
||||||
with open(f"configs/{self.base}{self.quote}.json","w") as 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)
|
self.status.set_so_amount(0)
|
||||||
|
|
||||||
#Done. Ready for start_trader
|
#Done. Ready for start_trader
|
||||||
|
self.broker.logger.log_this("Finished setting up the switch to long.",2,self.status.get_pair())
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue