Example #1
0
    def clickBtn(self):
        if self.button.text() == "매매시작":
            apiKey = self.apiKey.text()
            secKey = self.secKey.text()
            if len(apiKey) != 32 or len(secKey) != 32:
                self.textEdit.append("KEY가 올바르지 않습니다.")
                return
            else:
                self.bithumb = Bithumb(apiKey, secKey)
                self.balance = self.bithumb.get_balance(self.ticker)
                if self.balance == None:
                    self.textEdit.append("KEY가 올바르지 않습니다.")
                    return

            self.button.setText("매매중지")
            self.textEdit.append("------ START ------")
            self.textEdit.append(f"보유 현금 : {self.balance[2]} 원")

            #self.vw = VolatilityWorker(self.ticker, self.bithumb)'''
            self.vw.tradingSent.connect(self.receiveTradingSignal)
            self.vw.start()
        else:
            self.vw.close()
            self.textEdit.append("------- END -------")
            self.button.setText("매매시작")
Example #2
0
def market_buy(con_key, sec_key, coin):
    bitcoin_api_url = 'https://api.bithumb.com/public/ticker/%s_%s' % (coin,
                                                                       "KRW")
    response = requests.get(bitcoin_api_url)
    response_json = response.json()
    closing_price = response_json['data']['closing_price']
    balance = float(closing_price)
    try:
        available_krw = float(get_balance(con_key, sec_key))
        #available_krw = float(trunc(available_krw,4))

        available_coin_count = float((available_krw * 0.7) / balance)

        available_coin_count = format(float(available_coin_count), ".8f")

        available_coin_count = float(trunc(available_coin_count, 6))

        print("현재 사용가능원화", (available_krw))

        print("현재 시장가", (balance))

        print("현재 구매가능수량", (available_coin_count))

        bithumb = Bithumb(con_key, sec_key)
        result = bithumb.buy_market_order(coin, available_coin_count, "KRW")
        result = "coin : " + coin + "  현재 사용가능원화 : " + str(
            available_krw) + "  현재 시장가 : " + str(
                balance) + "  현재 구매가능수량 : " + str(available_coin_count) + str(
                    result)
    except:
        result = "존재하지 않는 API KEY"

    print("response", str(result))
    return str(result)
Example #3
0
class MainWindow(QMainWindow, form_class):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.ticker = "BTC"
        self.button.clicked.connect(self.clickBtn)
        self.setWindowTitle("Home Trading System")

    def clickBtn(self):
        # ----------------- 수 정 ------------------
        if self.button.text() == "매매시작":
            apiKey = self.apiKey.text()
            secKey = self.secKey.text()
            if len(apiKey) != 32 or len(secKey) != 32:
                self.textEdit.append("KEY가 올바르지 않습니다.")
                return
            else:
                self.bithumb = Bithumb(apiKey, secKey)
                self.balance = self.bithumb.get_balance(self.ticker)
                if self.balance == None:
                    self.textEdit.append("KEY가 올바르지 않습니다.")
                    return

            self.button.setText("매매중지")
            self.textEdit.append("------ START ------")
            self.textEdit.append(f"보유 현금 : {self.balance[2]} 원")
        else:
            self.textEdit.append("------- END -------")
            self.button.setText("매매시작")
Example #4
0
    def clickBtn(self):
        if self.button.text() == "매매시작":
            apiKey = self.apiKey.text()
            secKey = self.secKey.text()
            if len(apiKey) != 32 or len(secKey) != 32:
                self.textEdit.append("KEY가 올바르지 않습니다.")
                return
            else:
                self.bithumb = Bithumb(apiKey, secKey)
                self.balance = self.bithumb.get_balance(self.ticker)
                if self.balance == None:
                    self.textEdit.append("KEY가 올바르지 않습니다.")
                    return

            self.button.setText("매매중지")
            self.textEdit.append("------ START ------")
            self.textEdit.append(f"보유 현금 : {self.balance[2]} 원")
        else:
            self.textEdit.append("------- END -------")
            self.button.setText("매매시작")
Example #5
0
class MainWindow(QMainWindow, form_class):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.ticker = "BTC"
        self.button.clicked.connect(self.clickBtn)
        self.setWindowTitle("Home Trading System")

        with open("bithumb.txt") as f:
            lines = f.readlines()
            apikey = lines[0].strip()
            seckey = lines[1].strip()
            self.apiKey.setText(apikey)
            self.secKey.setText(seckey)

    def clickBtn(self):
        if self.button.text() == "매매시작":
            apiKey = self.apiKey.text()
            secKey = self.secKey.text()
            if len(apiKey) != 32 or len(secKey) != 32:
                self.textEdit.append("KEY가 올바르지 않습니다.")
                return
            else:
                self.bithumb = Bithumb(apiKey, secKey)
                self.balance = self.bithumb.get_balance(self.ticker)
                if self.balance == None:
                    self.textEdit.append("KEY가 올바르지 않습니다.")
                    return

            self.button.setText("매매중지")
            self.textEdit.append("------ START ------")
            self.textEdit.append(f"보유 현금 : {self.balance[2]} 원")

            self.vw = VolatilityWorker(self.ticker, self.bithumb)
            self.vw.tradingSent.connect(self.receiveTradingSignal)
            self.vw.start()
        else:
            self.vw.close()
            self.textEdit.append("------- END -------")
            self.button.setText("매매시작")

    def receiveTradingSignal(self, time, type, amount):
        self.textEdit.append(f"[{time}] {type} : {amount}")

    # ----------------- 추 가 ------------------
    def closeEvent(self, event):
        self.vw.close()
        self.widget.closeEvent(event)
        self.widget_2.closeEvent(event)
        self.widget_3.closeEvent(event)
Example #6
0
    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)))
Example #7
0
    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
Example #8
0
    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
Example #9
0
def get_ohlv(ticker, ms, ml):
    df = Bithumb.get_candlestick(ticker, chart_intervals="12h")
    df = df[['close']].copy()
    df['ma_s'] = df['close'].rolling(ms).mean().shift(1)
    df['ma_l'] = df['close'].rolling(ml).mean().shift(1)
    cond = (df['ma_s'] > df['ma_l'])
    df['status'] = np.where(cond, 1, 0)
    df.iloc[-1, -1] = 0

    if (df['status'][-2] == 0) & (df['status'][-1] == 1):
        return "지금이니"
    elif (df['status'][-2] == 1) & (df['status'][-1] == 0):
        return "팔아!"
    elif (df['status'][-2] == 1) & (df['status'][-1] == 1):
        return "홀딩해"
    elif (df['status'][-2] == 0) & (df['status'][-1] == 0):
        return "도망쳐"
Example #10
0
    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)
Example #11
0
def get_ohlv_MA(ticker):
    df = Bithumb.get_candlestick(ticker, chart_intervals="12h")

    return df
Example #12
0
    long = int(best.iloc[0]['long'])

    result = int(best.iloc[0]['result'])

    return short, long, result


def get_ohlv_MA(ticker):
    df = Bithumb.get_candlestick(ticker, chart_intervals="12h")

    return df


searchMA = pd.DataFrame(columns=['Ticker', 'MAS', 'MAL', 'result'])

for coin in Bithumb.get_tickers():
    f = open("BestMa.txt", 'r')
    try:
        df = get_ohlv_MA(coin)

        short, long, result = ma_long_ma_short(df)
        # get_ohlv(coin, short, long)

        new_data = {
            'Ticker': coin,
            'MAS': short,
            'MAL': long,
            'result': result
        }
        searchMA = searchMA.append(new_data, ignore_index=True)
Example #13
0
 def get_current_data(self):
     return Bithumb.get_market_detail(self.tickers)[3]
Example #14
0
    df['ma_l'] = df['close'].rolling(ml).mean().shift(1)
    cond = (df['ma_s'] > df['ma_l'])
    df['status'] = np.where(cond, 1, 0)
    df.iloc[-1, -1] = 0

    if (df['status'][-2] == 0) & (df['status'][-1] == 1):
        return "지금이니"
    elif (df['status'][-2] == 1) & (df['status'][-1] == 0):
        return "팔아!"
    elif (df['status'][-2] == 1) & (df['status'][-1] == 1):
        return "홀딩해"
    elif (df['status'][-2] == 0) & (df['status'][-1] == 0):
        return "도망쳐"


for coin in Bithumb.get_tickers()[:150]:
    f = open("BestMa.txt", 'r')
    searchMA = pd.DataFrame(columns=['Ticker', 'MAS', 'MAL'])

    try:
        df = get_ohlv_MA(coin)

        short, long = ma_long_ma_short(df)
        get_ohlv(coin, short, long)

        new_data = {'Ticker': coin, 'MAS': short, 'MAL': long}
        searchMA.append(new_data, ignore_index=True)

        print(new_data)
        # data = f"Ticker : {coin} MAS : {short} MAL : {long} \n"
Example #15
0
"""

import sys
from PyQt5 import QtGui
from PyQt5 import QtWidgets as Q
from PyQt5.QtCore import *
import time
from pybithumb import Bithumb as B

doing_job = False

from ui import Ui_Dialog

ui_class = Ui_Dialog

coin_list = ["-"] + B.get_tickers()


class autoTrader(QThread):
    text_out = pyqtSignal(str)

    def __init__(self, access_token, secret_key, coin, buyPrice, sellPrice):
        super().__init__()
        self.access_token = access_token
        self.secret_key = secret_key
        self.coin = coin
        self.buyPrice = buyPrice
        self.sellPrice = sellPrice

    def sell_all(self, trader):
        qty = trader.get_balance(self.coin)