diff --git a/Trading/Mode/trading_view_signals_trading_mode/resources/TradingViewSignalsTradingMode.md b/Trading/Mode/trading_view_signals_trading_mode/resources/TradingViewSignalsTradingMode.md index b25260d42..755687328 100644 --- a/Trading/Mode/trading_view_signals_trading_mode/resources/TradingViewSignalsTradingMode.md +++ b/Trading/Mode/trading_view_signals_trading_mode/resources/TradingViewSignalsTradingMode.md @@ -32,6 +32,17 @@ or a % of available holdings associated to all configured trading pairs assets ( When not specified, orders volume and price are automatically computed based on the current asset price and holdings. +It also takes cancel order signal with the following format: +``` bash +EXCHANGE=binance +SYMBOL=ETHBTC +ORDER_TYPE=CANCEL +``` + +Additional cancel parameters are available: +- `PARAM_SIDE` is the side of the order to cancel, it can be `buy` or `sell` to only cancel buy or sell orders. + + Additional data in the Trading View signal data will not be processed. This Trading mode is not using any strategy or evaluator and won't create stop losses. diff --git a/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py b/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py index ad9a4289c..6779c903b 100644 --- a/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py +++ b/Trading/Mode/trading_view_signals_trading_mode/trading_view_signals_trading.py @@ -44,6 +44,8 @@ class TradingViewSignalsTradingMode(trading_modes.AbstractTradingMode): SELL_SIGNAL = "sell" MARKET_SIGNAL = "market" LIMIT_SIGNAL = "limit" + CANCEL_SIGNAL = "cancel" + SIDE_PARAM_KEY = "SIDE" def __init__(self, config, exchange_manager): super().__init__(config, exchange_manager) @@ -219,6 +221,8 @@ async def _parse_order_details(self, ctx, parsed_data): else: state = trading_enums.EvaluatorStates.VERY_LONG if self.trading_mode.USE_MARKET_ORDERS \ else trading_enums.EvaluatorStates.LONG + elif side == TradingViewSignalsTradingMode.CANCEL_SIGNAL: + state = trading_enums.EvaluatorStates.NEUTRAL else: self.logger.error(f"Unknown signal: {parsed_data[TradingViewSignalsTradingMode.SIGNAL_KEY]}, " f"full data= {parsed_data}") @@ -280,3 +284,12 @@ async def _set_state(self, cryptocurrency: str, symbol: str, new_state, order_da # send_notification if not self.exchange_manager.is_backtesting: await self._send_alert_notification(symbol, new_state) + elif self.trading_mode.consumers: + cancel_order_raw_side = order_data.get( + TradingViewSignalsModeConsumer.ORDER_EXCHANGE_CREATION_PARAMS, {}).get( + TradingViewSignalsTradingMode.SIDE_PARAM_KEY, None) + cancel_order_side = trading_enums.TradeOrderSide.BUY if cancel_order_raw_side == trading_enums.TradeOrderSide.BUY.value \ + else trading_enums.TradeOrderSide.SELL if cancel_order_raw_side == trading_enums.TradeOrderSide.SELL.value else None + + # cancel open orders + await self.cancel_symbol_open_orders(symbol, side=cancel_order_side)