Check can_short in live-mode as well.

This commit is contained in:
Matthias 2022-03-11 19:43:00 +01:00
parent 20fc9459f2
commit 0aa170ac95
3 changed files with 11 additions and 2 deletions

View File

@ -177,7 +177,8 @@ class StrategyResolver(IResolver):
raise ImportError(
"Short strategies cannot run in spot markets. Please make sure that this "
"is the correct strategy and that your trading mode configuration is correct. "
"You can run this strategy by setting `can_short=False` in your strategy."
"You can run this strategy in spot markets by setting `can_short=False`"
" in your strategy. Please note that short signals will be ignored in that case."
)
@staticmethod

View File

@ -759,7 +759,7 @@ class IStrategy(ABC, HyperStrategyMixin):
enter_long = latest[SignalType.ENTER_LONG.value] == 1
exit_long = latest.get(SignalType.EXIT_LONG.value, 0) == 1
enter_short = latest.get(SignalType.ENTER_SHORT.value, 0) == 1
enter_short = latest.get(SignalType.ENTER_SHORT.value, 0 == 1)
exit_short = latest.get(SignalType.EXIT_SHORT.value, 0) == 1
enter_signal: Optional[SignalDirection] = None
@ -768,6 +768,7 @@ class IStrategy(ABC, HyperStrategyMixin):
enter_signal = SignalDirection.LONG
enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None)
if (self.config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT
and self.can_short
and enter_short == 1 and not any([exit_short, enter_long])):
enter_signal = SignalDirection.SHORT
enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None)

View File

@ -78,6 +78,12 @@ def test_returns_latest_signal(ohlcv_history):
assert _STRATEGY.get_entry_signal('ETH/BTC', '5m', mocked_history) == (None, None)
_STRATEGY.config['trading_mode'] = 'futures'
# Short signal get's ignored as can_short is not set.
assert _STRATEGY.get_entry_signal(
'ETH/BTC', '5m', mocked_history) == (None, None)
_STRATEGY.can_short = True
assert _STRATEGY.get_entry_signal(
'ETH/BTC', '5m', mocked_history) == (SignalDirection.SHORT, 'sell_signal_01')
assert _STRATEGY.get_exit_signal('ETH/BTC', '5m', mocked_history) == (False, False, None)
@ -93,6 +99,7 @@ def test_returns_latest_signal(ohlcv_history):
assert _STRATEGY.get_exit_signal(
'ETH/BTC', '5m', mocked_history, True) == (False, True, 'sell_signal_02')
_STRATEGY.can_short = False
_STRATEGY.config['trading_mode'] = 'spot'