Skip to content

Commit

Permalink
[DCA] Add cancel orders at startup option
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Oct 11, 2023
1 parent dda460a commit 15266c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Trading/Mode/dca_trading_mode/config/DCATradingMode.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"use_secondary_entry_orders": false,
"use_secondary_exit_orders": false,
"use_stop_losses": false,
"use_take_profit_exit_orders": false
"use_take_profit_exit_orders": false,
"cancel_open_orders_at_each_entry": true
}
23 changes: 17 additions & 6 deletions Trading/Mode/dca_trading_mode/dca_trading.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,15 @@ async def create_new_orders(self, symbol, _, state, **kwargs):
else:
initial_available_funds = current_market_holding \
if side is trading_enums.TradeOrderSide.BUY else current_symbol_holding
# cancel existing DCA orders from previous iterations
existing_orders = [
order
for order in self.exchange_manager.exchange_personal_data.orders_manager.get_open_orders(symbol=symbol)
if not (order.is_cancelled() or order.is_closed()) and side is order.side
]

existing_orders = []
if self.trading_mode.cancel_open_orders_at_each_entry:
# cancel existing DCA orders from previous iterations
existing_orders = [
order
for order in self.exchange_manager.exchange_personal_data.orders_manager.get_open_orders(symbol=symbol)
if not (order.is_cancelled() or order.is_closed()) and side is order.side
]

secondary_quantity = None
if user_amount := trading_modes.get_user_selected_order_amount(self.trading_mode,
Expand Down Expand Up @@ -315,6 +318,7 @@ async def can_create_order(self, symbol, state):
class DCATradingModeProducer(trading_modes.AbstractTradingModeProducer):
MINUTES_BEFORE_NEXT_BUY = "minutes_before_next_buy"
TRIGGER_MODE = "trigger_mode"
CANCEL_OPEN_ORDERS_AT_EACH_ENTRY = "cancel_open_orders_at_each_entry"

def __init__(self, channel, config, trading_mode, exchange_manager):
super().__init__(channel, config, trading_mode, exchange_manager)
Expand Down Expand Up @@ -480,6 +484,8 @@ def __init__(self, config, exchange_manager):
self.use_stop_loss = False
self.stop_loss_price_multiplier = DCATradingModeConsumer.DEFAULT_STOP_LOSS_ORDERS_PRICE_MULTIPLIER

self.cancel_open_orders_at_each_entry = True

def init_user_inputs(self, inputs: dict) -> None:
"""
Called right before starting the tentacle, should define all the tentacle's user inputs unless
Expand Down Expand Up @@ -642,6 +648,11 @@ def init_user_inputs(self, inputs: dict) -> None:
)
)) / trading_constants.ONE_HUNDRED

self.cancel_open_orders_at_each_entry = self.UI.user_input(
DCATradingModeProducer.CANCEL_OPEN_ORDERS_AT_EACH_ENTRY, commons_enums.UserInputTypes.BOOLEAN, self.cancel_open_orders_at_each_entry, inputs,
title="Cancel open orders on each entry: cancel existing orders from previous iteration on each entry.",
)

@classmethod
def get_is_symbol_wildcard(cls) -> bool:
return False
Expand Down

0 comments on commit 15266c1

Please sign in to comment.