def __init__(self, controller, strategy_module, worker_config=None): super().__init__() self.controller = controller self.module_name = strategy_module.split('.')[-1] strategy_class = getattr(importlib.import_module(strategy_module), 'Strategy') configure = strategy_class.configure(False) form_module = controller.strategies[strategy_module]['form_module'] try: widget = getattr(importlib.import_module(form_module), 'Ui_Form') self.strategy_widget = widget() self.strategy_widget.setupUi(self) except (ValueError, AttributeError): # Generate the strategy form widget automatically self.strategy_widget = AutoStrategyFormGenerator( self, configure, worker_config) # Assemble the controller class name parts = self.module_name.split('_') class_name = ''.join(map(str.capitalize, parts)) class_name = ''.join([class_name, 'Controller']) try: # Try to get the controller strategy_controller = getattr( dexbot.controllers.strategy_controller, class_name) except AttributeError: # The controller doesn't exist, use the default controller strategy_controller = getattr( dexbot.controllers.strategy_controller, 'StrategyController') self.strategy_controller = strategy_controller(self, configure, controller, worker_config)
def __init__(self, controller, strategy_module, worker_config=None): super().__init__() self.controller = controller self.module_name = strategy_module.split('.')[-1] strategy_class = getattr( importlib.import_module(strategy_module), 'Strategy' ) # For strategies uses autogeneration, we need the strategy configs without the defaults configure = strategy_class.configure(return_base_config=False) form_module = controller.strategies[strategy_module].get('form_module') try: widget = getattr( importlib.import_module(form_module), 'Ui_Form' ) self.strategy_widget = widget() self.strategy_widget.setupUi(self) except (ValueError, AttributeError): # Generate the strategy form widget automatically self.strategy_widget = AutoStrategyFormGenerator(self, configure) # Assemble the controller class name parts = self.module_name.split('_') class_name = ''.join(map(str.capitalize, parts)) class_name = ''.join([class_name, 'Controller']) try: # Try to get the controller from the internal set strategy_controller = getattr( dexbot.controllers.strategy_controller, class_name ) except AttributeError: try: # look in the strategy module itself (external strategies may do this) strategy_controller = getattr( importlib.import_module(strategy_module), 'StrategyController' ) except AttributeError: # The controller doesn't exist, use the default controller strategy_controller = getattr( dexbot.controllers.strategy_controller, 'StrategyController' ) self.strategy_controller = strategy_controller(self, configure, controller, worker_config)
def __init__(self, controller, strategy_module, config=None): super().__init__() self.controller = controller self.module_name = strategy_module.split('.')[-1] form_module = controller.strategies[strategy_module]['form_module'] widget = getattr(importlib.import_module(form_module), 'Ui_Form') self.strategy_widget = widget() self.strategy_widget.setupUi(self) # Invoke the correct controller class_name = '' if self.module_name == 'relative_orders': class_name = 'RelativeOrdersController' elif self.module_name == 'staggered_orders': class_name = 'StaggeredOrdersController' strategy_controller = getattr(dexbot.controllers.strategy_controller, class_name) self.strategy_controller = strategy_controller(self, controller, config)