in check_status: autoswitch prior to check orders
This commit is contained in:
parent
8ad157d17d
commit
d6b6b6d805
38
trader.py
38
trader.py
|
|
@ -964,6 +964,25 @@ class trader:
|
|||
self.update_status(False)
|
||||
return 0
|
||||
|
||||
#Check if short price exceeds old long price. If so, send a Telegram message
|
||||
if self.config.get_is_short() and self.status.get_old_long()!={} and self.config.get_check_old_long_price():
|
||||
self.check_old_long_price()
|
||||
|
||||
self.status.set_pause_reason("check for autoswitch")
|
||||
#If it's a short trader that used to be long AND autoswitch is enabled
|
||||
if self.config.get_is_short() and self.config.get_autoswitch() and self.status.get_old_long()!={}:
|
||||
#If selling the base currency left at the current market price plus the quote already received turns out to be more than the old long deal target,
|
||||
# it means that we already are in profit territory, switch back to long.
|
||||
#A more conservative approach would be old_target = self.status.get_old_long()["quote_spent"], just breaking even.
|
||||
old_target = self.status.get_old_long()["tp_price"]*self.status.get_old_long()["tp_amount"]
|
||||
base_left = self.status.get_old_long()["tp_amount"]-self.status.get_base_bought()
|
||||
if (base_left*self.status.get_price())+self.status.get_quote_spent()>=old_target:
|
||||
#Sell all base (market), report the profits and restart the trader
|
||||
self.status.set_pause_reason("automatic_switch")
|
||||
self.switch_to_long(already_received_quote=self.status.get_quote_spent())
|
||||
self.restart = True
|
||||
return 1
|
||||
|
||||
#Extract ids from order list
|
||||
open_orders_ids = [order["id"] for order in open_orders if order["symbol"]==self.config.get_pair()]
|
||||
|
||||
|
|
@ -1056,25 +1075,6 @@ class trader:
|
|||
self.restart = True
|
||||
return 1
|
||||
|
||||
#Check if short price exceeds old long price. If so, send a Telegram message
|
||||
if self.config.get_is_short() and self.status.get_old_long()!={} and self.config.get_check_old_long_price():
|
||||
self.check_old_long_price()
|
||||
|
||||
self.status.set_pause_reason("check for autoswitch")
|
||||
#If it's a short trader that used to be long AND autoswitch is enabled
|
||||
if self.config.get_is_short() and self.config.get_autoswitch() and self.status.get_old_long()!={}:
|
||||
#If selling the base currency left at the current market price plus the quote already received turns out to be more than the old long deal target,
|
||||
# it means that we already are in profit territory, switch back to long.
|
||||
#A more conservative approach would be old_target = self.status.get_old_long()["quote_spent"], just breaking even.
|
||||
old_target = self.status.get_old_long()["tp_price"]*self.status.get_old_long()["tp_amount"]
|
||||
base_left = self.status.get_old_long()["tp_amount"]-self.status.get_base_bought()
|
||||
if (base_left*self.status.get_price())+self.status.get_quote_spent()>=old_target:
|
||||
#Sell all base (market), report the profits and restart the trader
|
||||
self.status.set_pause_reason("automatic_switch")
|
||||
self.switch_to_long(already_received_quote=self.status.get_quote_spent())
|
||||
self.restart = True
|
||||
return 1
|
||||
|
||||
#Render status line(s)
|
||||
self.status.set_status_string(self.generate_status_strings())
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue