Esempio n. 1
0
    def jsonify_config(config):
        # check exchange keys encryption
        for exchange in config[CONFIG_EXCHANGES]:
            key = config[CONFIG_EXCHANGES][exchange][CONFIG_EXCHANGE_KEY]
            secret = config[CONFIG_EXCHANGES][exchange][CONFIG_EXCHANGE_SECRET]
            try:
                if not ConfigManager.has_invalid_default_config_value(key):
                    try:
                        decrypt(key, silent_on_invalid_token=True)
                    except Exception:
                        config[CONFIG_EXCHANGES][exchange][
                            CONFIG_EXCHANGE_KEY] = encrypt(key).decode()

                if not ConfigManager.has_invalid_default_config_value(secret):
                    try:
                        decrypt(secret, silent_on_invalid_token=True)
                    except Exception:
                        config[CONFIG_EXCHANGES][exchange][
                            CONFIG_EXCHANGE_SECRET] = encrypt(secret).decode()

            except Exception:
                config[CONFIG_EXCHANGES][exchange] = {
                    CONFIG_EXCHANGE_KEY: "",
                    CONFIG_EXCHANGE_SECRET: ""
                }

        return json.dumps(config, indent=4, sort_keys=True)
Esempio n. 2
0
    def jsonify_config(config):
        # check exchange keys encryption
        for exchange in config[CONFIG_EXCHANGES]:
            try:
                try:
                    decrypt(config[CONFIG_EXCHANGES][exchange]
                            [CONFIG_EXCHANGE_KEY],
                            silent_on_invalid_token=True)
                except Exception:
                    config[CONFIG_EXCHANGES][exchange][
                        CONFIG_EXCHANGE_KEY] = encrypt(
                            config[CONFIG_EXCHANGES][exchange]
                            [CONFIG_EXCHANGE_KEY]).decode()

                try:
                    decrypt(config[CONFIG_EXCHANGES][exchange]
                            [CONFIG_EXCHANGE_SECRET],
                            silent_on_invalid_token=True)
                except Exception:
                    config[CONFIG_EXCHANGES][exchange][
                        CONFIG_EXCHANGE_SECRET] = encrypt(
                            config[CONFIG_EXCHANGES][exchange]
                            [CONFIG_EXCHANGE_SECRET]).decode()

            except Exception:
                config[CONFIG_EXCHANGES][exchange] = {
                    CONFIG_EXCHANGE_KEY: "",
                    CONFIG_EXCHANGE_SECRET: ""
                }

        return json.dumps(config, indent=4, sort_keys=True)
Esempio n. 3
0
    def create_client(self):
        if self.exchange_manager.ignore_config or self.exchange_manager.check_config(
                self.get_name()):
            try:
                if self.exchange_manager.ignore_config or not self.exchange_manager.should_decrypt_token(
                        self.logger):
                    key = ""
                    secret = ""
                    password = ""
                else:
                    config_exchange = self.config[CONFIG_EXCHANGES][self.name]
                    key = decrypt(config_exchange[CONFIG_EXCHANGE_KEY])
                    secret = decrypt(config_exchange[CONFIG_EXCHANGE_SECRET])
                    password = decrypt(config_exchange[CONFIG_EXCHANGE_PASSWORD]) \
                        if CONFIG_EXCHANGE_PASSWORD in config_exchange and \
                        not ConfigManager.has_invalid_default_config_value(config_exchange[CONFIG_EXCHANGE_PASSWORD]) \
                        else None

                self.client = self.exchange_type({
                    'apiKey': key,
                    'secret': secret,
                    'password': password,
                    'verbose': False,
                    'enableRateLimit': True
                })
            except Exception as e:
                self.exchange_manager.handle_token_error(e, self.logger)
                self.client = self.exchange_type({'verbose': False})
        else:
            self.client = self.exchange_type({'verbose': False})
            self.logger.error(
                "configuration issue: missing login information !")
        self.client.logger.setLevel(logging.INFO)
Esempio n. 4
0
    def create_client(self):
        if self.exchange_manager.ignore_config or self.exchange_manager.check_config(
                self.get_name()):
            try:
                if self.exchange_manager.ignore_config:
                    key = ""
                    secret = ""
                else:
                    key = decrypt(self.config[CONFIG_EXCHANGES][self.name]
                                  [CONFIG_EXCHANGE_KEY])
                    secret = decrypt(self.config[CONFIG_EXCHANGES][self.name]
                                     [CONFIG_EXCHANGE_SECRET])

                self.client = self.exchange_type({
                    'apiKey': key,
                    'secret': secret,
                    'verbose': False,
                    'enableRateLimit': True
                })
            except Exception:
                self.client = self.exchange_type({'verbose': False})
                self.logger.error(
                    "Exchange configuration tokens are invalid : please check your configuration !"
                )
        else:
            self.client = self.exchange_type({'verbose': False})
            self.logger.error(
                "configuration issue: missing login information !")
        self.client.logger.setLevel(logging.INFO)
Esempio n. 5
0
    def __init__(self, config, exchange_manager):
        super().__init__(config, exchange_manager)
        try:
            self.client = Client(decrypt(self.config[CONFIG_EXCHANGES][self.name][CONFIG_EXCHANGE_KEY]),
                                 decrypt(self.config[CONFIG_EXCHANGES][self.name][CONFIG_EXCHANGE_SECRET]))
        except Exception:
            self.client = Client("", "")
            self.logger.error("Exchange configuration tokens are invalid : please check your configuration !")

        self.socket_manager = None
        self.open_sockets_keys = {}
        self.ws_time_frames = None
        self.ws_trader_pairs = None
Esempio n. 6
0
 def _handle_encrypted_value(value_key, config_element, verbose=False):
     if value_key in config_element:
         key = config_element[value_key]
         if not ConfigManager.has_invalid_default_config_value(key):
             try:
                 decrypt(key, silent_on_invalid_token=True)
                 return True
             except Exception:
                 config_element[value_key] = encrypt(key).decode()
                 if verbose:
                     get_logger().warning(
                         f"Non encrypted secret info found in config ({value_key}): replaced "
                         f"value with encrypted equivalent.")
                 return False
     return True
Esempio n. 7
0
    def __init__(self, config, exchange_manager):
        super().__init__(config, exchange_manager)
        try:
            self.client = Client(
                decrypt(self.config[CONFIG_EXCHANGES][self.name]
                        [CONFIG_EXCHANGE_KEY]),
                decrypt(self.config[CONFIG_EXCHANGES][self.name]
                        [CONFIG_EXCHANGE_SECRET]))
        except requests.exceptions.ConnectionError as e:
            self.logger.error(f"Impossible to initialize websocket: {e}")
        except Exception as e:
            self.client = Client("", "")
            self.logger.error(f"Exchange configuration tokens are invalid : "
                              f"please check your configuration ! ({e})")

        self.socket_manager = None
        self.open_sockets_keys = {}
        self.ws_time_frames = None
        self.ws_trader_pairs = None
Esempio n. 8
0
    def __init__(self, config, exchange_manager):
        super().__init__(config, exchange_manager)
        try:
            if self.exchange_manager.should_decrypt_token(self.logger):
                self.client = Client(
                    decrypt(self.config[CONFIG_EXCHANGES][self.name]
                            [CONFIG_EXCHANGE_KEY]),
                    decrypt(self.config[CONFIG_EXCHANGES][self.name]
                            [CONFIG_EXCHANGE_SECRET]))
            else:
                self.client = Client("", "")
        except requests.exceptions.ConnectionError as e:
            self.logger.error(f"Impossible to initialize websocket: {e}")
        except Exception as e:
            self.exchange_manager.handle_token_error(e, self.logger)
            try:
                self.client = Client("", "")
            except requests.exceptions.ConnectionError as e:
                self.logger.error(f"Impossible to initialize websocket: {e}")

        self.socket_manager = None
        self.open_sockets_keys = {}
        self.ws_time_frames = None
        self.ws_trader_pairs = None