Esempio 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)
Esempio n. 2
0
 def load_exchange(exchange_name: str,
                   config: dict,
                   validate: bool = True) -> Exchange:
     """
     Load the custom class from config parameter
     :param exchange_name: name of the Exchange to load
     :param config: configuration dictionary
     """
     # Map exchange name to avoid duplicate classes for identical exchanges
     exchange_name = MAP_EXCHANGE_CHILDCLASS.get(exchange_name,
                                                 exchange_name)
     exchange_name = exchange_name.title()
     exchange = None
     try:
         exchange = ExchangeResolver._load_exchange(exchange_name,
                                                    kwargs={
                                                        'config': config,
                                                        'validate': validate
                                                    })
     except ImportError:
         logger.info(
             f"No {exchange_name} specific subclass found. Using the generic class instead."
         )
     if not exchange:
         exchange = Exchange(config, validate=validate)
     return exchange
Esempio n. 3
0
 def __init__(self,
              exchange_name: str,
              config: dict,
              validate: bool = True) -> None:
     """
     Load the custom class from config parameter
     :param config: configuration dictionary
     """
     # Map exchange name to avoid duplicate classes for identical exchanges
     exchange_name = MAP_EXCHANGE_CHILDCLASS.get(exchange_name,
                                                 exchange_name)
     exchange_name = exchange_name.title()
     try:
         self.exchange = self._load_exchange(exchange_name,
                                             kwargs={
                                                 'config': config,
                                                 'validate': validate
                                             })
     except ImportError:
         logger.info(
             f"No {exchange_name} specific subclass found. Using the generic class instead."
         )
     if not hasattr(self, "exchange"):
         self.exchange = Exchange(config, validate=validate)