feat: Allow strategies to not define enter_long

This commit is contained in:
Matthias
2024-10-07 20:28:24 +02:00
parent fe8eabda37
commit 52304b37a2
2 changed files with 2 additions and 11 deletions

View File

@@ -1133,8 +1133,6 @@ class IStrategy(ABC, HyperStrategyMixin):
message = ""
if dataframe is None:
message = "No dataframe returned (return statement missing?)."
elif "enter_long" not in dataframe:
message = "enter_long/buy column not set."
elif df_len != len(dataframe):
message = message_template.format("length")
elif df_close != dataframe["close"].iloc[-1]:
@@ -1206,7 +1204,7 @@ class IStrategy(ABC, HyperStrategyMixin):
exit_ = latest.get(SignalType.EXIT_SHORT.value, 0) == 1
else:
enter = latest[SignalType.ENTER_LONG.value] == 1
enter = latest.get(SignalType.ENTER_LONG.value, 0) == 1
exit_ = latest.get(SignalType.EXIT_LONG.value, 0) == 1
exit_tag = latest.get(SignalTagType.EXIT_TAG.value, None)
# Tags can be None, which does not resolve to False.
@@ -1235,7 +1233,7 @@ class IStrategy(ABC, HyperStrategyMixin):
if latest is None or latest_date is None:
return None, None
enter_long = latest[SignalType.ENTER_LONG.value] == 1
enter_long = latest.get(SignalType.ENTER_LONG.value, 0) == 1
exit_long = latest.get(SignalType.EXIT_LONG.value, 0) == 1
enter_short = latest.get(SignalType.ENTER_SHORT.value, 0) == 1
exit_short = latest.get(SignalType.EXIT_SHORT.value, 0) == 1

View File

@@ -296,13 +296,6 @@ def test_assert_df(ohlcv_history, caplog):
ohlcv_history.loc[df_len, "close"],
ohlcv_history.loc[0, "date"],
)
with pytest.raises(StrategyError, match="enter_long/buy column not set."):
_STRATEGY.assert_df(
ohlcv_history.drop("enter_long", axis=1),
len(ohlcv_history),
ohlcv_history.loc[df_len, "close"],
ohlcv_history.loc[0, "date"],
)
_STRATEGY.disable_dataframe_checks = True
caplog.clear()