partial SO fills

This commit is contained in:
Nicolás Sánchez 2024-11-10 23:42:28 -03:00
parent cfc634a447
commit 1670ecefff
1 changed files with 2 additions and 23 deletions

View File

@ -820,34 +820,13 @@ class trader:
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
#Suggestion: Would it be feasible to send a market sell order for the amount of base bought on the old safety order?
#Or is it better to leave this amount of change to the cleanup routine?
if not self.is_short and self.so["id"]!="" and not already_counted:
old_so_order = self.broker.get_order(self.so["id"],self.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.pair)
self.status_dict["deal_order_history"].append(old_so_order)
#Uncomment the next two lines if you do not want to ignore the partial fill.
#Keep them commented out if you want to send a market sell order.
#self.total_amount_of_base = self.total_amount_of_base + old_so_order["filled"]
#self.total_amount_of_quote = self.total_amount_of_quote + old_so_order["cost"]
#Hypothetical market order code below:
#If there is not enough base for an order, we'll accumulate it and let the cleanup routine deal with that.
# floor_amount = self.broker.get_min_base_size(self.pair)
# if floor_amount is not None and old_so_order["filled"]>floor_amount:
# self.broker.logger.log_this(f"Sending sell order for partially filled funds: {old_so_order["filled"]} {self.base}",1,self.pair)
# loose_change_order = broker.new_market_order(self.pair,old_so_order["filled"],"sell",amount_in_base=True)
# retries = self.broker.get_retries()
# while retries>0:
# time.sleep(self.broker.get_wait_time())
# order_to_fill = self.broker.get_order(loose_change_order["id"],self.pair)
# if order_to_fill["status"]=="closed" and order_to_fill["filled"]>0:
# profit_with_fees = order_to_fill["filled"]-old_so_order["cost"]-self.parse_fees(order_to_fill)[1]
# self.broker.logger.log_this(f"Trader closed a loose change deal. Profit: {profit_with_fees} {self.quote}",0,self.pair)
# if profit_with_fees>0:
# self.profit_to_file(profit_with_fees,order_to_fill["id"])
# retries-=1
self.total_amount_of_base = self.total_amount_of_base + old_so_order["filled"] - self.parse_fees(old_so_order)[0]
self.total_amount_of_quote = self.total_amount_of_quote + old_so_order["cost"]
if not self.broker.check_for_duplicate_profit_in_db(filled_order):
self.status_dict["pause_reason"] = "calculating profit"