def get_exchange_time_frames(exchange_id): try: exchange_manager = trading_api.get_exchange_manager_from_exchange_id( exchange_id) return trading_api.get_watched_timeframes( exchange_manager), trading_api.get_exchange_name(exchange_manager) except KeyError: return [], ""
def _get_exchanges_report(self, reference_market, trading_mode): SYMBOL_REPORT = "symbol_report" BOT_REPORT = "bot_report" CHART_IDENTIFIERS = "chart_identifiers" ERRORS_COUNT = "errors_count" report = { SYMBOL_REPORT: [], BOT_REPORT: {}, CHART_IDENTIFIERS: [], ERRORS_COUNT: logging.get_backtesting_errors_count() } profitabilities = {} market_average_profitabilities = {} starting_portfolios = {} end_portfolios = {} for exchange_id in self.octobot_backtesting.exchange_manager_ids: exchange_manager = trading_api.get_exchange_manager_from_exchange_id( exchange_id) _, profitability, _, market_average_profitability, _ = trading_api.get_profitability_stats( exchange_manager) min_timeframe = time_frame_manager.find_min_time_frame( trading_api.get_watched_timeframes(exchange_manager)) exchange_name = trading_api.get_exchange_name(exchange_manager) for symbol in self.symbols_to_create_exchange_classes[ exchange_name]: market_delta = self._get_market_delta(symbol, exchange_manager, min_timeframe) report[SYMBOL_REPORT].append({symbol: market_delta * 100}) report[CHART_IDENTIFIERS].append({ "symbol": symbol, "exchange_id": exchange_id, "exchange_name": exchange_name, "time_frame": min_timeframe.value }) profitabilities[exchange_name] = profitability market_average_profitabilities[ exchange_name] = market_average_profitability starting_portfolios[ exchange_name] = trading_api.get_origin_portfolio( exchange_manager) end_portfolios[exchange_name] = trading_api.get_portfolio( exchange_manager) report[BOT_REPORT] = { "profitability": profitabilities, "market_average_profitability": market_average_profitabilities, "reference_market": reference_market, "end_portfolio": end_portfolios, "starting_portfolio": starting_portfolios, "trading_mode": trading_mode } return report
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 log_report(self): self.logger.info(" **** Backtesting report ****") for exchange_id in self.octobot_backtesting.exchange_manager_ids: exchange_manager = trading_api.get_exchange_manager_from_exchange_id(exchange_id) exchange_name = trading_api.get_exchange_name(exchange_manager) self.logger.info(f" ========= Trades on {exchange_name} =========") self._log_trades_history(exchange_manager, exchange_name) self.logger.info(f" ========= Prices evolution on {exchange_name} =========") min_timeframe = time_frame_manager.find_min_time_frame(trading_api.get_watched_timeframes(exchange_manager)) for symbol in self.symbols_to_create_exchange_classes[exchange_name]: self._log_symbol_report(symbol, exchange_manager, min_timeframe) self.logger.info(" ========= Octobot end state =========") self._log_global_report(exchange_manager)