def create_take_profit_inputs(self, tab: QTabWidget, innerLayout: QLayout, isOptimizer: bool = False): """ Creates inputs for take profit settings in GUI. :param tab: Tab to create inputs for - simulation, live, or backtest. :param innerLayout: Inner layout to place input widgets on. :param isOptimizer: Boolean for whether optimizer method called this function. """ if isOptimizer: self.takeProfitDict['optimizerTypes'] = [] innerLayout.addRow(QLabel("Take Profit Types")) for takeProfitType in self.takeProfitTypes: checkbox = QCheckBox(f'Enable {takeProfitType} take profit?') innerLayout.addRow(checkbox) self.takeProfitDict['optimizerTypes'].append((takeProfitType, checkbox)) for optimizerType in self.takeProfitOptimizerTypes: self.takeProfitDict[optimizerType, 'start'] = start = get_default_widget(QSpinBox, 1, 0) self.takeProfitDict[optimizerType, 'end'] = end = get_default_widget(QSpinBox, 1, 0) self.takeProfitDict[optimizerType, 'step'] = step = get_default_widget(QSpinBox, 1) add_start_end_step_to_layout(innerLayout, optimizerType, start, end, step) else: self.takeProfitDict[tab, 'takeProfitType'] = takeProfitTypeComboBox = QComboBox() self.takeProfitDict[tab, 'takeProfitPercentage'] = takeProfitPercentage = QDoubleSpinBox() takeProfitTypeComboBox.addItems(self.takeProfitTypes) takeProfitTypeComboBox.currentIndexChanged.connect(lambda: self.update_take_profit_settings(tab)) takeProfitPercentage.setValue(5) takeProfitPercentage.valueChanged.connect(lambda: self.update_take_profit_settings(tab)) innerLayout.addRow(QLabel("Take Profit Type"), takeProfitTypeComboBox) innerLayout.addRow(QLabel('Take Profit Percentage'), takeProfitPercentage)
def create_loss_inputs(self, tab: QTabWidget, innerLayout: QLayout, isOptimizer: bool = False): """ Creates inputs for loss settings in GUI. :param tab: Tab to create inputs for - simulation, live, or backtest. :param innerLayout: Inner layout to place input widgets on. :param isOptimizer: Boolean for whether optimizer method called this function. """ if isOptimizer: self.lossDict['optimizerTypes'] = [] innerLayout.addRow(QLabel("Loss Types")) for loss_type in self.lossTypes: checkbox = QCheckBox( f'Enable {loss_type.lower()} type of stop loss?') innerLayout.addRow(checkbox) self.lossDict['optimizerTypes'].append((loss_type, checkbox)) for optimizer_type in self.lossOptimizerTypes: self.lossDict[optimizer_type, 'start'] = start = get_default_widget( QSpinBox, 1, 0) self.lossDict[optimizer_type, 'end'] = end = get_default_widget( QSpinBox, 1, 0) self.lossDict[optimizer_type, 'step'] = step = get_default_widget(QSpinBox, 1) add_start_end_step_to_layout(innerLayout, optimizer_type, start, end, step) else: self.lossDict[tab, "lossType"] = loss_type_combo_box = QComboBox() self.lossDict[ tab, "lossPercentage"] = loss_percentage = QDoubleSpinBox() self.lossDict[ tab, "smartStopLossCounter"] = smart_stop_loss_counter = QSpinBox() loss_type_combo_box.addItems(self.lossTypes) loss_percentage.setValue(5) innerLayout.addRow(QLabel("Loss Type"), loss_type_combo_box) innerLayout.addRow(QLabel("Loss Percentage"), loss_percentage) innerLayout.addRow(QLabel("Smart Stop Loss Counter"), smart_stop_loss_counter) if tab != self.backtestConfigurationTabWidget: self.lossDict[tab, "safetyTimer"] = safetyTimer = QSpinBox() safetyTimer.valueChanged.connect( lambda: self.update_loss_settings(tab)) innerLayout.addRow(QLabel("Safety Timer"), safetyTimer) loss_type_combo_box.currentIndexChanged.connect( lambda: self.update_loss_settings(tab)) loss_percentage.valueChanged.connect( lambda: self.update_loss_settings(tab)) smart_stop_loss_counter.valueChanged.connect( lambda: self.update_loss_settings(tab))
def load_strategy_slots(config_obj): """ This will initialize all the necessary strategy slots and add them to the configuration GUI. All the strategies are loaded from the self.strategies dictionary. :param config_obj: Configuration QDialog object (from configuration.py) :return: None """ for strategy in config_obj.strategies.values(): temp = strategy() strategyName = temp.name parameters = temp.get_param_types() for tab in config_obj.categoryTabs: config_obj.strategyDict[tab, strategyName] = tabWidget = QTabWidget() descriptionLabel = QLabel(f'Strategy description: {temp.description}') descriptionLabel.setWordWrap(True) layout = QVBoxLayout() layout.addWidget(descriptionLabel) scroll = QScrollArea() # Added a scroll area so user can scroll when additional slots are added. scroll.setWidgetResizable(True) if config_obj.get_caller_based_on_tab(tab) == OPTIMIZER: groupBox, groupBoxLayout = get_regular_groupbox_and_layout(f'Enable {strategyName} optimization?') config_obj.strategyDict[tab, strategyName] = groupBox for index, parameter in enumerate(parameters, start=1): # TODO: Refactor this logic. if type(parameter) != tuple or type(parameter) == tuple and parameter[1] in [int, float]: if type(parameter) == tuple: widget = QSpinBox if parameter[1] == int else QDoubleSpinBox step_val = 1 if widget == QSpinBox else 0.1 else: widget = QSpinBox if parameter == int else QDoubleSpinBox step_val = 1 if widget == QSpinBox else 0.1 config_obj.strategyDict[strategyName, index, 'start'] = start = get_default_widget(widget, 1) config_obj.strategyDict[strategyName, index, 'end'] = end = get_default_widget(widget, 1) config_obj.strategyDict[strategyName, index, 'step'] = step = get_default_widget(widget, step_val) if type(parameter) == tuple: message = parameter[0] else: message = f"{strategyName} {index}" add_start_end_step_to_layout(groupBoxLayout, message, start, end, step) elif type(parameter) == tuple and parameter[1] == tuple: groupBoxLayout.addRow(QLabel(parameter[0])) for option in parameter[2]: config_obj.strategyDict[strategyName, option] = checkBox = QCheckBox(option) groupBoxLayout.addRow(checkBox) else: raise ValueError("Invalid type of parameter type provided.") else: groupBox, groupBoxLayout = get_regular_groupbox_and_layout(f"Enable {strategyName}?") config_obj.strategyDict[tab, strategyName, 'groupBox'] = groupBox status = QLabel() if temp.dynamic: addButton, deleteButton = add_strategy_buttons(config_obj.strategyDict, parameters, strategyName, groupBoxLayout, tab) horizontalLayout = QHBoxLayout() horizontalLayout.addWidget(addButton) horizontalLayout.addWidget(deleteButton) horizontalLayout.addWidget(status) horizontalLayout.addStretch() layout.addLayout(horizontalLayout) values, labels = create_strategy_inputs(parameters, strategyName, groupBoxLayout) config_obj.strategyDict[tab, strategyName, 'values'] = values config_obj.strategyDict[tab, strategyName, 'labels'] = labels config_obj.strategyDict[tab, strategyName, 'parameters'] = parameters config_obj.strategyDict[tab, strategyName, 'layout'] = groupBoxLayout config_obj.strategyDict[tab, strategyName, 'status'] = status layout.addWidget(scroll) scroll.setWidget(groupBox) tabWidget.setLayout(layout) tab.addTab(tabWidget, strategyName)