Use strings instead of subtemplates

This commit is contained in:
Matthias 2019-11-21 19:28:53 +01:00
parent f26c40082d
commit f23f659ac5
3 changed files with 12 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)