Exemplo n.º 1
0
 def load_live_settings(self):
     """
     Loads live settings from JSON file and sets it to live settings.
     """
     targetPath = self.create_appropriate_config_folders('Live')
     filePath, _ = QFileDialog.getOpenFileName(self, 'Load Credentials',
                                               targetPath, "JSON (*.json)")
     try:
         config = helpers.load_json_file(filePath)
         file = os.path.basename(filePath)
         if config['type'] != LIVE:
             QMessageBox.about(
                 self, 'Warning',
                 'Incorrect type of non-live configuration provided.')
         else:
             self.tickerComboBox.setCurrentIndex(config['ticker'])
             self.intervalComboBox.setCurrentIndex(config['interval'])
             self.precisionSpinBox.setValue(config['precision'])
             self.usRegionRadio.setChecked(config['usRegion'])
             self.otherRegionRadio.setChecked(config['otherRegion'])
             self.isolatedMarginAccountRadio.setChecked(
                 config['isolatedMargin'])
             self.crossMarginAccountRadio.setChecked(config['crossMargin'])
             self.lowerIntervalCheck.setChecked(config['lowerInterval'])
             self.helper_load(LIVE, config)
             self.configurationResult.setText(
                 f"Loaded live configuration successfully from {file}.")
     except Exception as e:
         self.logger.exception(str(e))
         self.configurationResult.setText(
             "Could not load live configuration.")
Exemplo n.º 2
0
 def load_simulation_settings(self):
     """
     Loads simulation settings from JSON file and sets it to simulation settings.
     """
     targetPath = self.create_appropriate_config_folders('Simulation')
     filePath, _ = QFileDialog.getOpenFileName(self, 'Load Credentials',
                                               targetPath, "JSON (*.json)")
     try:
         config = helpers.load_json_file(filePath)
         file = os.path.basename(filePath)
         if config['type'] != SIMULATION:
             QMessageBox.about(
                 self, 'Warning',
                 'Incorrect type of non-simulation configuration provided.')
         else:
             self.simulationTickerComboBox.setCurrentIndex(config['ticker'])
             self.simulationIntervalComboBox.setCurrentIndex(
                 config['interval'])
             self.simulationStartingBalanceSpinBox.setValue(
                 config['startingBalance'])
             self.simulationPrecisionSpinBox.setValue(config['precision'])
             self.lowerIntervalSimulationCheck.setChecked(
                 config['lowerInterval'])
             self.helper_load(SIMULATION, config)
             self.simulationConfigurationResult.setText(
                 f"Loaded simulation configuration successfully from {file}."
             )
     except Exception as e:
         self.logger.exception(str(e))
         self.simulationConfigurationResult.setText(
             "Could not load simulation configuration.")
Exemplo n.º 3
0
    def load_credentials(self, auto: bool = True):
        """
        Attempts to load credentials automatically from path program regularly stores credentials in if auto is True.
        """
        targetFolder = os.path.join(helpers.ROOT_DIR, self.credentialsFolder)
        if helpers.create_folder_if_needed(targetFolder):
            self.credentialResult.setText('No credentials found.')
            return

        if not auto:
            filePath, _ = QFileDialog.getOpenFileName(self, 'Load Credentials',
                                                      targetFolder,
                                                      "JSON (*.json)")
        else:
            filePath = os.path.join(targetFolder, 'default.json')

        try:
            credentials = helpers.load_json_file(jsonfile=filePath)
            self.binanceApiKey.setText(credentials['apiKey'])
            self.binanceApiSecret.setText(credentials['apiSecret'])
            self.telegramApiKey.setText(credentials['telegramApiKey'])
            self.telegramChatID.setText(credentials['chatID'])
            self.credentialResult.setText(
                f'Credentials loaded successfully from {os.path.basename(filePath)}.'
            )
        except FileNotFoundError:
            self.credentialResult.setText('Could not load credentials.')
        except Exception as e:
            self.credentialResult.setText(str(e))
Exemplo n.º 4
0
 def load_backtest_settings(self):
     """
     Loads backtest settings from JSON file and sets them to backtest settings.
     """
     targetPath = self.create_appropriate_config_folders('Backtest')
     filePath, _ = QFileDialog.getOpenFileName(self, 'Load Credentials',
                                               targetPath, "JSON (*.json)")
     try:
         config = helpers.load_json_file(filePath)
         file = os.path.basename(filePath)
         if config['type'] != BACKTEST:
             QMessageBox.about(
                 self, 'Warning',
                 'Incorrect type of non-backtest configuration provided.')
         else:
             self.backtestTickerComboBox.setCurrentIndex(config['ticker'])
             self.backtestIntervalComboBox.setCurrentIndex(
                 config['interval'])
             self.backtestStartingBalanceSpinBox.setValue(
                 config['startingBalance'])
             self.backtestPrecisionSpinBox.setValue(config['precision'])
             self.backtestMarginTradingCheckBox.setChecked(
                 config['marginTrading'])
             self.helper_load(BACKTEST, config)
             self.backtestConfigurationResult.setText(
                 f"Loaded backtest configuration successfully from {file}.")
     except Exception as e:
         self.logger.exception(str(e))
         self.backtestConfigurationResult.setText(
             "Could not load backtest configuration.")
Exemplo n.º 5
0
    def load_state(self):
        """
        This function will attempt to load previous basic configuration settings from self.basicFilePath.
        :return: None
        """
        if os.path.exists(self.basicFilePath):
            try:
                config = helpers.load_json_file(self.basicFilePath)

                self.lightModeRadioButton.setChecked(config['lightTheme'])
                self.darkModeRadioButton.setChecked(config['darkTheme'])
                self.bloombergModeRadioButton.setChecked(
                    config['bloombergTheme'])
                self.bullModeRadioButton.setChecked(config['bullTheme'])
                self.bearModeRadioButton.setChecked(config['bearTheme'])

                self.balanceColor.setCurrentIndex(config['balanceColor'])
                self.avg1Color.setCurrentIndex(config['avg1Color'])
                self.avg2Color.setCurrentIndex(config['avg2Color'])
                self.avg3Color.setCurrentIndex(config['avg3Color'])
                self.avg4Color.setCurrentIndex(config['avg4Color'])
                self.hoverLineColor.setCurrentIndex(config['lineColor'])

                self.graphIndicatorsCheckBox.setChecked(config['averagePlot'])

                if self.parent:
                    self.parent.add_to_live_activity_monitor(
                        'Loaded previous state successfully.')
            except Exception as e:
                self.logger.exception(str(e))

                if self.parent:
                    self.parent.add_to_live_activity_monitor(
                        'Failed to load previous state.')