def save_backtest_settings(config_obj): """ Saves backtest settings to JSON file. :param config_obj: Configuration QDialog object (from configuration.py) """ config = { 'type': BACKTEST, 'ticker': config_obj.backtestTickerLineEdit.text(), 'interval': config_obj.backtestIntervalComboBox.currentIndex(), 'startingBalance': config_obj.backtestStartingBalanceSpinBox.value(), 'precision': config_obj.backtestPrecisionSpinBox.value(), 'marginTrading': config_obj.backtestMarginTradingCheckBox.isChecked(), } helper_save(config_obj, BACKTEST, config) filePath = helper_get_save_file_path(config_obj, "Backtest") if filePath: helpers.write_json_file(filePath, **config) file = os.path.basename(filePath) config_obj.backtestConfigurationResult.setText( f"Saved backtest configuration successfully to {file}.") else: config_obj.backtestConfigurationResult.setText( "Could not save backtest configuration.")
def save_live_settings(config_obj): """ Saves live settings to JSON file. :param config_obj: Configuration QDialog object (from configuration.py) """ config = { 'type': LIVE, 'ticker': config_obj.tickerLineEdit.text(), 'interval': config_obj.intervalComboBox.currentIndex(), 'precision': config_obj.precisionSpinBox.value(), 'usRegion': config_obj.usRegionRadio.isChecked(), 'otherRegion': config_obj.otherRegionRadio.isChecked(), 'isolatedMargin': config_obj.isolatedMarginAccountRadio.isChecked(), 'crossMargin': config_obj.crossMarginAccountRadio.isChecked(), 'lowerInterval': config_obj.lowerIntervalCheck.isChecked(), } helper_save(config_obj, LIVE, config) filePath = helper_get_save_file_path(config_obj, "Live") if filePath: helpers.write_json_file(filePath, **config) file = os.path.basename(filePath) config_obj.configurationResult.setText( f"Saved live configuration successfully to {file}.") else: config_obj.configurationResult.setText( "Could not save live configuration.")
def save_simulation_settings(config_obj): """ Saves simulation settings to JSON file. :param config_obj: Configuration QDialog object (from configuration.py) """ config = { 'type': SIMULATION, 'ticker': config_obj.simulationTickerLineEdit.text(), 'interval': config_obj.simulationIntervalComboBox.currentIndex(), 'startingBalance': config_obj.simulationStartingBalanceSpinBox.value(), 'precision': config_obj.simulationPrecisionSpinBox.value(), 'lowerInterval': config_obj.lowerIntervalSimulationCheck.isChecked(), } helper_save(config_obj, SIMULATION, config) filePath = helper_get_save_file_path(config_obj, "Simulation") if filePath: helpers.write_json_file(filePath, **config) file = os.path.basename(filePath) config_obj.simulationConfigurationResult.setText( f"Saved simulation configuration successfully to {file}.") else: config_obj.simulationConfigurationResult.setText( "Could not save simulation configuration.")
def save_credentials(config_obj): """ Function that saves credentials to base path in a JSON format. Obviously not very secure, but temp fix. :param config_obj: Configuration QDialog object (from configuration.py) """ targetFolder = os.path.join(helpers.ROOT_DIR, config_obj.credentialsFolder) helpers.create_folder_if_needed(targetFolder) apiKey = config_obj.binanceApiKey.text() apiSecret = config_obj.binanceApiSecret.text() telegramApiKey = config_obj.telegramApiKey.text() telegramChatId = config_obj.telegramChatID.text() defaultPath = os.path.join(targetFolder, 'default.json') filePath, _ = QFileDialog.getSaveFileName(config_obj, 'Save Credentials', defaultPath, 'JSON (*.json)') filePath = filePath.strip() if filePath: helpers.write_json_file(filePath=filePath, apiKey=apiKey, apiSecret=apiSecret, telegramApiKey=telegramApiKey, chatID=telegramChatId) config_obj.credentialResult.setText( f'Credentials saved successfully to {os.path.basename(filePath)}.') else: config_obj.credentialResult.setText('Credentials could not be saved.')
def save_live_settings(self): """ Saves live settings to JSON file. """ config = { # General 'type': LIVE, 'ticker': self.tickerComboBox.currentIndex(), 'interval': self.intervalComboBox.currentIndex(), 'precision': self.precisionSpinBox.value(), 'usRegion': self.usRegionRadio.isChecked(), 'otherRegion': self.otherRegionRadio.isChecked(), 'isolatedMargin': self.isolatedMarginAccountRadio.isChecked(), 'crossMargin': self.crossMarginAccountRadio.isChecked(), 'lowerInterval': self.lowerIntervalCheck.isChecked(), } self.helper_save(LIVE, config) filePath = self.helper_get_save_file_path("Live") if filePath: helpers.write_json_file(filePath, **config) file = os.path.basename(filePath) self.configurationResult.setText(f"Saved live configuration successfully to {file}.") else: self.configurationResult.setText("Could not save live configuration.")
def save_simulation_settings(self): """ Saves simulation settings to JSON file. """ config = { # General 'type': SIMULATION, 'ticker': self.simulationTickerComboBox.currentIndex(), 'interval': self.simulationIntervalComboBox.currentIndex(), 'startingBalance': self.simulationStartingBalanceSpinBox.value(), 'precision': self.simulationPrecisionSpinBox.value(), 'lowerInterval': self.lowerIntervalSimulationCheck.isChecked(), } self.helper_save(SIMULATION, config) filePath = self.helper_get_save_file_path("Simulation") if filePath: helpers.write_json_file(filePath, **config) file = os.path.basename(filePath) self.simulationConfigurationResult.setText( f"Saved simulation configuration successfully to {file}.") else: self.simulationConfigurationResult.setText( "Could not save simulation configuration.")
def save_backtest_settings(self): """ Saves backtest settings to JSON file. """ config = { # General 'type': BACKTEST, 'ticker': self.backtestTickerComboBox.currentIndex(), 'interval': self.backtestIntervalComboBox.currentIndex(), 'startingBalance': self.backtestStartingBalanceSpinBox.value(), 'precision': self.backtestPrecisionSpinBox.value(), 'marginTrading': self.backtestMarginTradingCheckBox.isChecked(), } self.helper_save(BACKTEST, config) filePath = self.helper_get_save_file_path("Backtest") if filePath: helpers.write_json_file(filePath, **config) file = os.path.basename(filePath) self.backtestConfigurationResult.setText( f"Saved backtest configuration successfully to {file}.") else: self.backtestConfigurationResult.setText( "Could not save backtest configuration.")
def save_state(self): """ Saves bot configuration to a JSON file for next application run. """ config = { 'lightTheme': self.lightModeRadioButton.isChecked(), 'darkTheme': self.darkModeRadioButton.isChecked(), 'bloombergTheme': self.bloombergModeRadioButton.isChecked(), 'bullTheme': self.bullModeRadioButton.isChecked(), 'bearTheme': self.bearModeRadioButton.isChecked(), 'balanceColor': self.balanceColor.currentIndex(), 'avg1Color': self.avg1Color.currentIndex(), 'avg2Color': self.avg2Color.currentIndex(), 'avg3Color': self.avg3Color.currentIndex(), 'avg4Color': self.avg4Color.currentIndex(), 'lineColor': self.hoverLineColor.currentIndex(), 'averagePlot': self.graphIndicatorsCheckBox.isChecked(), } helpers.write_json_file(self.basicFilePath, **config)
def save_config_helper(config_obj, caller, result_label: QLabel, func: Callable): """ Helper function to save configurations. :param config_obj: Configuration object (configuration.py) :param caller: Caller that'll determine which settings get saved. :param result_label: QLabel to modify post-action completion. :param func: Callback function to call for basic caller settings. """ caller_str = get_caller_string(caller) config = func(config_obj) # TODO High priority: Save the optimizer settings. The function below is broken for optimizers. if caller != OPTIMIZER: helper_save(config_obj, caller, config) filePath = helper_get_save_file_path(config_obj, caller_str.capitalize()) if filePath: helpers.write_json_file(filePath, **config) file = os.path.basename(filePath) result_label.setText( f"Saved {caller_str} configuration successfully to {file}.") else: result_label.setText(f"Could not save {caller_str} configuration.")
def save_state(config_obj: Configuration): """ Saves bot configuration to a JSON file for next application run. """ # TODO: Dynamically populate this over time and get rid of this. config = { 'lightTheme': config_obj.lightModeRadioButton.isChecked(), 'darkTheme': config_obj.darkModeRadioButton.isChecked(), 'bloombergTheme': config_obj.bloombergModeRadioButton.isChecked(), 'bullTheme': config_obj.bullModeRadioButton.isChecked(), 'bearTheme': config_obj.bearModeRadioButton.isChecked(), 'balanceColor': config_obj.balanceColor.text(), 'lineColor': config_obj.hoverLineColor.text(), 'hoverLine': config_obj.enableHoverLine.isChecked(), 'averagePlot': config_obj.graphIndicatorsCheckBox.isChecked(), 'failureLimit': config_obj.failureLimitSpinBox.value(), 'failureSleep': config_obj.failureSleepSpinBox.value(), 'chatPass': config_obj.chatPass, 'tokenPass': config_obj.tokenPass, 'telegramResult': config_obj.telegrationConnectionResult.text(), 'hiddenStrategies': list(config_obj.hiddenStrategies), # Tickers 'mainTicker': config_obj.tickerLineEdit.text(), 'simTicker': config_obj.simulationTickerLineEdit.text(), 'backtestTicker': config_obj.backtestTickerLineEdit.text(), 'optimizerTicker': config_obj.optimizerTickerLineEdit.text(), # Intervals 'mainInterval': int(config_obj.intervalComboBox.currentIndex()), 'simInterval': int(config_obj.simulationIntervalComboBox.currentIndex()), 'optimizerInterval': int(config_obj.optimizerIntervalComboBox.currentIndex()), 'optimizerStrategyInterval': int(config_obj.optimizerStrategyIntervalCombobox.currentIndex()), 'optimizerStrategyEndInterval': int(config_obj.optimizerStrategyIntervalEndCombobox.currentIndex()), 'backtestInterval': int(config_obj.backtestIntervalComboBox.currentIndex()), 'backtestStrategyInterval': int(config_obj.backtestStrategyIntervalCombobox.currentIndex()) } helpers.write_json_file(config_obj.stateFilePath, **config)