Ejemplo n.º 1
0
    def collectProcessData(self):

        try:
            
            config = ConfigManager.get_config()

            index = 0

            for x in config.tradeApis:

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

                cposition = client.positions()

                if len(cposition) >= 1:

                    position = cposition[0]

                    direction = ""
                    
                    if position['direction'] == "buy":
                        direction = "Long"
                    else:
                        direction = "Short"

                    self.signeler.emit(index, x, direction, str(position["size"]), str(format(position["sizeBtc"], '.8f')), str(format(position["averagePrice"], '.4f')), str(format(position["profitLoss"], '.8f')), str(format(position["initialMargin"], '.8f')))

                else:
                    self.signeler.emit(index, x, "No Position", "", "", "", "", "")

                index = index + 1

        except Exception as e:
            print(e)
Ejemplo n.º 2
0
    def processOrder(self):

        try:
            config = ConfigManager.get_config()

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

            orders = client.getopenorders(ordertype="stop_market")

            for order in orders:
                client.cancel(order['orderId'])

            self.signeler.emit(
                True, "Cancel All Open Stop Orders Success",
                "Closed All Open Stop Orders On Account: " +
                str(self.accountid))

        except Exception as e:

            self.signeler.emit(
                False, "Cancel Open Stop Orders Error",
                "Failed to cancel open stop orders on " + str(self.accountid) +
                "\n" + str(e))
Ejemplo n.º 3
0
    def processOrder(self):

        try:
            config = ConfigManager.get_config()

            client = RestClient(config.tradeApis[self.accountid][0], config.tradeApis[self.accountid][1], ConfigManager.get_config().apiUrl)
            client.sell_stop_market_order(ConfigManager.get_config().tradeInsturment, float(self.amount), self.price)
        
            self.signeler.emit(True, "Stop Market Sell Order Success", "Stop Market Sell On Account: " + str(self.accountid) + " For Amount: " + str(self.amount) + " At Price: " + str(self.price))

        except Exception as e:
        	
            self.signeler.emit(False, "Stop Market Sell Order Error" , "Failed to stop market sell on " + str(self.accountid) + " for amount: " + str(self.amount) + "\n" + str(e))
Ejemplo n.º 4
0
    def processOrder(self):

        try:
            config = ConfigManager.get_config()

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

            cposition = client.positions()

            if len(cposition) >= 1:

                if cposition[0]['size'] > 0:
                    client.sell(ConfigManager.get_config().tradeInsturment,
                                abs(cposition[0]['size']), 0, "market")
                else:
                    client.buy(ConfigManager.get_config().tradeInsturment,
                               abs(cposition[0]['size']), 0, "market")

            self.signeler.emit(
                True, "Close Position Success",
                "Closed Position On Account: " + str(self.accountid))

        except Exception as e:

            self.signeler.emit(
                False, "Close Position Error", "Failed to close position on " +
                str(self.accountid) + "\n" + str(e))
Ejemplo n.º 5
0
    def processOrder(self):

        try:
            config = ConfigManager.get_config()

            client = RestClient(config.tradeApis[self.accountid][0],
                                config.tradeApis[self.accountid][1],
                                ConfigManager.get_config().apiUrl)
            client.buy(ConfigManager.get_config().tradeInsturment,
                       float(self.amount), 0, "market")

            self.signeler.emit(
                True, "Market Buy Order Success", "Market Buy On Account: " +
                str(self.accountid) + " For Amount: " + str(self.amount))

        except Exception as e:

            self.signeler.emit(
                False, "Market Buy Order Error",
                "Failed to market buy on " + str(self.accountid) +
                " for amount: " + str(self.amount) + "\n" + str(e))
Ejemplo n.º 6
0
    def processOrder(self):

        try:
            config = ConfigManager.get_config()

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

            client.cancel(self.orderid)

            self.signeler.emit(
                True, "Cancel Open Order Success",
                "Closed Open Order On Account: " + str(self.accountid) +
                " With id: " + str(self.orderid))

        except Exception as e:

            self.signeler.emit(
                False, "Cancel Open Order Error",
                "Failed to cancel open order id: " + str(self.orderid) +
                " on " + str(self.accountid) + "\n" + str(e))
Ejemplo n.º 7
0
    def collectProcessData(self):

        try:

            config = ConfigManager.get_config()

            openOrders = []

            for x in config.tradeApis:

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

                orders = client.getopenorders(ordertype="stop_market")

                if len(orders) >= 1:

                    for order in orders:

                        direction = ""

                        if order['direction'] == "buy":
                            direction = "Long"
                        else:
                            direction = "Short"

                        openOrders.append([
                            x, direction,
                            str(order["quantity"]),
                            str(format(order["stopPx"], '.2f')),
                            order['orderId']
                        ])

            self.signeler.emit(openOrders)

        except Exception as e:
            print(e)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
    def collectProcessData(self):

        try:
            config = ConfigManager.get_config()

            if len(config.tradeApis) >= 1:

                creds = list(config.tradeApis.values())[0]

                client = RestClient(creds[0], creds[1],
                                    ConfigManager.get_config().apiUrl)

                lastTrades = client.getlasttrades(
                    ConfigManager.get_config().tradeInsturment)

                tradeList = []

                for trade in lastTrades:

                    direction = ""

                    if trade['direction'] == "buy":
                        direction = "Long"
                    else:
                        direction = "Short"

                    tradeList.append([
                        direction, trade["price"], trade["quantity"],
                        datetime.datetime.utcfromtimestamp(
                            trade["timeStamp"] /
                            1000).strftime('%Y-%m-%d %H:%M:%S')
                    ])

                self.signeler.emit(tradeList)

        except Exception as e:
            print(e)
Ejemplo n.º 10
0
    def collectProcessData(self):

        try:

            config = ConfigManager.get_config()

            if len(config.tradeApis) >= 1:

                creds = list(config.tradeApis.values())[0]

                client = RestClient(creds[0], creds[1],
                                    ConfigManager.get_config().apiUrl)

                orderbook = client.getorderbook(
                    ConfigManager.get_config().tradeInsturment)

                indexPrice = client.index()['btc']

                self.signeler.emit(orderbook['bids'], orderbook['asks'],
                                   str(format(orderbook['mark'], '.2f')),
                                   str(format(indexPrice, '.2f')))

        except Exception as e:
            print(e)
    def processOrder(self):

        try:
            config = ConfigManager.get_config()

            client = RestClient(config.tradeApis[self.accountid][0], config.tradeApis[self.accountid][1], ConfigManager.get_config().apiUrl)
            client.buy(ConfigManager.get_config().tradeInsturment, float(self.amount), 0, "market")

            self.signeler.emit(True, "Market Buy Order Success", "Market Buy On Account: " + str(self.accountid) + " For Amount: " + str(self.amount))

        except Exception as e:
            self.signeler.emit(False, "Scalp Buy Order Error", "Failed to scalp buy on " + str(self.accountid) + " for amount: " + str(self.amount) + "\n" + str(e))

        if position['direction'] == "buy":

                try:

                    self.amount = float(self.scalpAmountInput.text()) * float(self.scalpTPInput.text()) / 100
                    self.price =  round(position["averagePrice"] * (1.0 + float(self.scalpTPInput.text()) / 100), 8)
                    print("Trying to send sell limit order at " + str(price) + " near " + str(position["averagePrice"]))
                    client = RestClient(config.tradeApis[self.accountid][0], config.tradeApis[self.accountid][1],ConfigManager.get_config().apiUrl)
                    client.sell(ConfigManager.get_config().tradeInsturment, amount, price, "limit")