コード例 #1
0
 def loadHistoricalData(self, coin):
     if (coin == 0):
         pass
     else:
         historicalData = fetchData.getData(self.exchange, "day",
                                            self.coinList[coin - 1])
         self.graph.addHistoricalData(historicalData,
                                      self.coinList[coin - 1])
         self.sim.setHistoricalData(historicalData)
コード例 #2
0
def resourceData(subscription, startDate, endDate, accessToken):
    # Defining loacl variables
    flagForUsageDetails = 0
    usageRawData = {}
    uniqueResourcesDetails = {}

    # Fetch Usage Details
    while (("nextLink" in usageRawData) or (flagForUsageDetails != 1)):
        if flagForUsageDetails != 1:
            url = f'https://management.azure.com/subscriptions/{subscription}/providers/Microsoft.Consumption/usageDetails?api-version=2019-01-01'
            flagForUsageDetails = 1
        else:
            url = usageRawData.get("nextLink")
            usageRawData = {}
            logging.info(
                f"Executing the nextLink in Usage Details API for subscription : {subscription}"
            )

        try:
            usageRawData = json.loads(getData(url, accessToken).text)
        except Exception as err:
            logging.error(err)

        for resource in usageRawData.get("value"):
            if resource.get('properties').get(
                    'instanceId') in uniqueResourcesDetails:
                # updating cost
                uniqueResourcesDetails.get(
                    resource.get('properties').get('instanceId')
                )[1] += resource.get('properties').get("pretaxCost")
            else:
                # Appending resources list
                data = {
                    resource.get('properties').get('instanceId'): [
                        resource.get('properties').get('instanceId'),
                        resource.get('properties').get('pretaxCost'),
                        resource.get('properties').get('currency'),
                        resource.get('properties').get('instanceId').split('/')
                        [4],
                        resource.get('tags'),
                        filterActivityLogs(
                            subscription,
                            resource.get('properties').get('instanceId'),
                            startDate, endDate, accessToken)
                    ]
                }
                uniqueResourcesDetails.update(data)

    return uniqueResourcesDetails
コード例 #3
0
    def compareButtonPressed(self):
        self.removeMessage()
        if len(self.compareList) != 2:
            msgBox = QMessageBox()
            msgBox.setIcon(QMessageBox.Warning)
            msgBox.setText(
                "Invalid number of bots selected - Please select 2 bots")
            msgBox.setWindowTitle("Compare Bots")
            msgBox.setStandardButtons(QMessageBox.Ok)
            msgBox.exec()
            return

        startDate, endDate, coin, ok = ComparisonInputDialog.getUserInput(self)

        if ok:
            bot1 = list(self.compareList.keys())[0]
            bot2 = list(self.compareList.keys())[1]
            self.botOneObject = self.botManager.loadBot(bot1)
            self.botTwoObject = self.botManager.loadBot(bot2)
            self.botOneObject.changeParam('Start Trading Date', startDate)
            self.botOneObject.changeParam('End Trading Date', endDate)
            self.botTwoObject.changeParam('Start Trading Date', startDate)
            self.botTwoObject.changeParam('End Trading Date', endDate)
            if not self.checkBot(self.botOneObject):
                return
            if not self.checkBot(self.botTwoObject):
                return
            try:
                self.data = fetchData.getData(exchange="Gemini",
                                              resolution="day",
                                              coin=coin)
                buySellDataOne = self.botOneObject.processHistoricalData(
                    self.data)
                buySellDataTwo = self.botTwoObject.processHistoricalData(
                    self.data)
                window = CompareWindow(self.data, bot1, bot2, buySellDataOne,
                                       buySellDataTwo, coin, self.botManager)
                self.windows.append(window)
                window.show()
            except IndexError as IE:
                self.displayMessage('Please select an appropriate date range',
                                    'red')
コード例 #4
0
def filterActivityLogs(subscriptionID, instanceID, startDate, endDate,
                       accessToken):
    """
        This function gets creator name of given instance
    """
    callerName = "Null"
    # Fetching data from activity logs API
    data = json.loads(
        getActivityLogs(subscriptionID, instanceID, startDate, endDate,
                        accessToken).text)
    # Iterating through pages in API and finding the last page
    while "nextLink" in data:
        data = json.loads(getData(data.get("nextLink"), accessToken).text)
    # Checking for caller in last value of array
    try:
        callerName = data['value'][-1]['caller']
    except Exception as err:
        logging.error(err)

    return callerName
コード例 #5
0
    def __init__(self):
        super().__init__()

        self.grid_layout = QGridLayout()
        self.setWindowTitle('Coinye')

        # wrapper groupbox to add all components to, and create scroll area
        wrapper = QGroupBox()
        wrapper.setLayout(self.grid_layout)

        scroll = QScrollArea(self)
        scroll.setWidget(wrapper)
        scroll.setWidgetResizable(True)
        layout = QVBoxLayout(self)
        layout.addWidget(scroll)
        layout.setContentsMargins(0, 0, 0, 0)

        # Header area i.e. title + description
        title = QLabel()
        title.setTextFormat(QtCore.Qt.RichText)
        title.setAlignment(QtCore.Qt.AlignLeft)
        title.resize(title.sizeHint())
        title.setWordWrap(True)
        title.setText('''
            <div style="font-size: 20px; font-weight: bold; align-items: center;">Coinye</div>
            <div style="font-size: 14px; text-align: justify; margin-top: 10px; margin-bottom:10px;">
                Coinye is a cryptocurrency backtesting tool.
            </div>
            <hr>
        ''')
        self.grid_layout.addWidget(title, 0, 0, 1, 2)

        # Plotly graph
        firstCoin = 'ETH'
        self.exchange = "Gemini"
        historicalData = fetchData.getData(self.exchange, "day", firstCoin)
        self.graph = GraphView(self, historicalData, firstCoin)
        self.graph.page().settings().setAttribute(
            QtWebEngineWidgets.QWebEngineSettings.ShowScrollBars, False)
        self.grid_layout.addWidget(self.graph, 0, 2, 3, 4)
        self.graph.setMinimumWidth(400)

        # Error message section
        self.error_msg = QLabel()
        self.error_msg.setWordWrap(True)
        self.error_msg.setAlignment(QtCore.Qt.AlignCenter)
        self.error_msg.setMaximumHeight(50)
        self.error_msg.setMinimumHeight(20)
        self.error_msg.hide()
        self.grid_layout.addWidget(self.error_msg, 1, 0, 1, 2)

        self.form = formView.FormView(self)
        self.grid_layout.addWidget(self.form, 2, 0, 1, 2)
        self.grid_layout.setRowStretch(2, 2)

        self.form.setMinimumWidth(310)
        _maxWidth = 480
        self.form.setMaximumWidth(_maxWidth)
        self.grid_layout.setColumnStretch(1, 2)

        # Reset button
        self.grid_layout.setRowStretch(3, 1)
        self.resetButton = QPushButton('Reset Parameters')
        self.resetButton.clicked.connect(self.resetPressed)
        self.resetButton.setEnabled(False)
        self.grid_layout.addWidget(self.resetButton, 3, 1, 1, 1)
        self.resetButton.setMaximumWidth(_maxWidth - 170)

        # Run button
        self.grid_layout.setRowStretch(4, 1)
        self.runButton = QPushButton('Run Simulation')
        self.runButton.clicked.connect(self.buttonPressed)
        self.runButton.setEnabled(False)
        self.grid_layout.addWidget(self.runButton, 4, 1, 1, 1)
        self.runButton.setMaximumWidth(_maxWidth - 170)

        #Load Button
        self.loadButton = QPushButton('Import Bot')
        self.loadButton.setEnabled(True)
        self.loadButton.clicked.connect(self.loadPressed)
        self.grid_layout.addWidget(self.loadButton, 3, 0, 1, 1)

        #Save Button
        self.saveButton = QPushButton('Save Bot')
        self.saveButton.setEnabled(False)
        self.saveButton.clicked.connect(self.savePressed)
        self.grid_layout.addWidget(self.saveButton, 4, 0, 1, 1)

        # Initialise a list of bots, one for each type
        self.listOfBots = [b() for b in bots.Bot.__subclasses__()]

        # Dropdown
        self.dropdown = QComboBox()
        self.dropdown.addItem("--Select a Bot--")
        self.setStyleSheet('''
            QComboBox::item:checked {
                font-weight: bold;
                height: 16px;
            }
        ''')
        for bot in self.listOfBots:
            self.dropdown.addItem(bot.getName())
        self.dropdown.currentIndexChanged.connect(self.selectionchange)

        # Get list of coins
        self.coinList = ["BTC", "ETH", "LTC", "ZEC"]

        # Dropdown
        self.coinDropdown = QComboBox()
        self.coinDropdown.addItem("--Select a Coin--")

        for coin in self.coinList:
            self.coinDropdown.addItem(coin)
        self.coinDropdown.currentIndexChanged.connect(self.loadHistoricalData)

        # log check box
        self.logCheckBox = QCheckBox()
        self.logCheckBox.setText("Logarithmic Y-axis")
        self.logCheckBox.toggled.connect(self.graph.setLog)

        # manage layout of dropdowns
        self.dropdown.setMaximumWidth(200)
        self.coinDropdown.setMaximumWidth(200)
        horizontal_layout = QHBoxLayout()
        horizontal_layout.addStretch(2)
        horizontal_layout.addWidget(self.dropdown)
        horizontal_layout.addWidget(self.coinDropdown)
        horizontal_layout.addWidget(self.logCheckBox)
        horizontal_layout.addStretch(2)
        self.grid_layout.addLayout(horizontal_layout, 4, 3, 1, 1)
        self.grid_layout.setColumnStretch(2, 0)
        self.grid_layout.setColumnStretch(3, 4)
        self.grid_layout.setColumnStretch(4, 0)

        #bot manager
        self.botManager = BotManager(self)
        botlist = self.botManager.getBotNames()

        self.botManagerView = BotManagerView(self, botlist)
        self.botManagerView.setMaximumWidth(_maxWidth)
        self.grid_layout.addWidget(self.botManagerView, 5, 0, 1, 2)

        # Stats Table
        #  self.grid_layout.setRowStretch(4, 3)
        self.statsView = StatisticsView(self)
        self.grid_layout.addWidget(self.statsView, 5, 2, 1, 4)

        # Link view with bot
        self.sim = simulator(self.graph, self.form, self.statsView,
                             historicalData, self)

        # data source label
        self.data_source = QLabel()
        self.data_source.setAlignment(QtCore.Qt.AlignRight)
        self.grid_layout.addWidget(self.data_source, 6, 0, 1, 4)
        self.data_source.setTextFormat(1)
        self.data_source.setOpenExternalLinks(True)
        font = QtGui.QFont()
        font.setWeight(2)
        font.setPointSize(8)
        self.data_source.setFont(font)
        self.data_source.setText(
            f"Data Source: <a href='https://www.cryptodatadownload.com'>cryptodatadownload.com</a>  &nbsp;&nbsp;&nbsp;    Exchange: {self.exchange}"
        )

        #set dropdown to the first coin selected by default
        idx = self.coinDropdown.findText(firstCoin)
        if idx >= 0:
            self.coinDropdown.setCurrentIndex(idx)
コード例 #6
0
     r"\w+", input("type your command or 'help' to get guide\n>>> "))
 if (statementParts[0] == 'help'):
     print("""List of commands:
 
 help                                             get information
 exit                                             to terminate the program
 update pageNumber                                to update the data until the given number of pages[for certain car model]
 brands                                           to see all brands that exist
 models                                           to show the models by company name(brands)
 grab                                             to grab the whole data from a certain car model
 determine                                        an estimation of price by mileage and buildYear
 clean                                            it will clean all data that was collected, useful to clear old data and update again
             """)
 elif (statementParts[0] == "update"):
     pageNumber = int(statementParts[1])
     cars = fetchData.getData(pageNumber, 'all-brands', 'all-models')
     counter = 0
     for car in cars:
         registeration = repository.save(car)
         if (registeration == True):
             counter = counter + 1
     if (counter > 0):
         print("successfully updated...")
         print(f"{counter} added")
     else:
         print("nothing to do, already updated")
 elif (statementParts[0] == "brands"):
     brands = repository.getAllBrands()
     for brand in brands:
         print(f"\t{brand[0]}")
 elif (statementParts[0] == "models"):