async def test_enabled(self): config, exchange_manager, trader_inst = await self.init_default() await self.stop(exchange_manager) config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = True assert Trader.enabled(config) config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = False assert not Trader.enabled(config) await self.stop(exchange_manager)
async def create(self, trading_tentacles_path=CONFIG_TRADING_FILE_PATH): await self.exchange_manager.initialize() # set sandbox mode if not self.is_backtesting: self.exchange_manager.exchange.client.setSandboxMode( self.is_sandboxed) if not self.is_simulated: self.trader = Trader(self.config, self.exchange_manager) else: self.trader = TraderSimulator(self.config, self.exchange_manager) try: # check traders activation if not is_trader_enabled( self.config) and not is_trader_simulator_enabled( self.config): raise ValueError( f"No trader simulator nor real trader activated on {self.exchange_manager.exchange.name}" ) # initialize trader await self.trader.initialize() self.exchange_manager.trader = self.trader init_trading_mode_config(self.config, trading_tentacles_path) await create_trading_mode(self.config, self.exchange_manager) # add to global exchanges Exchanges.instance().add_exchange(self.exchange_manager) except Exception as e: self.logger.error( f"An error occurred when creating trader or initializing trading mode : " ) raise e
def is_real(self): self.exchange_manager.is_simulated = False self.exchange_manager.trader = Trader(self.config, self.exchange_manager) return self
async def trader(exchange_manager): config = load_test_config() config[CONFIG_TRADER][CONFIG_ENABLED_OPTION] = True trader_inst = Trader(load_test_config(), exchange_manager) await trader_inst.initialize() return config, exchange_manager, trader_inst