Esempio n. 1
0
 def _init_community_config(self):
     self.has_real_trader = trading_api.is_trader_enabled_in_config(
         self.edited_config.config)
     self.has_simulator = trading_api.is_trader_simulator_enabled_in_config(
         self.edited_config.config)
     self.exchange_managers = trading_api.get_exchange_managers_from_exchange_ids(
         self.octobot_api.get_exchange_manager_ids())
Esempio n. 2
0
 def _handle_results(self, independent_backtesting, profitability):
     trades_count = 0
     profitability_result = None
     skip_this_run = False
     if independent_backtesting is not None:
         exchange_manager_ids = octobot_backtesting_api.get_independent_backtesting_exchange_manager_ids(
             independent_backtesting)
         try:
             for exchange_manager in trading_api.get_exchange_managers_from_exchange_ids(
                     exchange_manager_ids):
                 _, profitability, _, market_average_profitability, _ = \
                     trading_api.get_profitability_stats(exchange_manager)
                 # Only one exchange manager per run
                 profitability_result = (profitability,
                                         market_average_profitability)
                 trades_count += len(
                     trading_api.get_trade_history(exchange_manager))
         except (AttributeError, KeyError):
             skip_this_run = True
         if not skip_this_run:
             if profitability_result is None:
                 raise RuntimeError(
                     "Error with independent backtesting: no available exchange manager"
                 )
             self._profitability_results.append(profitability_result)
             self._trades_counts.append(trades_count)
Esempio n. 3
0
 def get_exchange_managers():
     try:
         import octobot_trading.api as api
         return api.get_exchange_managers_from_exchange_ids(
             AbstractInterface.bot_api.get_exchange_manager_ids())
     except ImportError:
         AbstractInterface.get_logger().error(
             "AbstractInterface requires OctoBot-Trading package installed")
 def _handle_results(self, independent_backtesting, profitability):
     exchange_manager_ids = octobot_api.get_independent_backtesting_exchange_manager_ids(
         independent_backtesting)
     for exchange_manager in trading_api.get_exchange_managers_from_exchange_ids(
             exchange_manager_ids):
         _, run_profitability, _, market_average_profitability, _ = trading_api.get_profitability_stats(
             exchange_manager)
         actual = round(run_profitability, 3)
         # uncomment this print for building tests
         # print(f"results: rounded run profitability {actual} market profitability: {market_average_profitability}"
         #       f" expected: {profitability} [result: {actual ==  profitability}]")
         assert actual == profitability
Esempio n. 5
0
    async def stop(self, memory_check=False, should_raise=False):
        self.logger.info(
            f"Stopping for {self.backtesting_files} with {self.symbols_to_create_exchange_classes}"
        )
        exchange_managers = []
        try:
            await backtesting_api.stop_backtesting(self.backtesting)
            try:
                for exchange_manager in trading_api.get_exchange_managers_from_exchange_ids(
                        self.exchange_manager_ids):
                    exchange_managers.append(exchange_manager)
                    await trading_api.stop_exchange(exchange_manager)
            except KeyError:
                # exchange managers are not added in global exchange list when an exception occurred
                pass
            for evaluators in self.evaluators:
                # evaluators by type
                for evaluator in evaluators:
                    # evaluator instance
                    if evaluator is not None:
                        await evaluator_api.stop_evaluator(evaluator)
            await evaluator_api.stop_all_evaluator_channels(self.matrix_id)
            evaluator_api.del_evaluator_channels(self.matrix_id)
            evaluator_api.del_matrix(self.matrix_id)
            for service_feed in self.service_feeds:
                await service_api.stop_service_feed(service_feed)
        except Exception as e:
            self.logger.exception(
                e, True, f"Error when stopping independent backtesting: {e}")
            if should_raise:
                raise
        finally:
            # call stop_importers in case it has not been called already
            await self.stop_importers()

            if memory_check:
                to_reference_check = exchange_managers + [self.backtesting]
                # Call at the next loop iteration to first let coroutines get cancelled
                # (references to coroutine and caller objects are kept while in async loop)
                asyncio.get_event_loop().call_soon(self.memory_leak_checkup,
                                                   to_reference_check)
            self.backtesting = None
Esempio n. 6
0
 async def stop(self):
     for exchange_manager in trading_api.get_exchange_managers_from_exchange_ids(
             self.exchange_manager_ids):
         await trading_api.stop_exchange(exchange_manager)