Ejemplo n.º 1
0
async def _get_tools():
    symbol = "BTC/USDT"
    exchange_traders = {}
    exchange_traders2 = {}
    config = load_test_config()
    AdvancedManager.create_class_list(config)
    exchange_manager = ExchangeManager(config, ccxt.binance, is_simulated=True)
    await exchange_manager.initialize()
    exchange_inst = exchange_manager.get_exchange()
    trader_inst = TraderSimulator(config, exchange_inst, 0.3)
    await trader_inst.initialize()
    trader_inst.stop_order_manager()
    trader_inst2 = TraderSimulator(config, exchange_inst, 0.3)
    await trader_inst2.initialize()
    trader_inst2.stop_order_manager()
    crypto_currency_evaluator = CryptocurrencyEvaluator(config, "Bitcoin", [])
    symbol_evaluator = SymbolEvaluator(config, symbol,
                                       crypto_currency_evaluator)
    exchange_traders[exchange_inst.get_name()] = trader_inst
    exchange_traders2[exchange_inst.get_name()] = trader_inst2
    symbol_evaluator.set_trader_simulators(exchange_traders)
    symbol_evaluator.set_traders(exchange_traders2)
    symbol_evaluator.strategies_eval_lists[exchange_inst.get_name()] = \
        EvaluatorCreator.create_strategies_eval_list(config)

    trading_mode = DailyTradingMode(config, exchange_inst)
    trading_mode.add_symbol_evaluator(symbol_evaluator)
    final_evaluator = trading_mode.get_only_decider_key(symbol)

    trader_inst.portfolio.portfolio["USDT"] = {
        Portfolio.TOTAL: 2000,
        Portfolio.AVAILABLE: 2000
    }
    return final_evaluator, trader_inst
Ejemplo n.º 2
0
    def __init__(self, config, strategy_name):
        self.is_properly_initialized = False
        self.logger = get_logger(self.get_name())
        AdvancedManager.init_advanced_classes_if_necessary(config)
        self.trading_mode = get_activated_trading_mode(config)
        self.config = create_blank_config_using_loaded_one(config)
        self.strategy_class = get_class_from_string(
            strategy_name, StrategiesEvaluator, Strategies,
            evaluator_parent_inspection)
        self.run_results = []
        self.results_report = []
        self.sorted_results_by_time_frame = {}
        self.sorted_results_through_all_time_frame = {}
        self.all_time_frames = []
        self.all_TAs = []
        self.risks = []
        self.current_test_suite = None
        self.errors = set()

        self.is_computing = False
        self.run_id = 0
        self.total_nb_runs = 0

        if not self.strategy_class:
            self.logger.error(
                f"Impossible to find a strategy matching class name: {strategy_name} in installed "
                f"strategies. Please make sure to enter the name of the class, "
                f"ex: FullMixedStrategiesEvaluator")
        else:
            self.is_properly_initialized = True
async def _get_tools(event_loop):
    symbol = "BTC/USDT"
    exchange_traders = {}
    exchange_traders2 = {}
    config = load_test_config()
    time_frame = TimeFrames.ONE_HOUR
    AdvancedManager.create_class_list(config)
    exchange_manager = ExchangeManager(config, ccxt.binance, is_simulated=True)
    await exchange_manager.initialize()
    exchange_inst = exchange_manager.get_exchange()
    global_price_updater = GlobalPriceUpdater(exchange_inst)
    trader_inst = TraderSimulator(config, exchange_inst, 0.3)
    trader_inst.stop_order_manager()
    trader_inst2 = TraderSimulator(config, exchange_inst, 0.3)
    trader_inst2.stop_order_manager()
    crypto_currency_evaluator = CryptocurrencyEvaluator(config, "Bitcoin", [])
    symbol_evaluator = SymbolEvaluator(config, symbol, crypto_currency_evaluator)
    exchange_traders[exchange_inst.get_name()] = trader_inst
    exchange_traders2[exchange_inst.get_name()] = trader_inst2
    symbol_evaluator.set_trader_simulators(exchange_traders)
    symbol_evaluator.set_traders(exchange_traders2)
    symbol_evaluator.strategies_eval_lists[exchange_inst.get_name()] = \
        EvaluatorCreator.create_strategies_eval_list(config)
    trading_mode_inst = get_activated_trading_mode(config)(config, exchange_inst)
    evaluator_task_manager = EvaluatorTaskManager(config, time_frame, global_price_updater,
                                                  symbol_evaluator, exchange_inst, trading_mode_inst, [],
                                                  event_loop)
    trader_inst.portfolio.portfolio["USDT"] = {
        Portfolio.TOTAL: 2000,
        Portfolio.AVAILABLE: 2000
    }
    return evaluator_task_manager, time_frame, global_price_updater, symbol_evaluator, symbol
Ejemplo n.º 4
0
def _get_tools():
    config = load_test_config()
    AdvancedManager.create_class_list(config)
    evaluator = Evaluator()
    evaluator.set_config(config)
    evaluator.set_symbol("BTC/USDT")
    evaluator.set_time_frame(TimeFrames.ONE_HOUR)
    return evaluator, config
Ejemplo n.º 5
0
def get_activated_trading_mode(config):
    if CONFIG_TRADING_TENTACLES in config:
        try:
            trading_modes = [
                class_str for class_str, activated in
                config[CONFIG_TRADING_TENTACLES].items() if activated
                and get_class_from_string(class_str,
                                          AbstractTradingMode,
                                          modes,
                                          error_when_not_found=True)
            ]

            if len(trading_modes) > 1:
                raise ConfigTradingError(
                    f"More than one activated trading mode found in your {CONFIG_TRADING_FILE_PATH} file, "
                    f"please activate only one")

            elif trading_modes:
                trading_mode_class = get_deep_class_from_string(
                    trading_modes[0], modes)

                if trading_mode_class is not None:
                    return AdvancedManager.get_class(config,
                                                     trading_mode_class)
        except ModuleNotFoundError as e:
            get_logger("get_activated_trading_mode").error(
                f"Error when loading a trading mode: {e} "
                f"referenced in {CONFIG_TRADING_FILE_PATH} file")

    raise ConfigTradingError(
        f"Please ensure your {CONFIG_TRADING_FILE_PATH} file is valid and at least one trading "
        f"mode is activated")
Ejemplo n.º 6
0
def _get_advanced_class_details(class_name,
                                klass,
                                is_trading_mode=False,
                                is_strategy=False):
    from tentacles_management.advanced_manager import AdvancedManager
    details = {}
    config = get_bot().get_config()
    advanced_class = AdvancedManager.get_class(config, klass)
    if advanced_class and advanced_class.get_name() != class_name:
        details[NAME_KEY] = advanced_class.get_name()
        details[DESCRIPTION_KEY] = advanced_class.get_description()
        details[BASE_CLASSES_KEY] = [
            k.get_name() for k in advanced_class.__bases__
        ]
        if is_trading_mode:
            required_strategies, required_strategies_count = klass.get_required_strategies_names_and_count(
            )
            details[REQUIREMENTS_KEY] = [
                strategy for strategy in required_strategies
            ]
            details[REQUIREMENTS_COUNT_KEY] = required_strategies_count
        elif is_strategy:
            details[REQUIREMENTS_KEY] = [
                evaluator
                for evaluator in advanced_class.get_required_evaluators(config)
            ]
            details[DEFAULT_CONFIG_KEY] = [
                evaluator
                for evaluator in advanced_class.get_default_evaluators(config)
            ]
    return details
Ejemplo n.º 7
0
def _assert_created_instances(instances_list, super_class, config):
    class_list = [instance.__class__ for instance in instances_list]
    for eval_class in AdvancedManager.create_advanced_evaluator_types_list(super_class, config):
        eval_instance = eval_class()
        eval_instance.set_config(config)
        if eval_instance.get_is_enabled():
            assert eval_class in class_list
Ejemplo n.º 8
0
    def create_real_time_ta_evals(config, exchange_inst, symbol,
                                  relevant_evaluators, dispatchers_list):
        real_time_ta_eval_list = []
        for real_time_eval_class in AdvancedManager.create_advanced_evaluator_types_list(
                RealTimeEvaluator, config):
            try:
                real_time_eval_class_instance = EvaluatorCreator.instantiate_real_time_evaluator(
                    real_time_eval_class, exchange_inst, symbol)
                real_time_eval_class_instance.set_config(config)
                if EvaluatorCreator.is_relevant_evaluator(
                        real_time_eval_class_instance, relevant_evaluators):
                    real_time_eval_class_instance.set_logger(
                        get_logger(real_time_eval_class.get_name()))

                    is_dispatcher_client, is_evaluator_to_be_used = \
                        DispatcherCreator.bind_to_dispatcher_if_necessary(real_time_eval_class_instance,
                                                                          dispatchers_list, symbol, True)

                    # register refreshing task
                    if not is_dispatcher_client:
                        real_time_eval_class_instance.set_is_to_be_started_as_task(
                            True)

                    if is_evaluator_to_be_used:
                        real_time_ta_eval_list.append(
                            real_time_eval_class_instance)
            except Exception as e:
                EvaluatorCreator.get_logger().error(
                    f"Error when creating evaluator {real_time_eval_class}: {e}"
                )
                EvaluatorCreator.get_logger().exception(e)

        return real_time_ta_eval_list
Ejemplo n.º 9
0
 def _init_strategies_instances(self, symbol, all_strategy_instances):
     all_strategy_classes = [s.__class__ for s in all_strategy_instances]
     required_strategies, required_strategies_min_count = self.get_required_strategies(
     )
     missing_strategies = []
     found_strategy_count = 0
     for required_class in required_strategies:
         if required_class in all_strategy_classes:
             self.strategy_instances_by_classes[symbol][required_class] = \
                 all_strategy_instances[all_strategy_classes.index(required_class)]
             found_strategy_count += 1
         else:
             subclass = AdvancedManager.get_class(self.config,
                                                  required_class)
             if subclass in all_strategy_classes:
                 self.strategy_instances_by_classes[symbol][required_class] = \
                     all_strategy_instances[all_strategy_classes.index(subclass)]
                 found_strategy_count += 1
         if required_class not in self.strategy_instances_by_classes[
                 symbol]:
             missing_strategies.append(required_class)
     if found_strategy_count < required_strategies_min_count:
         for missing_strategy in missing_strategies:
             self.logger.error(
                 f"No instance of {missing_strategy.__name__} or advanced equivalent found, "
                 f"{self.get_name()} trading mode can't work properly ! Maybe this strategy is "
                 f"disabled in tentacles/Evaluator/evaluator_config.json (missing "
                 f"{required_strategies_min_count-found_strategy_count} out of "
                 f"{required_strategies_min_count} minimum required strategies)."
             )
Ejemplo n.º 10
0
def get_strategies_list():
    try:
        config = get_bot().get_config()
        classes = AdvancedManager.get_all_classes(StrategiesEvaluator, config)
        return set(strategy.get_name() for strategy in classes)
    except Exception:
        return []
Ejemplo n.º 11
0
    async def eval_impl(self):
        interest_over_time = self.simplified_pytrends.interest_over_time()
        trend = numpy.array([d["data"] for d in interest_over_time])

        # compute bollinger bands
        self.eval_note = AdvancedManager.get_class(
            self.config,
            StatisticAnalysis).analyse_recent_trend_changes(trend, numpy.sqrt)
Ejemplo n.º 12
0
 def init_time_frames_from_strategies(config):
     time_frame_list = set()
     for strategies_eval_class in AdvancedManager.create_advanced_evaluator_types_list(
             StrategiesEvaluator, config):
         if strategies_eval_class.is_enabled(config, False):
             for time_frame in strategies_eval_class.get_required_time_frames(
                     config):
                 time_frame_list.add(time_frame)
     time_frame_list = TimeFrameManager.sort_time_frames(time_frame_list)
     config[CONFIG_TIME_FRAME] = time_frame_list
Ejemplo n.º 13
0
 def get_relevant_TAs_for_strategy(strategy, config):
     ta_classes_list = []
     relevant_evaluators = strategy.get_required_evaluators(config)
     for ta_eval_class in AdvancedManager.create_advanced_evaluator_types_list(
             TAEvaluator, config):
         ta_eval_class_instance = ta_eval_class()
         ta_eval_class_instance.set_config(config)
         if EvaluatorCreator.is_relevant_evaluator(ta_eval_class_instance,
                                                   relevant_evaluators):
             ta_classes_list.append(ta_eval_class)
     return ta_classes_list
Ejemplo n.º 14
0
 def get_relevant_evaluators_from_strategies(config):
     evaluator_list = set()
     for strategies_eval_class in AdvancedManager.create_advanced_evaluator_types_list(
             StrategiesEvaluator, config):
         if strategies_eval_class.is_enabled(config, False):
             required_evaluators = strategies_eval_class.get_required_evaluators(
                 config)
             if required_evaluators == CONFIG_EVALUATORS_WILDCARD:
                 return CONFIG_EVALUATORS_WILDCARD
             else:
                 for evaluator in required_evaluators:
                     evaluator_list.add(evaluator)
     return evaluator_list
Ejemplo n.º 15
0
def add_class_to_config_file_content(clazz, config_file_content, classes_list, activated=False):
    from config import SHORT_VERSION
    if TentacleUtil.is_first_version_superior(SHORT_VERSION, OCTOBOT_ADV_MNG_IMPORT_CHANGE_VERSION, or_equal=True):
        from tentacles_management.advanced_manager import AdvancedManager
    else:
        from evaluator.Util.advanced_manager import AdvancedManager
    changed_something = False
    current_classes_list = AdvancedManager.create_default_types_list(clazz)
    for current_class in current_classes_list:
        if not current_class.get_name() in config_file_content:
            config_file_content[current_class.get_name()] = activated
            changed_something = True
    classes_list += current_classes_list
    return changed_something
Ejemplo n.º 16
0
    def create_strategies_eval_list(config):
        strategies_eval_list = []
        for strategies_eval_class in AdvancedManager.create_advanced_evaluator_types_list(
                StrategiesEvaluator, config):
            try:
                strategies_eval_class_instance = strategies_eval_class()
                strategies_eval_class_instance.set_config(config)
                if strategies_eval_class_instance.get_is_enabled():
                    strategies_eval_class_instance.set_logger(
                        get_logger(strategies_eval_class_instance.get_name()))

                    strategies_eval_list.append(strategies_eval_class_instance)
            except Exception as e:
                EvaluatorCreator.get_logger().error(
                    f"Error when creating strategy {strategies_eval_class}: {e}"
                )
                EvaluatorCreator.get_logger().exception(e)

        return strategies_eval_list
Ejemplo n.º 17
0
    def create_ta_eval_list(evaluator, relevant_evaluators):
        ta_eval_instance_list = []
        for ta_eval_class in AdvancedManager.create_advanced_evaluator_types_list(
                TAEvaluator, evaluator.get_config()):
            try:
                ta_eval_class_instance = ta_eval_class()
                ta_eval_class_instance.set_config(evaluator.config)
                if EvaluatorCreator.is_relevant_evaluator(
                        ta_eval_class_instance, relevant_evaluators):
                    ta_eval_class_instance.set_logger(
                        get_logger(ta_eval_class.get_name()))
                    ta_eval_class_instance.set_data(evaluator.data)
                    ta_eval_class_instance.set_symbol(evaluator.get_symbol())
                    ta_eval_instance_list.append(ta_eval_class_instance)
            except Exception as e:
                EvaluatorCreator.get_logger().error(
                    f"Error when creating evaluator {ta_eval_class}: {e}")
                EvaluatorCreator.get_logger().exception(e)

        return ta_eval_instance_list
Ejemplo n.º 18
0
    def create_social_eval(config, symbol, dispatchers_list,
                           relevant_evaluators):
        social_eval_list = []
        for social_eval_class in AdvancedManager.create_advanced_evaluator_types_list(
                SocialEvaluator, config):
            try:
                social_eval_class_instance = social_eval_class()
                social_eval_class_instance.set_config(config)
                if EvaluatorCreator.is_relevant_evaluator(
                        social_eval_class_instance, relevant_evaluators):
                    is_evaluator_to_be_used = True
                    social_eval_class_instance.set_logger(
                        get_logger(social_eval_class.get_name()))
                    social_eval_class_instance.set_symbol(symbol)
                    social_eval_class_instance.prepare()

                    is_dispatcher_client, is_evaluator_to_be_used = \
                        DispatcherCreator.bind_to_dispatcher_if_necessary(social_eval_class_instance,
                                                                          dispatchers_list,
                                                                          symbol,
                                                                          is_evaluator_to_be_used)
                    # register refreshing task if the evaluator is not managed by a dispatcher
                    if not is_dispatcher_client and \
                            is_evaluator_to_be_used and \
                            social_eval_class_instance.get_is_to_be_independently_tasked():
                        social_eval_class_instance.set_is_to_be_started_as_task(
                            True)

                    if is_evaluator_to_be_used:
                        social_eval_list.append(social_eval_class_instance)
            except Exception as e:
                EvaluatorCreator.get_logger().error(
                    f"Error when creating evaluator {social_eval_class}: {e}")
                EvaluatorCreator.get_logger().exception(e)

        return social_eval_list
Ejemplo n.º 19
0
 def _manage_advanced_classes(self):
     AdvancedManager.init_advanced_classes_if_necessary(self.octobot.get_config())
Ejemplo n.º 20
0
 def prepare(self):
     self._format_config()
     self.sentiment_analyser = AdvancedManager.get_util_instance(
         self.config, TextAnalysis)