From c53e8d917db60a09a03c31dbb32fd21837362b41 Mon Sep 17 00:00:00 2001 From: Guillaume De Saint Martin Date: Fri, 27 Dec 2024 12:30:11 +0100 Subject: [PATCH] [Modes] reduce_only chained orders when trading futures --- Trading/Mode/daily_trading_mode/daily_trading.py | 7 +++++-- Trading/Mode/dca_trading_mode/dca_trading.py | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Trading/Mode/daily_trading_mode/daily_trading.py b/Trading/Mode/daily_trading_mode/daily_trading.py index a658fc1c2..4d0ffa959 100644 --- a/Trading/Mode/daily_trading_mode/daily_trading.py +++ b/Trading/Mode/daily_trading_mode/daily_trading.py @@ -499,6 +499,8 @@ async def _create_order( chained_orders = [] is_long = current_order.side is trading_enums.TradeOrderSide.BUY exit_side = trading_enums.TradeOrderSide.SELL if is_long else trading_enums.TradeOrderSide.BUY + # tag chained orders as reduce_only when trading futures + reduce_only_chained_orders = self.exchange_manager.is_future if use_stop_loss_orders: if len(stop_loss_details) > 1: self.logger.error(f"Multiple stop loss orders is not supported.") @@ -509,7 +511,8 @@ async def _create_order( ) ) if (not stop_loss_details or stop_loss_details[0].price.is_nan()) else stop_loss_details[0].price param_update, chained_order = await self.register_chained_order( - current_order, stop_price, trading_enums.TraderOrderType.STOP_LOSS, exit_side, tag=tag + current_order, stop_price, trading_enums.TraderOrderType.STOP_LOSS, exit_side, + tag=tag, reduce_only=reduce_only_chained_orders ) params.update(param_update) chained_orders.append(chained_order) @@ -536,7 +539,7 @@ async def _create_order( ) param_update, chained_order = await self.register_chained_order( current_order, take_profit_price, order_type, exit_side, - quantity=take_profits_detail.quantity, tag=tag + quantity=take_profits_detail.quantity, tag=tag, reduce_only=reduce_only_chained_orders ) params.update(param_update) chained_orders.append(chained_order) diff --git a/Trading/Mode/dca_trading_mode/dca_trading.py b/Trading/Mode/dca_trading_mode/dca_trading.py index 523dd7440..2bc2c9b0d 100644 --- a/Trading/Mode/dca_trading_mode/dca_trading.py +++ b/Trading/Mode/dca_trading_mode/dca_trading.py @@ -367,6 +367,7 @@ async def _create_entry_with_chained_exit_orders(self, entry_order, entry_price, symbol_market ) can_bundle_exit_orders = len(exit_quantities) == 1 + reduce_only_chained_orders = self.exchange_manager.is_future for i, exit_quantity in exit_quantities: order_couple = [] # stop loss @@ -374,7 +375,8 @@ async def _create_entry_with_chained_exit_orders(self, entry_order, entry_price, stop_price = trading_personal_data.decimal_adapt_price(symbol_market, stop_price) param_update, chained_order = await self.register_chained_order( entry_order, stop_price, trading_enums.TraderOrderType.STOP_LOSS, exit_side, - quantity=exit_quantity, allow_bundling=can_bundle_exit_orders + quantity=exit_quantity, allow_bundling=can_bundle_exit_orders, + reduce_only=reduce_only_chained_orders ) params.update(param_update) order_couple.append(chained_order) @@ -399,7 +401,8 @@ async def _create_entry_with_chained_exit_orders(self, entry_order, entry_price, ) param_update, chained_order = await self.register_chained_order( entry_order, take_profit_price, take_profit_order_type, None, - quantity=exit_quantity, allow_bundling=can_bundle_exit_orders + quantity=exit_quantity, allow_bundling=can_bundle_exit_orders, + reduce_only=reduce_only_chained_orders ) params.update(param_update) order_couple.append(chained_order)