2025.10.01

This commit is contained in:
Nicolás Sánchez 2025-10-01 15:07:17 -03:00
parent 0576f93477
commit c42a505e49
3 changed files with 36 additions and 8 deletions

View File

@ -1,3 +1,6 @@
2025.10.01:
. Fixed base fees not being taken into account.
2025.09.27: 2025.09.27:
. Added notes in every entry of deal_order_history. . Added notes in every entry of deal_order_history.
. Minor refactor in renew_tp_and_so_routine. . Minor refactor in renew_tp_and_so_routine.

View File

@ -18,7 +18,7 @@ import exchange_wrapper
import trader import trader
version = "2025.09.27" version = "2025.10.01"
''' '''
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

View File

@ -31,6 +31,13 @@ class trader:
self.market_reload_period = 86400 #Market reload period in seconds self.market_reload_period = 86400 #Market reload period in seconds
self.status.set_start_time(int(time.time())) self.status.set_start_time(int(time.time()))
self.last_time_seen = time.time() self.last_time_seen = time.time()
self.base_diff_check = False
self.min_base_difference = .1 #Percentage difference between base in the tp order and its adjusted amount that triggers a recheck.
#The exchanges sometimes take a few seconds to update the balance after an order is closed.
self.base_check_interval = 60 #In seconds
self.base_check_time = 0
self.base_amount_missing = 0
if self.config.get_is_short(): if self.config.get_is_short():
#Check if there is an old_long file. If so, load it. #Check if there is an old_long file. If so, load it.
@ -437,8 +444,8 @@ class trader:
if self.config.get_is_short(): #Short traders do not need cleanup if self.config.get_is_short(): #Short traders do not need cleanup
return 0 return 0
balance_to_clean = self.fetch_free_base() balance_in_account = self.fetch_free_base()
if balance_to_clean is None: if balance_in_account is None:
self.broker.logger.log_this("Can't fetch free base",1,self.status.get_pair()) self.broker.logger.log_this("Can't fetch free base",1,self.status.get_pair())
return 1 return 1
@ -446,10 +453,10 @@ class trader:
# Sometimes when an order is filled the balance is not updated immediately, so having a bit of a buffer irons out a couple of issues. # Sometimes when an order is filled the balance is not updated immediately, so having a bit of a buffer irons out a couple of issues.
min_size = self.status.get_safety_orders()[0]["amount"] min_size = self.status.get_safety_orders()[0]["amount"]
if (balance_to_clean-min_size)*self.status.get_start_price()>self.broker.get_min_quote_size(self.status.get_pair()): if (balance_in_account-min_size)*self.status.get_start_price()>self.broker.get_min_quote_size(self.status.get_pair()):
self.broker.logger.log_this(f"Balance to clean: {balance_to_clean-min_size} {self.base}",2,self.status.get_pair()) self.broker.logger.log_this(f"Balance to clean: {balance_in_account-min_size} {self.base}",2,self.status.get_pair())
self.broker.logger.log_this("Sending cleanup order...",2,self.status.get_pair()) self.broker.logger.log_this("Sending cleanup order...",2,self.status.get_pair())
cleanup_order = self.broker.new_limit_order(self.status.get_pair(),balance_to_clean-min_size,"sell",self.status.get_take_profit_price(),no_retries=True) cleanup_order = self.broker.new_limit_order(self.status.get_pair(),balance_in_account-min_size,"sell",self.status.get_take_profit_price(),no_retries=True)
if cleanup_order is None: if cleanup_order is None:
self.broker.logger.log_this("Problems with the cleanup order, new_limit_order returned None",1,self.status.get_pair()) self.broker.logger.log_this("Problems with the cleanup order, new_limit_order returned None",1,self.status.get_pair())
return 1 return 1
@ -970,7 +977,7 @@ class trader:
safety_orders_to_remove_by_id.append(order["id"]) safety_orders_to_remove_by_id.append(order["id"])
new_fees_base, new_fees_quote = self.parse_fees(order) new_fees_base, new_fees_quote = self.parse_fees(order)
previous_fees_paid_in_quote += new_fees_quote previous_fees_paid_in_quote += new_fees_quote
previous_base += order["filled"] previous_base = previous_base + order["filled"] - new_fees_base
previous_quote += order["cost"] previous_quote += order["cost"]
self.status.set_base_bought(previous_base) self.status.set_base_bought(previous_base)
self.status.set_quote_spent(previous_quote) self.status.set_quote_spent(previous_quote)
@ -1236,6 +1243,10 @@ class trader:
self.set_pause(False) self.set_pause(False)
self.update_status(True) self.update_status(True)
#Base check
if self.base_diff_check and time.time()>self.base_check_time+self.base_check_interval:
self.base_check()
#Render status line(s) #Render status line(s)
self.status.set_status_string(self.generate_status_strings()) self.status.set_status_string(self.generate_status_strings())
@ -1248,6 +1259,14 @@ class trader:
return 0 return 0
def base_check(self):
self.base_check_time = time.time()
current_base_balance = self.fetch_free_base()
#3. If self.base_amount_missing==current_base_balance: replace take profit order
#4. Set self.base_diff_check to False
def check_boosted(self): def check_boosted(self):
''' '''
Checks if the trader qualifies for boost: Checks if the trader qualifies for boost:
@ -1333,11 +1352,17 @@ class trader:
else: else:
self.status.set_take_profit_price(self.status.get_quote_spent()/self.status.get_base_bought()*self.get_tp_level(self.status.get_so_amount())) self.status.set_take_profit_price(self.status.get_quote_spent()/self.status.get_base_bought()*self.get_tp_level(self.status.get_so_amount()))
self.status.set_take_profit_order(self.broker.new_limit_order(self.status.get_pair(),self.status.get_base_bought(),"sell",self.status.get_take_profit_price())) self.status.set_take_profit_order(self.broker.new_limit_order(self.status.get_pair(),self.status.get_base_bought(),"sell",self.status.get_take_profit_price()))
if self.status.get_take_profit_order()==1: #This means that there was a miscalculation of base currency amount, let's correct it. if self.status.get_take_profit_order()==1: #This means that there was a miscalculation of base currency amount
if self.config.get_is_short(): #If in short mode, we don't recalculate anything. if self.config.get_is_short(): #If in short mode, we don't recalculate anything.
return 1 return 1
adjusted = self.adjust_base() adjusted = self.adjust_base()
if adjusted is not None: if adjusted is not None:
# if self.status.get_base_bought()-adjusted>=adjusted*self.min_base_difference:
# #Enabling base check
# self.broker.logger.log_this("Enabling base check",1,self.status.get_pair())
# self.base_diff_check = True
# self.base_check_time = time.time()
# self.base_amount_missing = self.status.get_base_bought()-adjusted
self.status.set_base_bought(adjusted) self.status.set_base_bought(adjusted)
self.status.set_take_profit_order(None) #Just to be able to iterate self.status.set_take_profit_order(None) #Just to be able to iterate
if self.status.get_take_profit_order() not in [None,self.broker.get_empty_order()]: if self.status.get_take_profit_order() not in [None,self.broker.get_empty_order()]: