This commit is contained in:
Nicolás Sánchez 2025-03-04 20:18:24 -03:00
parent df16f76c6b
commit d8f33da253
6 changed files with 33 additions and 8 deletions

View File

@ -1,3 +1,8 @@
2025.03.04.
. Error fix in add_quote.
. Error fix in last_call.
. Fixed a bug in switch_quote_currency that prevented the new config and status files to be written to disk.
2025.03.03:
. Replaced more variables with their respective config handlers.
. Added a new API endpoint: reload_trader_config.

View File

@ -117,6 +117,13 @@ class ConfigHandler:
def get_check_old_long_price(self):
return self.config_dictionary["check_old_long_price"]
def get_config_file_path(self):
return self.config_file_path
def set_config_file_path(self, new_file_path):
self.config_file_path = new_file_path
return 0
def set_pair(self, pair: str):
self.config_dictionary["pair"] = pair
return 0

16
main.py
View File

@ -16,7 +16,7 @@ import exchange_wrapper
import trader
version = "2025.03.03"
version = "2025.03.04"
'''
Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@ -1669,9 +1669,9 @@ def unwrapped_last_call(base,quote):
if f"{base}{quote}" in broker.get_pairs():
for x in running_instances:
if f"{base}/{quote}"==x.config.get_pair():
x.stop_when_profit = not x.stop_when_profit
x.status.set_stop_when_profit(not x.status.get_stop_when_profit())
x.update_status(True)
if x.stop_when_profit:
if x.status.get_stop_when_profit():
return jsonify({"Success": "Trader scheduled to go offline when profit is reached"})
return jsonify({"Success": "Last call cancelled"})
return jsonify({"Error": "Trader does not exist"})
@ -1728,7 +1728,9 @@ def unwrapped_toggle_pause(base,quote):
for instance in running_instances:
if instance.config.get_pair()==f"{base}/{quote}":
if instance.pause:
instance.status.set_pause_reason("")
return jsonify({"Success": "Trader will be resumed"})
instance.status.set_pause_reason("User requested pause")
return jsonify({"Success": "Trader will be paused"})
return jsonify({"Error": "Trader does not exist"})
except Exception:
@ -1746,7 +1748,7 @@ def unwrapped_global_last_call():
if broker.get_pairs!=[]:
#broker.clear_pairs()
for x in running_instances:
x.stop_when_profit = True
x.status.set_stop_when_profit(True)
broker.logger.log_this("Modified flag",2,f"{x.base}/{x.quote}")
return jsonify({"Success": "All traders scheduled to go offline when profit is reached"})
return jsonify({"Error": "No traders running"})
@ -1765,7 +1767,7 @@ def unwrapped_cancel_global_last_call():
if broker.get_pairs!=[]:
#broker.clear_pairs()
for x in running_instances:
x.stop_when_profit = False
x.status.set_stop_when_profit(False)
broker.logger.log_this("Modified flag",2,f"{x.base}/{x.quote}")
return jsonify({"Success": "Last call canceled"})
return jsonify({"Error": "No traders running"})
@ -1819,7 +1821,7 @@ def unwrapped_add_quote(base,quote,amount):
x.status.set_quote_spent(x.status.get_quote_spent()+returned_order["cost"])
broker.logger.log_this("Cancelling old take profit order and sending a new one",2,f"{base}/{quote}")
attempts = 5
while broker.cancel_order(x.status.get_tp_order_id(),x.config.get_pair())==1:
while broker.cancel_order(x.status.get_take_profit_order()["id"],x.config.get_pair())==1:
broker.logger.log_this("Can't cancel old take profit order, retrying...",2,f"{base}/{quote}")
time.sleep(broker.get_wait_time())
attempts-=1
@ -1967,6 +1969,8 @@ def unwrapped_switch_quote_currency(base,quote,new_quote):
if trader.switch_quote_currency(new_quote)==1:
return jsonify({"Error": "Swap failed. Check log files for details."})
del(worker_status[f"{base}/{quote}"])
#Resume the trader
trader.pause = False
return jsonify({"Success": "Mission successful"})

View File

@ -140,6 +140,13 @@ class StatusHandler:
def get_deal_order_history(self):
return self.status_dictionary["deal_order_history"]
def get_status_file_path(self):
return self.status_file_path
def set_status_file_path(self, new_file_path):
self.status_file_path = new_file_path
return 0
def set_tp_order_id(self, order_id: str):
self.status_dictionary["tp_order_id"] = order_id
return 0

View File

@ -13,6 +13,7 @@ Mandatory:
* Status (parameter validation remains to be implemented).
8. Implement the ability to add safety orders to a short trader depending on the amount of free funds available, not just any number of orders.
9. API documentation.
10. Bug when switching quote currency: when switching from USDT to USDC, status script keeps querying for base/USDT.
Would be nice to have:

View File

@ -1373,6 +1373,7 @@ class trader:
#Updates status_dict
self.broker.logger.log_this("Updating status file",2,self.config.get_pair())
self.status.set_status_file_path(f"status/{self.base}{self.quote}.status")
self.update_status(True)
#Done
@ -1400,7 +1401,6 @@ class trader:
#Change broker config file
self.broker.remove_pair_from_config(f"{self.base}{self.quote}")
self.broker.add_pair_to_config(f"{self.base}{new_quote}")
if self.broker.rewrite_config_file()==1:
#Error writing broker config file, undoing changes
self.broker.logger.log_this("Error writing new broker config file",1,self.config.get_pair())
@ -1423,7 +1423,8 @@ class trader:
self.broker.logger.log_this(f"Exception while writing new old_long file: {e}",1,self.config.get_pair())
#Write the new config file
if self.config.save_to_file(f"configs/{self.base}{self.quote}.json")==1:
self.config.set_config_file_path(f"configs/{self.base}{self.quote}.json")
if self.config.save_to_file()==1:
self.broker.logger.log_this(f"Error while writing the new trader config file",1,self.config.get_pair())
#Undoing changes
self.quote_currency_undo_changes(new_quote,old_quote,True)