Check can_short in live-mode as well.
This commit is contained in:
parent
20fc9459f2
commit
0aa170ac95
@ -177,7 +177,8 @@ class StrategyResolver(IResolver):
|
|||||||
raise ImportError(
|
raise ImportError(
|
||||||
"Short strategies cannot run in spot markets. Please make sure that this "
|
"Short strategies cannot run in spot markets. Please make sure that this "
|
||||||
"is the correct strategy and that your trading mode configuration is correct. "
|
"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
|
@staticmethod
|
||||||
|
@ -759,7 +759,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
|
|
||||||
enter_long = latest[SignalType.ENTER_LONG.value] == 1
|
enter_long = latest[SignalType.ENTER_LONG.value] == 1
|
||||||
exit_long = latest.get(SignalType.EXIT_LONG.value, 0) == 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
|
exit_short = latest.get(SignalType.EXIT_SHORT.value, 0) == 1
|
||||||
|
|
||||||
enter_signal: Optional[SignalDirection] = None
|
enter_signal: Optional[SignalDirection] = None
|
||||||
@ -768,6 +768,7 @@ class IStrategy(ABC, HyperStrategyMixin):
|
|||||||
enter_signal = SignalDirection.LONG
|
enter_signal = SignalDirection.LONG
|
||||||
enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None)
|
enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None)
|
||||||
if (self.config.get('trading_mode', TradingMode.SPOT) != TradingMode.SPOT
|
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])):
|
and enter_short == 1 and not any([exit_short, enter_long])):
|
||||||
enter_signal = SignalDirection.SHORT
|
enter_signal = SignalDirection.SHORT
|
||||||
enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None)
|
enter_tag_value = latest.get(SignalTagType.ENTER_TAG.value, None)
|
||||||
|
@ -78,6 +78,12 @@ def test_returns_latest_signal(ohlcv_history):
|
|||||||
assert _STRATEGY.get_entry_signal('ETH/BTC', '5m', mocked_history) == (None, None)
|
assert _STRATEGY.get_entry_signal('ETH/BTC', '5m', mocked_history) == (None, None)
|
||||||
|
|
||||||
_STRATEGY.config['trading_mode'] = 'futures'
|
_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(
|
assert _STRATEGY.get_entry_signal(
|
||||||
'ETH/BTC', '5m', mocked_history) == (SignalDirection.SHORT, 'sell_signal_01')
|
'ETH/BTC', '5m', mocked_history) == (SignalDirection.SHORT, 'sell_signal_01')
|
||||||
assert _STRATEGY.get_exit_signal('ETH/BTC', '5m', mocked_history) == (False, False, None)
|
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(
|
assert _STRATEGY.get_exit_signal(
|
||||||
'ETH/BTC', '5m', mocked_history, True) == (False, True, 'sell_signal_02')
|
'ETH/BTC', '5m', mocked_history, True) == (False, True, 'sell_signal_02')
|
||||||
|
|
||||||
|
_STRATEGY.can_short = False
|
||||||
_STRATEGY.config['trading_mode'] = 'spot'
|
_STRATEGY.config['trading_mode'] = 'spot'
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user