first run of config_handler

This commit is contained in:
Nicolás Sánchez 2025-02-26 16:00:53 -03:00
parent 3d9f28d6a0
commit 8e9a26cffb
2 changed files with 20 additions and 20 deletions

36
main.py
View File

@ -24,7 +24,7 @@ In case the permissions of the certificate changes, reset them this way:
# ll /etc/letsencrypt/
'''
version = "2025.02.02"
version = "2025.02.26"
'''
Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@ -315,7 +315,7 @@ def main_loop():
while True:
#Restart traders that have the restart flag raised and remove traders that have the quit flag raised
for x in running_instances:
if x.restart and x.config_dict["attempt_restart"]:
if x.restart and x.config.get_attempt_restart():
broker.logger.log_this(f"Restarting trader",1,x.pair)
restart_pair_no_json(x.base,x.quote)
if x.quit:
@ -376,7 +376,7 @@ def main_loop():
for x in running_instances:
if not x.is_short:
curr += int(x.get_status_dict()["so_amount"]) # For the safety order occupancy percentage calculation
top += int(x.config_dict["no_of_safety_orders"]) # It shows the percentage of safety orders not filled
top += int(x.config.get_no_of_safety_orders()) # It shows the percentage of safety orders not filled
if not x.quit: #Why? Maybe to protect return_status() from weird errors if the trader errored out?
try:
if x.pair in price_list and price_list[x.pair] is not None:
@ -1489,10 +1489,10 @@ def unwrapped_switch_to_short(base,quote):
#x.safety_order_index = 0
#Reloading config file
x.config_dict = x.reload_config_dict()
x.config.load_from_file()
#Enabling autoswitch
x.config_dict["autoswitch"] = True
x.config.set_autoswitch(True)
if x.start_trader()==1:
x.quit = True
return jsonify({"Error": "Error switching to short mode (wAPI)"})
@ -1616,9 +1616,9 @@ def unwrapped_add_safety_orders(base,quote,amount):
if f"{base}/{quote}"==x.pair:
x.pause = True
#x.no_of_safety_orders += int(amount)
x.config_dict["no_of_safety_orders"]+=int(amount)
x.config.set_no_of_safety_orders(x.config.get_no_of_safety_orders()+int(amount))
broker.logger.log_this("Recalculating safety price table...",1,f"{base}/{quote}")
x.safety_price_table = x.calculate_safety_prices(x.start_price,x.config_dict["no_of_safety_orders"],x.config_dict["safety_order_deviance"])
x.safety_price_table = x.calculate_safety_prices(x.start_price,x.config.get_no_of_safety_orders(),x.config.get_safety_order_deviance())
broker.logger.log_this(f"Done. Added {amount} safety orders",1,f"{base}/{quote}")
x.update_status(True)
x.pause = False
@ -1645,7 +1645,7 @@ def unwrapped_mod_tp_level(base,quote,amount):
try:
for x in running_instances:
if f"{base}/{quote}"==x.pair:
x.config_dict["tp_level"]=float(amount)
x.config.set_tp_level(float(amount))
broker.logger.log_this("Done. The change will take effect when the next take profit order is placed",2,f"{base}/{quote}")
return jsonify({"Success": "Success. The change will take effect when the next TP order is placed"})
except Exception:
@ -1666,7 +1666,7 @@ def unwrapped_mod_global_tp_level(amount):
for x in running_instances:
try:
x.config_dict["tp_level"]=float(amount)
x.config.set_tp_level(float(amount))
broker.logger.log_this("Done. The change will take effect when the next take profit order is placed",2)
except Exception:
broker.logger.log_this("Error changing percentage. Ignoring.",2)
@ -1721,7 +1721,7 @@ def unwrapped_deferred_last_call(base,quote,yyyymmdd):
return jsonify({"Error": "Can't convert date to unix"})
for x in running_instances:
if f"{base}{quote}"==x.pair:
x.config_dict["stop_time"] = limit
x.config.set_programmed_stop_time(limit)
#save config file to disk
x.broker.rewrite_config_file()
return jsonify({"Success": f"Trader scheduled to go offline when profit is reached after {limit}"})
@ -1880,8 +1880,8 @@ def unwrapped_toggle_cleanup(base,quote):
pair_to_toggle = f"{base}/{quote}"
for x in running_instances:
if pair_to_toggle==x.pair:
x.config_dict["cleanup"] = not x.config_dict["cleanup"]
if x.config_dict["cleanup"]:
x.config.set_cleanup(not x.config.get_cleanup())
if x.config.get_cleanup():
return jsonify({"Success": "Cleanup turned ON"})
return jsonify({"Success": "Cleanup turned OFF"})
except Exception as e:
@ -1906,13 +1906,13 @@ def unwrapped_toggle_autoswitch(base,quote):
pair_to_toggle = f"{base}/{quote}"
for x in running_instances:
if pair_to_toggle==x.pair:
if x.config_dict["autoswitch"]:
if x.config.get_autoswitch():
broker.logger.log_this("Autoswitch turned OFF",1,f"{base}/{quote}")
x.config_dict["autoswitch"] = False
x.config.set_autoswitch(False)
return jsonify({"Success": "Autoswitch is now OFF"})
else:
broker.logger.log_this("Autoswitch turned ON",1,f"{base}/{quote}")
x.config_dict["autoswitch"] = True
x.config.set_autoswitch(True)
return jsonify({"Success": "Autoswitch is now ON"})
except Exception as e:
broker.logger.log_this(f"Exception while toggling autoswitch: {e}",1,f"{base}{quote}")
@ -1935,13 +1935,13 @@ def unwrapped_toggle_check_old_long_price(base,quote):
pair_to_toggle = f"{base}/{quote}"
for x in running_instances:
if pair_to_toggle==x.pair:
if x.config_dict["check_old_long_price"]:
if x.config.get_check_old_long_price():
broker.logger.log_this("Check OFF",1,f"{base}/{quote}")
x.config_dict["check_old_long_price"] = False
x.config.set_check_old_long_price(False)
return jsonify({"Success": "Old long price check turned OFF"})
else:
broker.logger.log_this("Check ON",1,f"{base}/{quote}")
x.config_dict["check_old_long_price"] = True
x.config.set_check_old_long_price(True)
return jsonify({"Success": "Old long price check turned ON"})
except Exception as e:
broker.logger.log_this(f"Exception while toggling check_old_long_price: {e}",1,f"{base}{quote}")

View File

@ -9,7 +9,7 @@ class trader:
def __init__(self, broker, config_dict: dict, is_import: bool = False):
self.pause = True #Signals the trader to not process order info when an API call manhandles the trader
#True by default, once the trader is started the start_trader method toggles it
self.quit = False #If true, it doesn't restart the bot when profit is reached.
self.quit = False
self.restart = False
self.broker = broker
self.tp_order = self.broker.get_empty_order()
@ -19,7 +19,7 @@ class trader:
self.market = self.broker.fetch_market(self.pair)
self.market_load_time = int(time.time())
self.market_reload_period = 86400 #Market reload period in seconds
self.base,self.quote = self.pair.split("/")
self.base,self.quote = self.pair.split("/")
self.is_short = self.config.get_is_short()
self.profit_table = self.config.get_tp_table()
self.max_short_safety_orders = self.config.get_max_short_safety_orders()