def set_coin(self): self.coin = self.comboBox.currentText() if self.coin != "-": currentPrice = B.get_current_price(self.coin) else: currentPrice = 0 self.coinsetter1 = SetCoin() self.coinsetter1.text_out.connect(self.lineEdit_3.setText) self.coinsetter1.change(str(int(currentPrice * 0.996))) self.coinsetter2 = SetCoin() self.coinsetter2.text_out.connect(self.lineEdit_4.setText) self.coinsetter2.change(str(int(currentPrice * 1.004)))
def sell_all(self, trader): qty = trader.get_balance(self.coin) price = B.get_current_price(self.coin) if price < self.sellPrice: return None, None if qty <= 0: return None, None trader.sell_limit_order(self.coin, price, qty) QtGui.QGuiApplication.processEvents() splt = str(qty).split(".") qtyStr = splt[0] + "." + splt[-1][:6] return "TRY> Coin Limit sell\t" + str( time.ctime()) + "\nPrice: " + str( price) + "\tQuantity: " + qtyStr + "\n", price * qty
def buy_all(self, trader): krw = trader.get_balance("KRW") price = B.get_current_price(self.coin) if price > self.buyPrice: return None, None qty = krw / price qty -= qty % 0.0001 if qty <= 0: return None, None trader.buy_limit_order(self.coin, price, qty) QtGui.QGuiApplication.processEvents() splt = str(qty).split(".") qtyStr = splt[0] + "." + splt[-1][:6] return "TRY> Coin Limit Buy\t" + str(time.ctime()) + "\nPrice: " + str( price) + "\tQuantity: " + qtyStr + "\n", price * qty
def run(self): global doing_job, latest_message if doing_job: self.text_out.emit("Auto Trading Bot Initiated.") self.text_out.emit("Target Coin : " + self.coin + "\n") latest_message = "" bithumb = B(self.access_token, self.secret_key) else: self.text_out.emit("Stop Auto Trading.\n\n") while doing_job: QtGui.QGuiApplication.processEvents() lastBuyWon = None lastSellWon = None coinPrice = B.get_current_price(self.coin) if coinPrice < self.buyPrice: message, lastBuyWon = self.buy_all(bithumb) if not message: continue elif message[:20] == latest_message: continue elif message: self.text_out.emit(message) latest_message = message[:20] QtGui.QGuiApplication.processEvents() elif coinPrice > self.sellPrice: message, lastSellWon = self.sell_all(bithumb) if not message: continue elif message[:20] == latest_message: continue elif message: self.text_out.emit(message) QtGui.QGuiApplication.processEvents() latest_message = message[:20] if lastSellWon and lastBuyWon: self.text_out.emit("Income : " + str(lastSellWon - lastBuyWon) + "₩\n\n") QtGui.QGuiApplication.processEvents() time.sleep(0.5)