예제 #1
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)
예제 #2
0
def get_trades_history(bot_api=None,
                       symbol=None,
                       independent_backtesting=None,
                       since=None,
                       as_dict=False):
    simulated_trades_history = []
    real_trades_history = []

    for exchange_manager in interfaces.get_exchange_managers(
            bot_api=bot_api, independent_backtesting=independent_backtesting):
        if trading_api.is_trader_existing_and_enabled(exchange_manager):
            if trading_api.is_trader_simulated(exchange_manager):
                simulated_trades_history += trading_api.get_trade_history(
                    exchange_manager, symbol, since, as_dict)
            else:
                real_trades_history += trading_api.get_trade_history(
                    exchange_manager, symbol, since, as_dict)
    return real_trades_history, simulated_trades_history
예제 #3
0
 def _get_traded_volumes(self):
     volume_by_currency = {}
     if self.has_real_trader:
         trades = []
         for exchange_manager in self.exchange_managers:
             trades += trading_api.get_trade_history(
                 exchange_manager, since=self.octobot_api.get_start_time())
         for trade in trades:
             # cost is in quote currency for a traded pair
             currency = symbol_util.split_symbol(trade.symbol)[-1]
             if currency in volume_by_currency:
                 volume_by_currency[currency] += float(trade.total_cost)
             else:
                 volume_by_currency[currency] = float(trade.total_cost)
     return volume_by_currency
예제 #4
0
 def _log_trades_history(self, exchange_manager, exchange_name):
     trades_history_string = "\n".join([pretty_printer.trade_pretty_printer(exchange_name, trade)
                                        for trade in trading_api.get_trade_history(exchange_manager)])
     self.logger.info(f"\n{trades_history_string}")