Ejemplo n.º 1
0
def deploy_new_config(config_path: Path, selections: Dict[str, Any]) -> None:
    """
    Applies selections to the template and writes the result to config_path
    :param config_path: Path object for new config file. Should not exist yet
    :param selecions: Dict containing selections taken by the user.
    """
    from jinja2.exceptions import TemplateNotFound
    try:
        exchange_template = MAP_EXCHANGE_CHILDCLASS.get(
            selections['exchange_name'], selections['exchange_name'])

        selections['exchange'] = render_template(
            templatefile=f"subtemplates/exchange_{exchange_template}.j2",
            arguments=selections
            )
    except TemplateNotFound:
        selections['exchange'] = render_template(
            templatefile="subtemplates/exchange_generic.j2",
            arguments=selections
        )

    config_text = render_template(templatefile='base_config.json.j2',
                                  arguments=selections)

    logger.info(f"Writing config to `{config_path}`.")
    config_path.write_text(config_text)
Ejemplo n.º 2
0
def deploy_new_hyperopt(hyperopt_name: str, hyperopt_path: Path,
                        subtemplate: str) -> None:
    """
    Deploys a new hyperopt template to hyperopt_path
    """
    buy_guards = render_template(
        templatefile=f"subtemplates/hyperopt_buy_guards_{subtemplate}.j2", )
    sell_guards = render_template(
        templatefile=f"subtemplates/hyperopt_sell_guards_{subtemplate}.j2", )
    buy_space = render_template(
        templatefile=f"subtemplates/hyperopt_buy_space_{subtemplate}.j2", )
    sell_space = render_template(
        templatefile=f"subtemplates/hyperopt_sell_space_{subtemplate}.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)
Ejemplo n.º 3
0
def deploy_new_strategy(strategy_name: str, strategy_path: Path,
                        subtemplate: str) -> None:
    """
    Deploy new strategy from template to strategy_path
    """
    indicators = render_template(
        templatefile=f"subtemplates/indicators_{subtemplate}.j2", )
    buy_trend = render_template(
        templatefile=f"subtemplates/buy_trend_{subtemplate}.j2", )
    sell_trend = render_template(
        templatefile=f"subtemplates/sell_trend_{subtemplate}.j2", )
    plot_config = render_template(
        templatefile=f"subtemplates/plot_config_{subtemplate}.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,
                                    })

    logger.info(f"Writing strategy to `{strategy_path}`.")
    strategy_path.write_text(strategy_text)
Ejemplo n.º 4
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
Ejemplo n.º 5
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)