diff --git a/freqtrade/commands/build_config_commands.py b/freqtrade/commands/build_config_commands.py index 311622458..3b0c39921 100644 --- a/freqtrade/commands/build_config_commands.py +++ b/freqtrade/commands/build_config_commands.py @@ -10,7 +10,7 @@ from freqtrade.configuration.directory_operations import chown_user_directory from freqtrade.constants import UNLIMITED_STAKE_AMOUNT from freqtrade.exceptions import OperationalException from freqtrade.exchange import MAP_EXCHANGE_CHILDCLASS, available_exchanges -from freqtrade.misc import render_template +from freqtrade.util import render_template logger = logging.getLogger(__name__) diff --git a/freqtrade/commands/deploy_commands.py b/freqtrade/commands/deploy_commands.py index 8237a63db..75da2552e 100644 --- a/freqtrade/commands/deploy_commands.py +++ b/freqtrade/commands/deploy_commands.py @@ -10,7 +10,7 @@ from freqtrade.configuration.directory_operations import copy_sample_files, crea from freqtrade.constants import USERPATH_STRATEGIES from freqtrade.enums import RunMode from freqtrade.exceptions import OperationalException -from freqtrade.misc import render_template, render_template_with_fallback +from freqtrade.util import render_template, render_template_with_fallback logger = logging.getLogger(__name__) diff --git a/freqtrade/misc.py b/freqtrade/misc.py index e715c280a..f8d730fae 100644 --- a/freqtrade/misc.py +++ b/freqtrade/misc.py @@ -192,30 +192,6 @@ def plural(num: float, singular: str, plural: Optional[str] = None) -> str: return singular if (num == 1 or num == -1) else plural or singular + 's' -def render_template(templatefile: str, arguments: dict = {}) -> str: - - from jinja2 import Environment, PackageLoader, select_autoescape - - env = Environment( - loader=PackageLoader('freqtrade', 'templates'), - autoescape=select_autoescape(['html', 'xml']) - ) - template = env.get_template(templatefile) - return template.render(**arguments) - - -def render_template_with_fallback(templatefile: str, templatefallbackfile: str, - arguments: dict = {}) -> str: - """ - Use templatefile if possible, otherwise fall back to templatefallbackfile - """ - from jinja2.exceptions import TemplateNotFound - try: - return render_template(templatefile, arguments) - except TemplateNotFound: - return render_template(templatefallbackfile, arguments) - - def chunks(lst: List[Any], n: int) -> Iterator[List[Any]]: """ Split lst into chunks of the size n. diff --git a/freqtrade/util/__init__.py b/freqtrade/util/__init__.py index 92c79b899..af09624ac 100644 --- a/freqtrade/util/__init__.py +++ b/freqtrade/util/__init__.py @@ -2,6 +2,7 @@ from freqtrade.util.datetime_helpers import (dt_floor_day, dt_from_ts, dt_humani dt_utc, format_ms_time, shorten_date) from freqtrade.util.ft_precise import FtPrecise from freqtrade.util.periodic_cache import PeriodicCache +from freqtrade.util.template_renderer import render_template, render_template_with_fallback # noqa __all__ = [ diff --git a/freqtrade/util/template_renderer.py b/freqtrade/util/template_renderer.py new file mode 100644 index 000000000..821b8e458 --- /dev/null +++ b/freqtrade/util/template_renderer.py @@ -0,0 +1,25 @@ +""" +Jinja2 rendering utils, used to generate new strategy and configurations. +""" +def render_template(templatefile: str, arguments: dict = {}) -> str: + + from jinja2 import Environment, PackageLoader, select_autoescape + + env = Environment( + loader=PackageLoader('freqtrade', 'templates'), + autoescape=select_autoescape(['html', 'xml']) + ) + template = env.get_template(templatefile) + return template.render(**arguments) + + +def render_template_with_fallback(templatefile: str, templatefallbackfile: str, + arguments: dict = {}) -> str: + """ + Use templatefile if possible, otherwise fall back to templatefallbackfile + """ + from jinja2.exceptions import TemplateNotFound + try: + return render_template(templatefile, arguments) + except TemplateNotFound: + return render_template(templatefallbackfile, arguments)