better handling of concurrent safety orders changes in runtime
This commit is contained in:
parent
16e1994ed1
commit
0dd3077eb5
|
|
@ -17,6 +17,7 @@ logs/gateio.log
|
||||||
logs/kucoin.log
|
logs/kucoin.log
|
||||||
upload_testnet.sh
|
upload_testnet.sh
|
||||||
upload_mainnet.sh
|
upload_mainnet.sh
|
||||||
|
upload_local_testnet.sh
|
||||||
utils/data/binance.db
|
utils/data/binance.db
|
||||||
utils/data/okx.db
|
utils/data/okx.db
|
||||||
utils/data/gateio.db
|
utils/data/gateio.db
|
||||||
|
|
|
||||||
20
trader.py
20
trader.py
|
|
@ -34,6 +34,7 @@ class trader:
|
||||||
self.low_price_cache = None
|
self.low_price_cache = None
|
||||||
self.mid_price_cache = None
|
self.mid_price_cache = None
|
||||||
self.high_price_cache = None
|
self.high_price_cache = None
|
||||||
|
self.concurrent_so_amount_cache = None
|
||||||
|
|
||||||
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.
|
||||||
|
|
@ -1123,7 +1124,7 @@ class trader:
|
||||||
if order["id"] not in open_orders_ids:
|
if order["id"] not in open_orders_ids:
|
||||||
filled_ids.append(order["id"])
|
filled_ids.append(order["id"])
|
||||||
|
|
||||||
if filled_ids!=[]: #WRONG: Once all safety orders are filled, adding no_of_safety_orders won't result in sending new orders.
|
if filled_ids!=[]:
|
||||||
closed_orders = self.broker.get_closed_orders(self.status.get_pair())
|
closed_orders = self.broker.get_closed_orders(self.status.get_pair())
|
||||||
filled_orders = [item for item in closed_orders if item["id"] in filled_ids and item["status"]=="closed"] #maybe item["status"] in ["closed", "canceled", ""]?
|
filled_orders = [item for item in closed_orders if item["id"] in filled_ids and item["status"]=="closed"] #maybe item["status"] in ["closed", "canceled", ""]?
|
||||||
self.status.set_safety_orders_filled(self.status.get_safety_orders_filled()+len(filled_orders))
|
self.status.set_safety_orders_filled(self.status.get_safety_orders_filled()+len(filled_orders))
|
||||||
|
|
@ -1157,6 +1158,17 @@ class trader:
|
||||||
self.restart = True
|
self.restart = True
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
|
#Should we send more safety orders without touching the TP order?
|
||||||
|
#Necessary check if we add to no_of_safety_orders or modify concurrent_safety_orders at runtime
|
||||||
|
max_concurrent_safety_orders = self.config.get_boosted_concurrent_safety_orders() if self.status.get_is_boosted() else self.config.get_concurrent_safety_orders()
|
||||||
|
condition_a = len(self.status.get_safety_orders())<max_concurrent_safety_orders
|
||||||
|
condition_b = self.status.get_safety_orders_filled()+len(self.status.get_safety_orders())<self.status.get_no_of_safety_orders()
|
||||||
|
|
||||||
|
if condition_a and condition_b:
|
||||||
|
amount_to_send = max_concurrent_safety_orders-len(self.status.get_safety_orders())
|
||||||
|
self.send_new_safety_order_batch(amount_to_send)
|
||||||
|
self.update_status(True)
|
||||||
|
|
||||||
#Check for autoswitch (long->short)
|
#Check for autoswitch (long->short)
|
||||||
#Commented out because i'm not sure where this should go
|
#Commented out because i'm not sure where this should go
|
||||||
#if not self.config.get_is_short() and self.status.get_so_amount()==self.status.get_no_of_safety_orders() and self.config.get_autoswitch():
|
#if not self.config.get_is_short() and self.status.get_so_amount()==self.status.get_no_of_safety_orders() and self.config.get_autoswitch():
|
||||||
|
|
@ -1517,8 +1529,9 @@ class trader:
|
||||||
low_price = self.status.get_next_so_price() if self.status.get_next_so_price() is not None else 0
|
low_price = self.status.get_next_so_price() if self.status.get_next_so_price() is not None else 0
|
||||||
mid_price = self.status.get_price() if self.status.get_price() is not None else 0
|
mid_price = self.status.get_price() if self.status.get_price() is not None else 0
|
||||||
high_price = self.status.get_take_profit_price() if self.status.get_take_profit_price() is not None else 0
|
high_price = self.status.get_take_profit_price() if self.status.get_take_profit_price() is not None else 0
|
||||||
|
concurrent_so_amount = len(self.status.get_safety_orders())
|
||||||
|
|
||||||
if low_price==self.low_price_cache and mid_price==self.mid_price_cache and high_price==self.high_price_cache:
|
if low_price==self.low_price_cache and mid_price==self.mid_price_cache and high_price==self.high_price_cache and concurrent_so_amount==self.concurrent_so_amount_cache:
|
||||||
#Only modifies the uptime
|
#Only modifies the uptime
|
||||||
position = self.status.get_status_string().find("Uptime")
|
position = self.status.get_status_string().find("Uptime")
|
||||||
new_uptime = self.seconds_to_time(self.status.get_deal_uptime())
|
new_uptime = self.seconds_to_time(self.status.get_deal_uptime())
|
||||||
|
|
@ -1528,6 +1541,7 @@ class trader:
|
||||||
self.low_price_cache = low_price
|
self.low_price_cache = low_price
|
||||||
self.mid_price_cache = mid_price
|
self.mid_price_cache = mid_price
|
||||||
self.high_price_cache = high_price
|
self.high_price_cache = high_price
|
||||||
|
self.concurrent_so_amount_cache = concurrent_so_amount
|
||||||
|
|
||||||
#Formatting
|
#Formatting
|
||||||
low_boundary = '{:.20f}'.format(low_price)[:decimals].center(decimals)
|
low_boundary = '{:.20f}'.format(low_price)[:decimals].center(decimals)
|
||||||
|
|
@ -1588,7 +1602,7 @@ class trader:
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
safety_order_string = f"{self.status.get_safety_orders_filled()}/{self.get_color('cyan')}{len(self.status.get_safety_orders())}{self.get_color('white')}/{self.status.get_no_of_safety_orders()}".rjust(27)
|
safety_order_string = f"{self.status.get_safety_orders_filled()}/{self.get_color('cyan')}{concurrent_so_amount}{self.get_color('white')}/{self.status.get_no_of_safety_orders()}".rjust(27)
|
||||||
prices = f"{low_boundary_color}{low_boundary}{self.get_color('white')}|{price_color}{mid_boundary}{self.get_color('white')}|{target_price_color}{high_boundary}{self.get_color('white')}|{pct_color}{pct_to_profit_str}%{self.get_color('white')}"
|
prices = f"{low_boundary_color}{low_boundary}{self.get_color('white')}|{price_color}{mid_boundary}{self.get_color('white')}|{target_price_color}{high_boundary}{self.get_color('white')}|{pct_color}{pct_to_profit_str}%{self.get_color('white')}"
|
||||||
line1 = f"{p}{pair_color}{self.status.get_pair().center(13)}{self.get_color('white')}| {safety_order_string} |{prices}| Uptime: {self.seconds_to_time(self.status.get_deal_uptime())}"
|
line1 = f"{p}{pair_color}{self.status.get_pair().center(13)}{self.get_color('white')}| {safety_order_string} |{prices}| Uptime: {self.seconds_to_time(self.status.get_deal_uptime())}"
|
||||||
if self.status.get_is_boosted():
|
if self.status.get_is_boosted():
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue