new trader config option
This commit is contained in:
parent
b3d22c0fa2
commit
82686a04ab
|
|
@ -1,5 +1,6 @@
|
||||||
2024.10.31:
|
2024.10.31:
|
||||||
. Added an option to set the wait time before sending a new safety order.
|
. Added an option to set the wait time before sending a new safety order.
|
||||||
|
. Added a per-trader option to enable or disable slippage checks.
|
||||||
|
|
||||||
2024.10.30:
|
2024.10.30:
|
||||||
. Changes trying to catch the wrong base amount bug.
|
. Changes trying to catch the wrong base amount bug.
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
"safety_order_scale": 0.0105, #Size multiplier of every subsequent safety order. (check strategy documentation for more details)
|
"safety_order_scale": 0.0105, #Size multiplier of every subsequent safety order. (check strategy documentation for more details)
|
||||||
"write_logs": false, #Write logs to file.
|
"write_logs": false, #Write logs to file.
|
||||||
"calculate_fees": true, #Take into account the fees when calculating profits.
|
"calculate_fees": true, #Take into account the fees when calculating profits.
|
||||||
|
"check_slippage": true, #Slippage checks before sending orders.
|
||||||
"cleanup": true, #Execute the cleanup routine every trader (re)start.
|
"cleanup": true, #Execute the cleanup routine every trader (re)start.
|
||||||
"telegram": true, #Send Telegram notifications.
|
"telegram": true, #Send Telegram notifications.
|
||||||
"tp_mode": 3, #Take profit mode. (check strategy documentation for more details)
|
"tp_mode": 3, #Take profit mode. (check strategy documentation for more details)
|
||||||
|
|
|
||||||
1
todo.txt
1
todo.txt
|
|
@ -5,7 +5,6 @@ Mandatory:
|
||||||
2. Instead of giving a list of order_ids to each trader, give a list of the open orders and that's it (for easier future development, partial order fills for example)
|
2. Instead of giving a list of order_ids to each trader, give a list of the open orders and that's it (for easier future development, partial order fills for example)
|
||||||
3. Deploying script, both for testnet and for mainnet.
|
3. Deploying script, both for testnet and for mainnet.
|
||||||
4. Maintain local orderbooks for each trading pair.
|
4. Maintain local orderbooks for each trading pair.
|
||||||
5. Global option for slippage checks.
|
|
||||||
|
|
||||||
|
|
||||||
Would be nice to have:
|
Would be nice to have:
|
||||||
|
|
|
||||||
49
trader.py
49
trader.py
|
|
@ -24,6 +24,9 @@ class trader:
|
||||||
self.max_short_safety_orders = 45
|
self.max_short_safety_orders = 45
|
||||||
if "max_short_safety_orders" in config_dict:
|
if "max_short_safety_orders" in config_dict:
|
||||||
self.max_short_safety_orders = config_dict["max_short_safety_orders"]
|
self.max_short_safety_orders = config_dict["max_short_safety_orders"]
|
||||||
|
self.check_slippage = True
|
||||||
|
if "check_slippage" in self.config_dict:
|
||||||
|
self.check_slippage = self.config_dict["check_slippage"]
|
||||||
self.start_time = int(time.time())
|
self.start_time = int(time.time())
|
||||||
self.total_amount_of_quote=0
|
self.total_amount_of_quote=0
|
||||||
self.total_amount_of_base=1
|
self.total_amount_of_base=1
|
||||||
|
|
@ -192,12 +195,13 @@ class trader:
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#check slippage
|
#check slippage
|
||||||
self.broker.logger.log_this("Checking slippage...",2,self.pair)
|
if self.check_slippage:
|
||||||
self.status_dict["pause_reason"] = "start_bot - checking slippage"
|
self.broker.logger.log_this("Checking slippage...",2,self.pair)
|
||||||
if self.check_orderbook_depth(self.broker.get_slippage_default_threshold(),self.config_dict["order_size"]):
|
self.status_dict["pause_reason"] = "start_bot - checking slippage"
|
||||||
#Slippage threshold exceeded
|
if self.check_orderbook_depth(self.broker.get_slippage_default_threshold(),self.config_dict["order_size"]):
|
||||||
self.broker.logger.log_this("Slippage threshold exceeded",1,self.pair)
|
#Slippage threshold exceeded
|
||||||
return 3
|
self.broker.logger.log_this("Slippage threshold exceeded",1,self.pair)
|
||||||
|
return 3
|
||||||
|
|
||||||
self.status_dict["pause_reason"] = "start_bot - after slippage"
|
self.status_dict["pause_reason"] = "start_bot - after slippage"
|
||||||
self.status_dict["order_size"] = self.config_dict["order_size"]
|
self.status_dict["order_size"] = self.config_dict["order_size"]
|
||||||
|
|
@ -914,22 +918,23 @@ class trader:
|
||||||
#self.safety_order_index = 0
|
#self.safety_order_index = 0
|
||||||
self.config_dict = self.reload_config_dict()
|
self.config_dict = self.reload_config_dict()
|
||||||
|
|
||||||
self.broker.logger.log_this("Checking slippage...",2,self.pair)
|
if self.check_slippage:
|
||||||
price_to_compare = self.broker.get_top_bid_price(self.pair) if self.is_short else self.broker.get_top_ask_price(self.pair)
|
self.broker.logger.log_this("Checking slippage...",2,self.pair)
|
||||||
if abs(filled_order["price"]-price_to_compare)/filled_order["price"]>self.broker.get_slippage_default_threshold():
|
price_to_compare = self.broker.get_top_bid_price(self.pair) if self.is_short else self.broker.get_top_ask_price(self.pair)
|
||||||
self.broker.logger.log_this(f"Slippage threshold exceeded, waiting for cooldown and restarting pair",1,self.pair)
|
if abs(filled_order["price"]-price_to_compare)/filled_order["price"]>self.broker.get_slippage_default_threshold():
|
||||||
time.sleep(self.broker.get_wait_time()*self.broker.get_cooldown_multiplier())
|
self.broker.logger.log_this(f"Slippage threshold exceeded, waiting for cooldown and restarting pair",1,self.pair)
|
||||||
#The trader is restarted by the instance instead of by itself to allow a couple of more seconds for the price to return to normal.
|
time.sleep(self.broker.get_wait_time()*self.broker.get_cooldown_multiplier())
|
||||||
#This could also be the default behavior.
|
#The trader is restarted by the instance instead of by itself to allow a couple of more seconds for the price to return to normal.
|
||||||
self.pause = False
|
#This could also be the default behavior.
|
||||||
self.restart = True
|
self.pause = False
|
||||||
return 1
|
self.restart = True
|
||||||
elif self.check_orderbook_depth(self.broker.get_slippage_default_threshold(),self.config_dict["order_size"],filled_order["price"]):
|
return 1
|
||||||
self.broker.logger.log_this(f"Orderbook depth not sufficient, waiting for cooldown and restarting pair",1,self.pair)
|
elif self.check_orderbook_depth(self.broker.get_slippage_default_threshold(),self.config_dict["order_size"],filled_order["price"]):
|
||||||
time.sleep(self.broker.get_wait_time()*self.broker.get_cooldown_multiplier())
|
self.broker.logger.log_this(f"Orderbook depth not sufficient, waiting for cooldown and restarting pair",1,self.pair)
|
||||||
self.pause = False
|
time.sleep(self.broker.get_wait_time()*self.broker.get_cooldown_multiplier())
|
||||||
self.restart = True
|
self.pause = False
|
||||||
return 1
|
self.restart = True
|
||||||
|
return 1
|
||||||
|
|
||||||
#Restarting the trader
|
#Restarting the trader
|
||||||
self.status_dict["pause_reason"] = "take_profit_routine - restart_bot call"
|
self.status_dict["pause_reason"] = "take_profit_routine - restart_bot call"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue