From bc8d621152d1674ebe5c37575b0499d4a6a4a32b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20S=C3=A1nchez?= Date: Sun, 7 Sep 2025 18:30:00 -0300 Subject: [PATCH] 2025.09.07 --- changelog.txt | 3 +++ main.py | 2 +- trader.py | 26 +++++++++++--------------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/changelog.txt b/changelog.txt index 2c7b780..4f6f105 100755 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +2025.09.07: +. Increased wait time after sending market orders. + 2025.09.05: . Now the trader supports multiple safety orders at the same time. . Removed forcing orders when importing a trader. Maybe it will be reinstated at a later date. diff --git a/main.py b/main.py index 5b284e7..93c3621 100644 --- a/main.py +++ b/main.py @@ -18,7 +18,7 @@ import exchange_wrapper import trader -version = "2025.09.05" +version = "2025.09.07" ''' Color definitions. If you want to change them, check the reference at https://en.wikipedia.org/wiki/ANSI_escape_code#Colors diff --git a/trader.py b/trader.py index 0dcbba7..53ebdab 100755 --- a/trader.py +++ b/trader.py @@ -216,7 +216,7 @@ class trader: #Wait a bit longer, sometimes a recently filled market order is not updated quickly enough. # When that happens, the amount of base taken into account by the trader is lower than the amount bought, # which ends up misrepresenting the trade cost per unit of base, which causes the take profit price to skyrocket. - time.sleep(self.broker.get_wait_time()) + time.sleep(self.broker.get_wait_time()*2) returned_order = self.broker.get_order(first_order["id"],self.status.get_pair()) if returned_order==self.broker.get_empty_order(): self.broker.logger.log_this("Problems with the initial order",1,self.status.get_pair()) @@ -682,13 +682,14 @@ class trader: return 1 #send market order selling the total amount of base in the last take profit short order order = self.broker.new_market_order(self.status.get_pair(),free_base,"sell") + time.sleep(self.broker.get_wait_time()*2) tries = self.broker.get_retries() while True: - time.sleep(self.broker.get_wait_time()) market_tp_order = self.broker.get_order(order["id"],self.status.get_pair()) if market_tp_order["status"]=="closed": _, fees_paid = self.parse_fees(market_tp_order) break + time.sleep(self.broker.get_wait_time()) tries-=1 if tries==0: self.broker.logger.log_this("Liquidation order not filling. Skipping base liquidation",1,self.status.get_pair()) @@ -722,6 +723,7 @@ class trader: #Send the market order amount = self.status.get_take_profit_order()["amount"] market_order = self.broker.new_market_order(self.status.get_pair(),amount,"sell",amount_in_base=True) + time.sleep(self.broker.get_wait_time()*2) #Wait for it to be filled tries = self.broker.get_retries() @@ -730,6 +732,7 @@ class trader: if order["status"]=="closed": break tries-=1 + time.sleep(self.broker.get_wait_time()) if tries==0: self.broker.logger.log_this("Forced market order not filling.",1,self.status.get_pair()) self.quit = True @@ -773,21 +776,14 @@ class trader: partial_filled_price = [] for order in self.status.get_safety_orders(): closed_order = self.broker.get_order(order["id"],self.status.get_pair()) - if closed_order["filled"]==0: - #If this order wasn't filled, it is safe to assume that no order coming after this one was. + if closed_order["filled"]==0: #If this order wasn't filled, it is safe to assume that no order coming after this one was. break - #Sum the filled amounts partial_filled_amount+=closed_order["filled"] partial_filled_price.append(closed_order["average"]) - #Better than this, the total filled and total cost can be used to send a sell market order of the partial filled amount, and add that to the profit. - self.broker.logger.log_this(f"Old safety order is partially filled, ID: {closed_order['id']}, {closed_order['filled']}/{closed_order['amount']} {self.base} filled",1,self.status.get_pair()) - #self.status.set_base_bought(self.status.get_base_bought() + closed_order["filled"] - self.parse_fees(closed_order)[0]) - #self.status.set_quote_spent(self.status.get_quote_spent() + closed_order["cost"]) - #Save the order + self.broker.logger.log_this(f"Old safety order is partially filled, ID: {closed_order['id']}, {closed_order['filled']}/{closed_order['amount']} {self.base} filled",1,self.status.get_pair()) if self.broker.get_follow_order_history(): self.status.update_deal_order_history(closed_order) - if closed_order["remaining"]!=0: - #If this order is not completely filled, it is safe to assume that no order coming after this one was partially filled. + if closed_order["remaining"]!=0: #If this order is not completely filled, it is safe to assume that no order coming after this one was partially filled. break #Now we can clear the safety order list self.status.set_safety_orders([]) @@ -796,12 +792,11 @@ class trader: if not self.status.get_is_short(): #With short traders is just an accounting issue, since when the trader restarts it will be buying cheaper what it sold more expensive in the partially filled safety order(s) if partial_filled_amount!=0 and len(partial_filled_price)>0 and partial_filled_amount>self.broker.get_min_base_size(self.status.get_pair()): - #send a market order and sum the profits + #send a market order and sum the profits and wait for it to be filled market_order = self.broker.new_market_order(self.status.get_pair(),partial_filled_amount,"sell",amount_in_base=True) - #Wait for it to be filled + time.sleep(self.broker.get_wait_time()*2) tries = self.broker.get_retries() while True: - time.sleep(self.broker.get_wait_time()) partial_fill_order = self.broker.get_order(market_order["id"],self.status.get_pair()) if partial_fill_order["status"]=="closed": avg_buy_price = sum(partial_filled_price)/len(partial_filled_price) @@ -809,6 +804,7 @@ class trader: self.status.set_partial_profit(self.status.get_partial_profit()+partial_profit) break tries-=1 + time.sleep(self.broker.get_wait_time()) if tries==0: self.broker.logger.log_this("Partial fill sell order not filling.",1,self.status.get_pair()) break