2025.08.17
This commit is contained in:
parent
9855c64d81
commit
d922bbe06f
|
|
@ -1,3 +1,6 @@
|
|||
2025.08.17:
|
||||
. Minor refactorings.
|
||||
|
||||
2025.08.16:
|
||||
. Improved threading.
|
||||
|
||||
|
|
|
|||
7
main.py
7
main.py
|
|
@ -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"])
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -389,7 +389,6 @@ 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))
|
||||
return 0
|
||||
|
||||
|
|
|
|||
12
trader.py
12
trader.py
|
|
@ -245,6 +245,7 @@ class trader:
|
|||
return 2
|
||||
|
||||
#Save the 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)
|
||||
|
||||
|
|
@ -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,7 +735,8 @@ 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
|
||||
#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)
|
||||
|
|
@ -746,6 +750,7 @@ 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
|
||||
if self.broker.get_follow_order_history():
|
||||
self.status.update_deal_order_history(closed_order)
|
||||
already_counted = True
|
||||
|
||||
|
|
@ -754,6 +759,7 @@ 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())
|
||||
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,6 +855,7 @@ class trader:
|
|||
self.status.set_pause_reason("new_so_routine")
|
||||
|
||||
# Save the 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
|
||||
|
|
@ -885,6 +892,7 @@ 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())
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue