Skip to content

Commit

Permalink
[TV] Add cancel signal
Browse files Browse the repository at this point in the history
  • Loading branch information
Herklos committed Oct 11, 2023
1 parent dda460a commit ea796d2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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)

0 comments on commit ea796d2

Please sign in to comment.