Exemplo n.º 1
0
def deploy_new_hyperopt(hyperopt_name: str, hyperopt_path: Path,
                        subtemplate: str) -> None:
    """
    Deploys a new hyperopt template to hyperopt_path
    """
    fallback = 'full'
    buy_guards = render_template_with_fallback(
        templatefile=f"subtemplates/hyperopt_buy_guards_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/hyperopt_buy_guards_{fallback}.j2",
    )
    sell_guards = render_template_with_fallback(
        templatefile=f"subtemplates/hyperopt_sell_guards_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/hyperopt_sell_guards_{fallback}.j2",
    )
    buy_space = render_template_with_fallback(
        templatefile=f"subtemplates/hyperopt_buy_space_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/hyperopt_buy_space_{fallback}.j2",
    )
    sell_space = render_template_with_fallback(
        templatefile=f"subtemplates/hyperopt_sell_space_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/hyperopt_sell_space_{fallback}.j2",
    )

    strategy_text = render_template(templatefile='base_hyperopt.py.j2',
                                    arguments={
                                        "hyperopt": hyperopt_name,
                                        "buy_guards": buy_guards,
                                        "sell_guards": sell_guards,
                                        "buy_space": buy_space,
                                        "sell_space": sell_space,
                                    })

    logger.info(f"Writing hyperopt to `{hyperopt_path}`.")
    hyperopt_path.write_text(strategy_text)
Exemplo n.º 2
0
def test_render_template_fallback(mocker):
    from jinja2.exceptions import TemplateNotFound
    with pytest.raises(TemplateNotFound):
        val = render_template(
            templatefile='subtemplates/indicators_does-not-exist.j2', )

    val = render_template_with_fallback(
        templatefile='subtemplates/indicators_does-not-exist.j2',
        templatefallbackfile='subtemplates/indicators_minimal.j2',
    )
    assert isinstance(val, str)
    assert 'if self.dp' in val
Exemplo n.º 3
0
def deploy_new_strategy(strategy_name: str, strategy_path: Path,
                        subtemplate: str) -> None:
    """
    Deploy new strategy from template to strategy_path
    """
    fallback = 'full'
    indicators = render_template_with_fallback(
        templatefile=f"subtemplates/indicators_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/indicators_{fallback}.j2",
    )
    buy_trend = render_template_with_fallback(
        templatefile=f"subtemplates/buy_trend_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/buy_trend_{fallback}.j2",
    )
    sell_trend = render_template_with_fallback(
        templatefile=f"subtemplates/sell_trend_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/sell_trend_{fallback}.j2",
    )
    plot_config = render_template_with_fallback(
        templatefile=f"subtemplates/plot_config_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/plot_config_{fallback}.j2",
    )
    additional_methods = render_template_with_fallback(
        templatefile=f"subtemplates/strategy_methods_{subtemplate}.j2",
        templatefallbackfile=f"subtemplates/strategy_methods_empty.j2",
    )

    strategy_text = render_template(templatefile='base_strategy.py.j2',
                                    arguments={
                                        "strategy": strategy_name,
                                        "indicators": indicators,
                                        "buy_trend": buy_trend,
                                        "sell_trend": sell_trend,
                                        "plot_config": plot_config,
                                        "additional_methods":
                                        additional_methods,
                                    })

    logger.info(f"Writing strategy to `{strategy_path}`.")
    strategy_path.write_text(strategy_text)