2025.08.17

This commit is contained in:
Nicolás Sánchez 2025-08-17 13:03:13 -03:00
parent 9855c64d81
commit d922bbe06f
5 changed files with 25 additions and 16 deletions

View File

@ -1,3 +1,6 @@
2025.08.17:
. Minor refactorings.
2025.08.16:
. Improved threading.

View File

@ -18,7 +18,7 @@ import exchange_wrapper
import trader
version = "2025.08.16"
version = "2025.08.17"
'''
Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
@ -36,8 +36,8 @@ white = "\033[0;37;40m"
MAX_WORKERS = 35
executor = None
def shutdown_handler(signum, frame):
broker.logger.log_this(f"Received signal {signum}, shutting down as gracefully as possible...", 0)
def shutdown_handler(signum, _):
broker.logger.log_this(f"Received signal {signum}, shutting down as gracefully as possible...", 2)
if executor:
executor.shutdown(wait=True, timeout=5)
os_exit(0)
@ -1351,7 +1351,6 @@ def reload_trader_config():
def run_API():
serve(base_api, host="0.0.0.0", port=broker.get_config()["port"])
#base_api.run(host="0.0.0.0", port=broker.get_config()["port"])

View File

@ -389,8 +389,7 @@ class StatusHandler:
def update_deal_order_history(self, new_deal: dict):
# if not isinstance(new_deal, dict):
# self.broker.logger.log_this(f"value provided is not a dict",1,self.get_pair())
if not self.broker.get_follow_order_history():
self.status_dictionary["deal_order_history"].append(self.strip_order(new_deal))
self.status_dictionary["deal_order_history"].append(self.strip_order(new_deal))
return 0
def strip_order(self, order):

View File

@ -245,8 +245,9 @@ class trader:
return 2
#Save the order
self.status.set_pause_reason("start_trader - saving the order in deal_order_history")
self.status.update_deal_order_history(returned_order)
if self.broker.follow_order_history:
self.status.set_pause_reason("start_trader - saving the order in deal_order_history")
self.status.update_deal_order_history(returned_order)
# Reset the fee count and sum fees from the first order
self.status.set_fees_paid_in_base(self.parse_fees(returned_order)[0])
@ -717,8 +718,10 @@ class trader:
self.pause = True #To stop the main thread to iterate through this trader's orders (just in case)
self.status.set_pause_reason("take_profit_routine - order handling") #start_trader will set this flag to False again once it starts
#Add the timestamp to the deals cache
#Add the timestamp to the deals cache and trims it
self.deals_timestamps.append(time.time())
self.deals_timestamps = self.deals_timestamps[-self.config.get_boosted_deals_range():]
#Let's do some type checking first
if self.status.get_take_profit_order() is None:
@ -732,8 +735,9 @@ class trader:
self.broker.logger.log_this("Error. Safety order is None",1,self.config.get_pair())
self.status.set_safety_order(self.broker.get_empty_order())
#Save the order
self.status.update_deal_order_history(filled_order)
#Save the order in history.
if self.broker.get_follow_order_history():
self.status.update_deal_order_history(filled_order)
# Cancel the current safety order (first check if there is something to cancel)
already_counted = False
@ -746,7 +750,8 @@ class trader:
self.status.set_base_bought(self.status.get_base_bought() + closed_order["filled"])
self.status.set_quote_spent(self.status.get_quote_spent() + closed_order["cost"])
#Save the order
self.status.update_deal_order_history(closed_order)
if self.broker.get_follow_order_history():
self.status.update_deal_order_history(closed_order)
already_counted = True
#IF NOT SHORT - Check if the SO was partially filled. If so, add the amounts to total_amount_of_base and total_amount_of_quote
@ -754,7 +759,8 @@ class trader:
old_so_order = self.broker.get_order(self.status.get_safety_order()["id"],self.config.get_pair())
if old_so_order["filled"]>0:
self.broker.logger.log_this(f"Old safety order is partially filled, ID: {old_so_order['id']}",1,self.config.get_pair())
self.status.update_deal_order_history(old_so_order)
if self.broker.get_follow_order_history():
self.status.update_deal_order_history(old_so_order)
self.status.set_base_bought(self.status.get_base_bought() + old_so_order["filled"] - self.parse_fees(old_so_order)[0])
self.status.set_quote_spent(self.status.get_quote_spent() + old_so_order["cost"])
@ -849,7 +855,8 @@ class trader:
self.status.set_pause_reason("new_so_routine")
# Save the order
self.status.update_deal_order_history(filled_order)
if self.broker.get_follow_order_history():
self.status.update_deal_order_history(filled_order)
# Add the amount filled in the last safety order to the totals
new_fees_base,new_fees_quote = self.parse_fees(filled_order)
@ -885,7 +892,8 @@ class trader:
old_tp_order = self.broker.get_order(self.status.get_take_profit_order()["id"],self.config.get_pair())
if old_tp_order["filled"]>0:
self.broker.logger.log_this(f"Old take profit order is partially filled, id {old_tp_order['id']}",1,self.config.get_pair())
self.status.update_deal_order_history(old_tp_order)
if self.broker.get_follow_order_history():
self.status.update_deal_order_history(old_tp_order)
#self.status.set_base_bought(old_tp_order["remaining"])
# Partial profit calculation
#if not self.config.get_is_short():

View File

@ -614,7 +614,7 @@ if __name__=="__main__":
#Waitress
logger = logging.getLogger('waitress')
logger.setLevel(logging.INFO)
serve(stats_api,host="0.0.0.0",port=5010, threads=32)
serve(stats_api,host="0.0.0.0",port=5010)
#Flask
# app.run(host="0.0.0.0", port=5010, debug=True)