Use strings instead of subtemplates
This commit is contained in:
parent
f26c40082d
commit
f23f659ac5
@ -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'
|
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
|
from jinja2 import Environment, PackageLoader, select_autoescape
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ class {{ strategy }}(IStrategy):
|
|||||||
:param metadata: Additional information, like the currently traded pair
|
:param metadata: Additional information, like the currently traded pair
|
||||||
:return: a Dataframe with all mandatory indicators for the strategies
|
:return: a Dataframe with all mandatory indicators for the strategies
|
||||||
"""
|
"""
|
||||||
{% filter indent(8) %}{% include 'subtemplates/indicators_' + subtemplates + '.j2' %}{% endfilter %}
|
{{ indicators | indent(8) }}
|
||||||
|
|
||||||
return dataframe
|
return dataframe
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ class {{ strategy }}(IStrategy):
|
|||||||
"""
|
"""
|
||||||
dataframe.loc[
|
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
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
||||||
),
|
),
|
||||||
'buy'] = 1
|
'buy'] = 1
|
||||||
@ -131,7 +131,7 @@ class {{ strategy }}(IStrategy):
|
|||||||
"""
|
"""
|
||||||
dataframe.loc[
|
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
|
(dataframe['volume'] > 0) # Make sure Volume is not 0
|
||||||
),
|
),
|
||||||
'sell'] = 1
|
'sell'] = 1
|
||||||
|
@ -105,9 +105,16 @@ def start_new_strategy(args: Dict[str, Any]) -> None:
|
|||||||
raise OperationalException(f"`{new_path}` already exists. "
|
raise OperationalException(f"`{new_path}` already exists. "
|
||||||
"Please choose another Strategy Name.")
|
"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',
|
strategy_text = render_template(templatefile='base_strategy.py.j2',
|
||||||
arguments={"strategy": args["strategy"],
|
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}`.")
|
logger.info(f"Writing strategy to `{new_path}`.")
|
||||||
new_path.write_text(strategy_text)
|
new_path.write_text(strategy_text)
|
||||||
|
Loading…
Reference in New Issue
Block a user