first run of config_handler
This commit is contained in:
parent
3d9f28d6a0
commit
8e9a26cffb
36
main.py
36
main.py
|
|
@ -24,7 +24,7 @@ In case the permissions of the certificate changes, reset them this way:
|
||||||
# ll /etc/letsencrypt/
|
# 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
|
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:
|
while True:
|
||||||
#Restart traders that have the restart flag raised and remove traders that have the quit flag raised
|
#Restart traders that have the restart flag raised and remove traders that have the quit flag raised
|
||||||
for x in running_instances:
|
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)
|
broker.logger.log_this(f"Restarting trader",1,x.pair)
|
||||||
restart_pair_no_json(x.base,x.quote)
|
restart_pair_no_json(x.base,x.quote)
|
||||||
if x.quit:
|
if x.quit:
|
||||||
|
|
@ -376,7 +376,7 @@ def main_loop():
|
||||||
for x in running_instances:
|
for x in running_instances:
|
||||||
if not x.is_short:
|
if not x.is_short:
|
||||||
curr += int(x.get_status_dict()["so_amount"]) # For the safety order occupancy percentage calculation
|
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?
|
if not x.quit: #Why? Maybe to protect return_status() from weird errors if the trader errored out?
|
||||||
try:
|
try:
|
||||||
if x.pair in price_list and price_list[x.pair] is not None:
|
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
|
#x.safety_order_index = 0
|
||||||
|
|
||||||
#Reloading config file
|
#Reloading config file
|
||||||
x.config_dict = x.reload_config_dict()
|
x.config.load_from_file()
|
||||||
|
|
||||||
#Enabling autoswitch
|
#Enabling autoswitch
|
||||||
x.config_dict["autoswitch"] = True
|
x.config.set_autoswitch(True)
|
||||||
if x.start_trader()==1:
|
if x.start_trader()==1:
|
||||||
x.quit = True
|
x.quit = True
|
||||||
return jsonify({"Error": "Error switching to short mode (wAPI)"})
|
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:
|
if f"{base}/{quote}"==x.pair:
|
||||||
x.pause = True
|
x.pause = True
|
||||||
#x.no_of_safety_orders += int(amount)
|
#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}")
|
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}")
|
broker.logger.log_this(f"Done. Added {amount} safety orders",1,f"{base}/{quote}")
|
||||||
x.update_status(True)
|
x.update_status(True)
|
||||||
x.pause = False
|
x.pause = False
|
||||||
|
|
@ -1645,7 +1645,7 @@ def unwrapped_mod_tp_level(base,quote,amount):
|
||||||
try:
|
try:
|
||||||
for x in running_instances:
|
for x in running_instances:
|
||||||
if f"{base}/{quote}"==x.pair:
|
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}")
|
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"})
|
return jsonify({"Success": "Success. The change will take effect when the next TP order is placed"})
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|
@ -1666,7 +1666,7 @@ def unwrapped_mod_global_tp_level(amount):
|
||||||
|
|
||||||
for x in running_instances:
|
for x in running_instances:
|
||||||
try:
|
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)
|
broker.logger.log_this("Done. The change will take effect when the next take profit order is placed",2)
|
||||||
except Exception:
|
except Exception:
|
||||||
broker.logger.log_this("Error changing percentage. Ignoring.",2)
|
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"})
|
return jsonify({"Error": "Can't convert date to unix"})
|
||||||
for x in running_instances:
|
for x in running_instances:
|
||||||
if f"{base}{quote}"==x.pair:
|
if f"{base}{quote}"==x.pair:
|
||||||
x.config_dict["stop_time"] = limit
|
x.config.set_programmed_stop_time(limit)
|
||||||
#save config file to disk
|
#save config file to disk
|
||||||
x.broker.rewrite_config_file()
|
x.broker.rewrite_config_file()
|
||||||
return jsonify({"Success": f"Trader scheduled to go offline when profit is reached after {limit}"})
|
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}"
|
pair_to_toggle = f"{base}/{quote}"
|
||||||
for x in running_instances:
|
for x in running_instances:
|
||||||
if pair_to_toggle==x.pair:
|
if pair_to_toggle==x.pair:
|
||||||
x.config_dict["cleanup"] = not x.config_dict["cleanup"]
|
x.config.set_cleanup(not x.config.get_cleanup())
|
||||||
if x.config_dict["cleanup"]:
|
if x.config.get_cleanup():
|
||||||
return jsonify({"Success": "Cleanup turned ON"})
|
return jsonify({"Success": "Cleanup turned ON"})
|
||||||
return jsonify({"Success": "Cleanup turned OFF"})
|
return jsonify({"Success": "Cleanup turned OFF"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
@ -1906,13 +1906,13 @@ def unwrapped_toggle_autoswitch(base,quote):
|
||||||
pair_to_toggle = f"{base}/{quote}"
|
pair_to_toggle = f"{base}/{quote}"
|
||||||
for x in running_instances:
|
for x in running_instances:
|
||||||
if pair_to_toggle==x.pair:
|
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}")
|
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"})
|
return jsonify({"Success": "Autoswitch is now OFF"})
|
||||||
else:
|
else:
|
||||||
broker.logger.log_this("Autoswitch turned ON",1,f"{base}/{quote}")
|
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"})
|
return jsonify({"Success": "Autoswitch is now ON"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
broker.logger.log_this(f"Exception while toggling autoswitch: {e}",1,f"{base}{quote}")
|
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}"
|
pair_to_toggle = f"{base}/{quote}"
|
||||||
for x in running_instances:
|
for x in running_instances:
|
||||||
if pair_to_toggle==x.pair:
|
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}")
|
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"})
|
return jsonify({"Success": "Old long price check turned OFF"})
|
||||||
else:
|
else:
|
||||||
broker.logger.log_this("Check ON",1,f"{base}/{quote}")
|
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"})
|
return jsonify({"Success": "Old long price check turned ON"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
broker.logger.log_this(f"Exception while toggling check_old_long_price: {e}",1,f"{base}{quote}")
|
broker.logger.log_this(f"Exception while toggling check_old_long_price: {e}",1,f"{base}{quote}")
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class trader:
|
||||||
def __init__(self, broker, config_dict: dict, is_import: bool = False):
|
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
|
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
|
#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.restart = False
|
||||||
self.broker = broker
|
self.broker = broker
|
||||||
self.tp_order = self.broker.get_empty_order()
|
self.tp_order = self.broker.get_empty_order()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue