示例#1
0
 def get_config():
     if os.path.isfile("config.json"):
         file = open("config.json", "r") 
         return jsonpickle.decode(file.read())
     else:
         Util.get_logger().debug("No configuration found generating new one")
         ConfigManager.create_config()
         file = open("config.json", "r") 
         return jsonpickle.decode(file.read())
示例#2
0
    def update_positions(self, index, account, insturment, size, sizeb,
                         averageprice, pnl, initialmargin):

        self.currentPositionsTable.setItem(index, 0, QTableWidgetItem(account))
        self.currentPositionsTable.setItem(index, 1,
                                           QTableWidgetItem(insturment))
        self.currentPositionsTable.setItem(index, 2, QTableWidgetItem(size))
        self.currentPositionsTable.setItem(index, 3, QTableWidgetItem(sizeb))
        self.currentPositionsTable.setItem(index, 4,
                                           QTableWidgetItem(averageprice))
        self.currentPositionsTable.setItem(index, 5, QTableWidgetItem(pnl))

        if pnl:

            self.currentPositionsTable.setItem(
                index, 6,
                QTableWidgetItem(
                    str(format(Util.percentageOf(pnl, initialmargin), ".2f")) +
                    str("%")))

            if float(str(pnl)) > 0:
                self.currentPositionsTable.item(index, 5).setBackground(
                    QtGui.QColor(27, 94, 32))
                self.currentPositionsTable.item(index, 6).setBackground(
                    QtGui.QColor(27, 94, 32))
            elif float(str(pnl)) < 0:
                self.currentPositionsTable.item(index, 5).setBackground(
                    QtGui.QColor(213, 0, 0))
                self.currentPositionsTable.item(index, 6).setBackground(
                    QtGui.QColor(213, 0, 0))
            else:
                self.currentPositionsTable.item(index, 5).setBackground(
                    QtGui.QColor(26, 35, 126))
                self.currentPositionsTable.item(index, 6).setBackground(
                    QtGui.QColor(26, 35, 126))
        else:
            self.currentPositionsTable.setItem(index, 6, QTableWidgetItem(""))

        self.currentPositionsTable.item(
            index, 0).setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.currentPositionsTable.item(
            index, 1).setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.currentPositionsTable.item(
            index, 2).setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.currentPositionsTable.item(
            index, 3).setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.currentPositionsTable.item(
            index, 4).setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.currentPositionsTable.item(
            index, 5).setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        self.currentPositionsTable.item(
            index, 6).setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter)

        orderButton = QPushButton(self.currentPositionsTable)
        orderButton.setText("Close Position")
        orderButton.clicked.connect(partial(self.do_close_position, account))
        self.currentPositionsTable.setCellWidget(index, 7, orderButton)

        self.currentPositionsTable.update()
示例#3
0
    def do_cancel_all_stop_orders(self):

        config = ConfigManager.get_config()

        try:
            
            for x in config.tradeApis:

                thread = CancelOpenStopOrdersThread(x)
                thread.signeler.connect(self.show_dialogs)
                thread.start()
                self.runningThreads.append(thread)

            Util.show_info_dialog(self, "Order Info", "All Stop Orders On All Accounts Cancelled")

        except Exception as e:
            error_dialog = QErrorMessage(self)
            error_dialog.showMessage(str(e))
            print(e)
示例#4
0
    def collectProcessData(self):

        try:
            
            config = ConfigManager.get_config()

            toreturn = []

            for x in config.tradeApis:

                client = RestClient(config.tradeApis[x][0], config.tradeApis[x][1], ConfigManager.get_config().apiUrl)

                accountinfo = client.account()

                toreturn.append([x, str(format(accountinfo["equity"], '.8f')), str(format(accountinfo["balance"], '.8f')), 
                    str(format(accountinfo["availableFunds"], '.8f')), str(format(accountinfo["initialMargin"], '.8f')), 
                    str(format(Util.percentageOf(accountinfo["initialMargin"],accountinfo["equity"]), '.2f')), str(format(accountinfo["maintenanceMargin"], '.8f')),
                    str(format(Util.percentageOf(accountinfo["maintenanceMargin"],accountinfo["equity"]), '.2f'))])

            self.signeler.emit(toreturn)

        except Exception as e:
            print(e)
示例#5
0
    def show_dialogs(self, success, title, text):

        if success:
            Util.show_info_dialog(self, title, text)
        else:
            Util.show_error_dialog(self, title, text)