예제 #1
0
 def update_activation_configuration(
         self,
         new_config,
         deactivate_other_evaluators,
         add_missing_elements,
         tentacles_path=constants.TENTACLES_PATH):
     something_changed = False
     loaders.ensure_tentacles_metadata(tentacles_path)
     for element_name, activated in new_config.items():
         try:
             element_type = loaders.get_tentacle_classes(
             )[element_name].tentacle_root_type
             if element_name in self.tentacles_activation[element_type]:
                 current_activation = self.tentacles_activation[
                     element_type][element_name]
                 if current_activation != activated:
                     self.logger.info(
                         f"Tentacles configuration updated: {element_name} "
                         f"{'activated' if activated else 'deactivated'}")
                     self.tentacles_activation[element_type][
                         element_name] = activated
                     something_changed = True
             elif add_missing_elements:
                 self.tentacles_activation[element_type][
                     element_name] = activated
                 something_changed = True
         except KeyError:
             # tentacle missing in loaded metadata: can't be used
             self.logger.error(
                 f"Impossible to change activation of {element_name}: this Tentacle class is not "
                 f"in loaded tentacles metadata dict.")
     if deactivate_other_evaluators:
         something_changed = self._deactivate_other_evaluators(
             new_config) or something_changed
     return something_changed
예제 #2
0
 def is_tentacle_activated(self,
                           tentacle_class_name,
                           tentacles_path=constants.TENTACLES_PATH):
     loaders.ensure_tentacles_metadata(tentacles_path)
     tentacle_type = loaders.get_tentacle_classes(
     )[tentacle_class_name].tentacle_root_type
     return self.tentacles_activation[tentacle_type][tentacle_class_name]
예제 #3
0
 def read_config(self, tentacles_path=constants.TENTACLES_PATH):
     try:
         self._from_dict(configuration.read_config(self.config_path))
     except Exception as e:
         self.logger.error(f"Error when reading tentacles global configuration file ({e}), "
                           "resetting this file with default values. This will not change "
                           "any specific tentacle configuration.")
         loaders.ensure_tentacles_metadata(tentacles_path)
         self._update_tentacles_setup_config(loaders.get_tentacle_classes().values())
         self.save_config()
예제 #4
0
 def from_activated_tentacles_classes(self, *tentacles_classes, tentacles_path=constants.TENTACLES_PATH):
     loaders.ensure_tentacles_metadata(tentacles_path)
     tentacle_by_class_name = loaders.get_tentacle_classes()
     for tentacle_class in tentacles_classes:
         tentacle_name = tentacle_class.get_name()
         tentacle = tentacle_by_class_name[tentacle_name]
         try:
             self.tentacles_activation[tentacle.tentacle_root_type][tentacle_name] = True
         except KeyError:
             self.tentacles_activation[tentacle.tentacle_root_type] = {tentacle_name: True}
예제 #5
0
 def _deactivate_tentacle_if_evaluator(self, element_name, element_type):
     try:
         if loaders.get_tentacle_classes()[element_name].get_simple_tentacle_type() in {
             constants.TENTACLES_EVALUATOR_TA_PATH,
             constants.TENTACLES_EVALUATOR_SOCIAL_PATH,
             constants.TENTACLES_EVALUATOR_REALTIME_PATH
         }:
             self.logger.info(f"Tentacles configuration updated: {element_name} {'deactivated'}")
             self.tentacles_activation[element_type][element_name] = False
             return True
     except KeyError:
         # might happen when a tentacle is listed in config but has not been loaded in OctoBot (import fail etc)
         pass
     return False
예제 #6
0
def get_installed_tentacles_modules() -> set:
    return set(tentacle
               for tentacle in loaders.get_tentacle_classes().values())
예제 #7
0
async def test__set_activation_using_default_config():
    _cleanup()
    async with aiohttp.ClientSession() as session:
        await api.install_all_tentacles(_tentacles_local_path(), aiohttp_session=session)
    tentacle_setup_config = TentaclesSetupConfiguration()
    tentacles = list(loaders.get_tentacle_classes().values())
    tentacle_setup_config._update_tentacles_setup_config(tentacles)

    tentacle_root_path = tentacles[0].tentacle_root_path
    tentacle_types = sorted(util.tentacle_explorer._get_tentacle_types(tentacle_root_path), key=lambda x: x.__str__())

    new_tentacles = []
    # Add Evaluators
    # TA one
    testTA = models.Tentacle(tentacles[0].tentacle_root_path, "testTA",
                             models.TentacleType(os.path.join(constants.TENTACLES_EVALUATOR_PATH,
                                                              constants.TENTACLES_EVALUATOR_TA_PATH)))
    testTA.tentacle_class_names = ["testTA"]
    new_tentacles.append(testTA)
    # Social one
    testSocial = models.Tentacle(tentacles[0].tentacle_root_path, "testSocial", tentacle_types[2])
    testSocial.tentacle_class_names = ["testSocial"]
    new_tentacles.append(testSocial)
    # RealTime one
    testRT = models.Tentacle(tentacles[0].tentacle_root_path, "testRT", tentacle_types[1])
    testRT.tentacle_class_names = ["testRT"]
    new_tentacles.append(testRT)
    # Strategy one
    testStrategy = models.Tentacle(tentacles[0].tentacle_root_path, "testStrategy", tentacle_types[3])
    testStrategy.tentacle_class_names = ["testStrategy"]
    new_tentacles.append(testStrategy)
    # Util one
    testUtil = models.Tentacle(tentacles[0].tentacle_root_path, "testUtil", tentacle_types[4])
    testUtil.tentacle_class_names = ["testUtil"]
    new_tentacles.append(testUtil)

    # Add Trading mode
    # Exchange
    testExchange = models.Tentacle(tentacles[0].tentacle_root_path, "testExchange",
                                   models.TentacleType(os.path.join(constants.TENTACLES_TRADING_PATH,
                                                                    constants.TENTACLES_TRADING_EXCHANGE_PATH)))
    testExchange.tentacle_class_names = ["testExchange"]
    new_tentacles.append(testExchange)
    # Mode
    testMode = models.Tentacle(tentacles[0].tentacle_root_path, "testMode", tentacle_types[7])
    testMode.tentacle_class_names = ["testMode"]
    new_tentacles.append(testMode)

    # Add backtesting
    testBacktesting = models.Tentacle(tentacles[0].tentacle_root_path, "testBacktesting", tentacle_types[0])
    testBacktesting.tentacle_class_names = ["testBacktesting"]
    new_tentacles.append(testBacktesting)

    # Add Service
    testServiceBase = models.Tentacle(tentacles[0].tentacle_root_path, "testServiceBase", tentacle_types[5])
    testServiceBase.tentacle_class_names = ["testServiceBase"]
    testServiceFeed = models.Tentacle(tentacles[0].tentacle_root_path, "testServiceFeed", tentacle_types[6])
    testServiceFeed.tentacle_class_names = ["testServiceFeed"]
    new_tentacles.append(testServiceFeed)
    new_tentacles.append(testServiceBase)

    tentacles += new_tentacles
    tentacle_setup_config._update_tentacles_setup_config(tentacles, newly_installed_tentacles=new_tentacles)

    # Evaluator are disabled by default except for Util
    assert not tentacle_setup_config.tentacles_activation[constants.TENTACLES_EVALUATOR_PATH]["testTA"]
    assert not tentacle_setup_config.tentacles_activation[constants.TENTACLES_EVALUATOR_PATH]["testSocial"]
    assert not tentacle_setup_config.tentacles_activation[constants.TENTACLES_EVALUATOR_PATH]["testStrategy"]
    assert tentacle_setup_config.tentacles_activation[constants.TENTACLES_EVALUATOR_PATH]["testUtil"]

    # Trading
    assert tentacle_setup_config.tentacles_activation[constants.TENTACLES_TRADING_PATH]["testExchange"]
    assert not tentacle_setup_config.tentacles_activation[constants.TENTACLES_TRADING_PATH]["testMode"]

    # Backtesting
    assert tentacle_setup_config.tentacles_activation[constants.TENTACLES_BACKTESTING_PATH]["testBacktesting"]

    # Services
    assert tentacle_setup_config.tentacles_activation[constants.TENTACLES_SERVICES_PATH]["testServiceBase"]
    assert tentacle_setup_config.tentacles_activation[constants.TENTACLES_SERVICES_PATH]["testServiceFeed"]

    _cleanup()