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
async def create_exchange_traders(self, ignore_config=False): self.async_loop = asyncio.get_running_loop() available_exchanges = ccxt.exchanges for exchange_class_string in self.config[CONFIG_EXCHANGES]: if exchange_class_string in available_exchanges: exchange_type = getattr(ccxt, exchange_class_string) # Backtesting Exchange if self.backtesting_enabled: exchange_manager = ExchangeManager(self.config, exchange_type, is_simulated=True) else: # Real Exchange exchange_manager = ExchangeManager( self.config, exchange_type, is_simulated=False, ignore_config=ignore_config) await exchange_manager.initialize() exchange_inst = exchange_manager.get_exchange() self.exchanges_list[exchange_inst.get_name()] = exchange_inst self.global_updaters_by_exchange[exchange_inst.get_name( )] = GlobalPriceUpdater(exchange_inst) # create trader instance for this exchange exchange_trader = Trader(self.config, exchange_inst) await exchange_trader.initialize() self.exchange_traders[ exchange_inst.get_name()] = exchange_trader # create trader simulator instance for this exchange exchange_trader_simulator = TraderSimulator( self.config, exchange_inst) await exchange_trader_simulator.initialize() self.exchange_trader_simulators[ exchange_inst.get_name()] = exchange_trader_simulator if not (exchange_trader_simulator.enabled(self.config) or exchange_trader.enabled(self.config)): self.logger.error( f"No trader simulator nor real trader activated on {exchange_inst.get_name()}" ) # create trading mode try: self.trading_mode = get_activated_trading_mode( self.config)(self.config, exchange_inst) self.exchange_trading_modes[ exchange_inst.get_name()] = self.trading_mode self.logger.debug( f"Using {self.trading_mode.get_name()} trading mode") except RuntimeError as e: self.logger.error(e.args[0]) raise e else: self.logger.error( f"{exchange_class_string} exchange not found")
async def _get_tools(event_loop): config = load_test_config() symbol = "BTC/USDT" exchange_traders = {} exchange_traders2 = {} time_frame = TimeFrames.FIVE_MINUTES AdvancedManager.create_class_list(config) exchange_manager = ExchangeManager(config, ccxt.binance, is_simulated=True) await exchange_manager.initialize() exchange_inst = exchange_manager.get_exchange() symbol_time_frame_updater_thread = GlobalPriceUpdater(exchange_inst) 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() trader_inst2.set_enabled(False) trader_inst.portfolio.portfolio["SUB"] = { Portfolio.TOTAL: 0.000000000000000000005, Portfolio.AVAILABLE: 0.000000000000000000005 } trader_inst.portfolio.portfolio["BNB"] = { Portfolio.TOTAL: 0.000000000000000000005, Portfolio.AVAILABLE: 0.000000000000000000005 } trader_inst.portfolio.portfolio["USDT"] = { Portfolio.TOTAL: 2000, Portfolio.AVAILABLE: 2000 } 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) trading_mode_inst = get_activated_trading_mode(config)(config, exchange_inst) _ = EvaluatorTaskManager(config, time_frame, symbol_time_frame_updater_thread, symbol_evaluator, exchange_inst, trading_mode_inst, [], event_loop) trading_mode = HighFrequencyMode(config, exchange_inst) trading_mode.add_symbol_evaluator(symbol_evaluator) decider = trading_mode.get_only_decider_key(symbol) await decider.initialize() return config, exchange_inst, trader_inst, symbol, trading_mode
def _create_global_price_updater(self, exchange_inst) -> None: self.global_updaters_by_exchange[ exchange_inst.get_name()] = GlobalPriceUpdater(exchange_inst)