2025.09.07

This commit is contained in:
Nicolás Sánchez 2025-09-07 18:30:00 -03:00
parent 5cf2979f38
commit bc8d621152
3 changed files with 15 additions and 16 deletions

View File

@ -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.

View File

@ -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

View File

@ -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
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