From f23f659ac590618ec8a4b232d49db079b61796d1 Mon Sep 17 00:00:00 2001 From: Matthias Date: Thu, 21 Nov 2019 19:28:53 +0100 Subject: [PATCH] Use strings instead of subtemplates --- freqtrade/misc.py | 2 +- freqtrade/templates/base_strategy.py.j2 | 6 +++--- freqtrade/utils.py | 9 ++++++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/freqtrade/misc.py b/freqtrade/misc.py index 6497a4727..bcba78cf0 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -129,7 +129,7 @@ def plural(num, singular: str, plural: str = None) -> str: return singular if (num == 1 or num == -1) else plural or singular + 's' -def render_template(templatefile: str, arguments: dict): +def render_template(templatefile: str, arguments: dict = {}): from jinja2 import Environment, PackageLoader, select_autoescape diff --git a/freqtrade/templates/base_strategy.py.j2 b/freqtrade/templates/base_strategy.py.j2 index 4c5fe9a0b..73a4c7a5a 100644 --- a/freqtrade/templates/base_strategy.py.j2 +++ b/freqtrade/templates/base_strategy.py.j2 @@ -102,7 +102,7 @@ class {{ strategy }}(IStrategy): :param metadata: Additional information, like the currently traded pair :return: a Dataframe with all mandatory indicators for the strategies """ - {% filter indent(8) %}{% include 'subtemplates/indicators_' + subtemplates + '.j2' %}{% endfilter %} + {{ indicators | indent(8) }} return dataframe @@ -115,7 +115,7 @@ class {{ strategy }}(IStrategy): """ dataframe.loc[ ( - {% filter indent(16) %}{% include 'subtemplates/buy_trend_' + subtemplates + '.j2' %}{% endfilter %} + {{ buy_trend | indent(16) }} (dataframe['volume'] > 0) # Make sure Volume is not 0 ), 'buy'] = 1 @@ -131,7 +131,7 @@ class {{ strategy }}(IStrategy): """ dataframe.loc[ ( - {% filter indent(16) %}{% include 'subtemplates/sell_trend_' + subtemplates + '.j2' %}{% endfilter %} + {{ sell_trend | indent(16) }} (dataframe['volume'] > 0) # Make sure Volume is not 0 ), 'sell'] = 1 diff --git a/freqtrade/utils.py b/freqtrade/utils.py index 4657e58fc..e94de4f3e 100644 --- a/freqtrade/utils.py +++ b/freqtrade/utils.py @@ -105,9 +105,16 @@ def start_new_strategy(args: Dict[str, Any]) -> None: raise OperationalException(f"`{new_path}` already exists. " "Please choose another Strategy Name.") + indicators = render_template(templatefile=f"subtemplates/indicators_{args['template']}.j2",) + buy_trend = render_template(templatefile=f"subtemplates/buy_trend_{args['template']}.j2",) + sell_trend = render_template(templatefile=f"subtemplates/sell_trend_{args['template']}.j2",) + strategy_text = render_template(templatefile='base_strategy.py.j2', arguments={"strategy": args["strategy"], - "subtemplates": args['template']}) + "indicators": indicators, + "buy_trend": buy_trend, + "sell_trend": sell_trend, + }) logger.info(f"Writing strategy to `{new_path}`.") new_path.write_text(strategy_text)