def start_optimizer(strategy, time_frames, evaluators, risks): try: tools = web_interface_root.WebInterface.tools optimizer = tools[constants.BOT_TOOLS_STRATEGY_OPTIMIZER] if optimizer is not None and octobot_api.is_optimizer_computing( optimizer): return False, "Optimizer already running" independent_backtesting = tools[constants.BOT_TOOLS_BACKTESTING] if independent_backtesting and octobot_api.is_independent_backtesting_in_progress( independent_backtesting): return False, "A backtesting is already running" else: formatted_time_frames = time_frame_manager.parse_time_frames( time_frames) float_risks = [float(risk) for risk in risks] temp_independent_backtesting = octobot_api.create_independent_backtesting( interfaces_util.get_global_config(), None, []) optimizer_config = interfaces_util.run_in_bot_async_executor( octobot_api.initialize_independent_backtesting_config( temp_independent_backtesting)) optimizer = octobot_api.create_strategy_optimizer( optimizer_config, interfaces_util.get_bot_api().get_edited_tentacles_config(), strategy) tools[constants.BOT_TOOLS_STRATEGY_OPTIMIZER] = optimizer thread = threading.Thread( target=octobot_api.find_optimal_configuration, args=(optimizer, evaluators, formatted_time_frames, float_risks), name=f"{optimizer.get_name()}-WebInterface-runner") thread.start() return True, "Optimizer started" except Exception as e: LOGGER.exception(e, True, f"Error when starting optimizer: {e}") raise e
def get_current_exchange(): g_config = interfaces_util.get_global_config() exchanges = g_config[commons_constants.CONFIG_EXCHANGES] if exchanges: return next(iter(exchanges)) else: return DEFAULT_EXCHANGE
def get_full_exchange_list(remove_config_exchanges=False): g_config = interfaces_util.get_global_config() if remove_config_exchanges: user_exchanges = [e for e in g_config[commons_constants.CONFIG_EXCHANGES]] full_exchange_list = list(set(ccxt.exchanges) - set(user_exchanges)) else: full_exchange_list = list(set(ccxt.exchanges)) # can't handle exchanges containing UPDATED_CONFIG_SEPARATOR character in their name return [exchange for exchange in full_exchange_list if constants.UPDATED_CONFIG_SEPARATOR not in exchange]
def _get_time_frame(exchange_name, exchange_id): try: return time_frame_manager.get_display_time_frame( interfaces_util.get_global_config(), commons_enums.TimeFrames(constants.DEFAULT_TIMEFRAME)) except IndexError: # second try with watched timeframes, there might be a real-time time frame available return trading_api.get_watched_timeframes( trading_api.get_exchange_manager_from_exchange_name_and_id( exchange_name, exchange_id))[0]
def get_time_frames_list(strategy_name): if strategy_name: strategy_class = tentacles_management.get_class_from_string( strategy_name, evaluators.StrategyEvaluator, TentaclesStrategies, tentacles_management.evaluator_parent_inspection) return [ tf.value for tf in strategy_class.get_required_time_frames( interfaces_util.get_global_config()) ] else: return []
def start_backtesting_using_specific_files(files, source, reset_tentacle_config=False, run_on_common_part_only=True, start_timestamp=None, end_timestamp=None): try: tools = web_interface_root.WebInterface.tools previous_independent_backtesting = tools[ constants.BOT_TOOLS_BACKTESTING] if tools[ constants. BOT_TOOLS_STRATEGY_OPTIMIZER] and octobot_api.is_optimizer_in_progress( tools[constants.BOT_TOOLS_STRATEGY_OPTIMIZER]): return False, "Optimizer already running" elif previous_independent_backtesting and \ octobot_api.is_independent_backtesting_in_progress(previous_independent_backtesting): return False, "A backtesting is already running" else: if previous_independent_backtesting: interfaces_util.run_in_bot_main_loop( octobot_api.stop_independent_backtesting( previous_independent_backtesting)) if reset_tentacle_config: tentacles_config = interfaces_util.get_edited_config( dict_only=False).get_tentacles_config_path() tentacles_setup_config = tentacles_manager_api.get_tentacles_setup_config( tentacles_config) else: tentacles_setup_config = interfaces_util.get_bot_api( ).get_edited_tentacles_config() config = interfaces_util.get_global_config() independent_backtesting = octobot_api.create_independent_backtesting( config, tentacles_setup_config, files, run_on_common_part_only=run_on_common_part_only, start_timestamp=start_timestamp, end_timestamp=end_timestamp) interfaces_util.run_in_bot_main_loop( octobot_api.initialize_and_run_independent_backtesting( independent_backtesting), blocking=False) tools[constants.BOT_TOOLS_BACKTESTING] = independent_backtesting tools[constants.BOT_TOOLS_BACKTESTING_SOURCE] = source return True, "Backtesting started" except Exception as e: bot_logging.get_logger("DataCollectorWebInterfaceModel").exception( e, False) return False, f"Error when starting backtesting: {e}"
def get_currency_price_graph_update(exchange_id, symbol, time_frame, list_arrays=True, backtesting=False, minimal_candles=False, ignore_trades=False): bot_api = interfaces_util.get_bot_api() # TODO: handle on the fly backtesting price graph # if backtesting and WebInterface and WebInterface.tools[BOT_TOOLS_BACKTESTING]: # bot = WebInterface.tools[BOT_TOOLS_BACKTESTING].get_bot() symbol = parse_get_symbol(symbol) in_backtesting = backtesting_api.is_backtesting_enabled( interfaces_util.get_global_config()) or backtesting exchange_manager = trading_api.get_exchange_manager_from_exchange_id( exchange_id) if time_frame is not None: try: symbol_data = trading_api.get_symbol_data(exchange_manager, symbol, allow_creation=False) limit = 1 if minimal_candles else -1 historical_candles = trading_api.get_symbol_historical_candles( symbol_data, time_frame, limit=limit) kline = [math.nan] if trading_api.has_symbol_klines(symbol_data, time_frame): kline = trading_api.get_symbol_klines(symbol_data, time_frame) if historical_candles is not None: return _create_candles_data(symbol, time_frame, historical_candles, kline, bot_api, list_arrays, in_backtesting, ignore_trades) except KeyError: traded_pairs = trading_api.get_trading_pairs(exchange_manager) if not traded_pairs or symbol in traded_pairs: # not started yet return None else: return {"error": f"no data for {symbol}"} return None
def get_in_backtesting_mode(): return backtesting_api.is_backtesting_enabled( interfaces_util.get_global_config())