Skip to content

Commit

Permalink
[Modes] reduce_only chained orders when trading futures
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Dec 27, 2024
1 parent ef8fb8f commit c53e8d9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Trading/Mode/daily_trading_mode/daily_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand All @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions Trading/Mode/dca_trading_mode/dca_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,16 @@ 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
if self.trading_mode.use_stop_loss:
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)
Expand All @@ -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)
Expand Down

0 comments on commit c53e8d9

Please sign in to comment.