Skip to content

Commit

Permalink
make should_cancel_entry optional
Browse files Browse the repository at this point in the history
  • Loading branch information
saleh-mir committed Nov 7, 2024
1 parent c054612 commit 1e935a8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions jesse/modes/backtest_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ def _prepare_routes(hyperparameters: dict = None) -> None:
r.strategy = StrategyClass()
except TypeError:
raise exceptions.InvalidStrategy(
"Looks like the structure of your strategy directory is incorrect. Make sure to include the strategy INSIDE the __init__.py file. Another reason for this error might be that your strategy is missing the mandatory methods such as should_long(), go_long(), and should_cancel_entry(). "
"\nIf you need working examples, check out: https://github.com/jesse-ai/example-strategies"
"Looks like the structure of your strategy directory is incorrect. Make sure to include the strategy INSIDE the __init__.py file. Another reason for this error might be that your strategy is missing the mandatory methods such as should_long(), go_long(). "
"\nIf you need working examples, check out: https://jesse.trade/strategies"
)
except:
raise
Expand Down
3 changes: 0 additions & 3 deletions jesse/services/strategy_handler/ExampleStrategy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,3 @@ def go_long(self):
def go_short(self):
# For futures trading only
pass

def should_cancel_entry(self) -> bool:
return True
7 changes: 5 additions & 2 deletions jesse/strategies/Strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,12 @@ def should_long(self) -> bool:
def should_short(self) -> bool:
return False

@abstractmethod
def should_cancel_entry(self) -> bool:
pass
"""
Whether to cancel the active entry orders or not. By default, it will cancel the
entry orders when a new candle is formed and the position is still not open.
"""
return True

def before(self) -> None:
"""
Expand Down
15 changes: 15 additions & 0 deletions jesse/strategies/TestWithoutCancelMethod/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from jesse.strategies import Strategy


class TestWithoutCancelMethod(Strategy):
def should_long(self):
return False

def go_long(self):
pass

def go_short(self):
pass

def should_short(self):
return False
2 changes: 1 addition & 1 deletion jesse/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.12'
__version__ = '1.3.13'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

# also change in version.py
VERSION = '1.3.12'
VERSION = '1.3.13'
DESCRIPTION = "A trading framework for cryptocurrencies"
with open("requirements.txt", "r", encoding="utf-8") as f:
REQUIRED_PACKAGES = f.read().splitlines()
Expand Down
3 changes: 3 additions & 0 deletions tests/test_parent_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,6 @@ def test_chart_values():
with pytest.raises(ValueError):
single_route_backtest('TestAddLineToExtraChart')


def test_without_cancel_method():
single_route_backtest('TestWithoutCancelMethod')

0 comments on commit 1e935a8

Please sign in to comment.