Ejemplo n.ยบ 1
0
def get_current_price(ticker):
    """ํ˜„์žฌ๊ฐ€ ์กฐํšŒ"""
    orderbook = pyupbit.get_orderbook(tickers=ticker)[0]["orderbook_units"][0]["ask_price"]
    while True :
        if orderbook is None :
            time.sleep(0.7)
            orderbook = pyupbit.get_orderbook(tickers=ticker)[0]["orderbook_units"][0]["ask_price"]
        else :
            break
    return orderbook
Ejemplo n.ยบ 2
0
def buy_crypto_currency():
    krw = upbit.get_balance(TIKER)[2]
    orderbook = pyupbit.get_orderbook(TIKER)
    print(orderbook)
    sell_price = orderbook['asks'][0]['price']
    unit = krw / float(sell_price)
    upbit.buy_market_order(TIKER, unit)
Ejemplo n.ยบ 3
0
    def account_inquiry(self):

        coin_count = len(self.user_info_) - 1  #์ฝ”์ธ ๋ณด์œ  ๊ฐฏ์ˆ˜์ˆ˜

        for i in range(coin_count):
            coin_info = self.user_info_[i + 1]  # ๋ณด์œ ํ•˜๊ณ  ์žˆ๋Š” ์ฝ”์ธ ์ •๋ณด๋ฅผ 1๊ฐœ์”ฉ ๊ฐ€์ ธ์˜จ๋‹ค.

            coin_name = coin_info['currency']
            coin_count = coin_info['balance']
            coin_avg_price = coin_info['avg_buy_price']
            coin_type = coin_info['unit_currency']
            now_price = pyupbit.get_current_price(coin_type + '-' + coin_name)
            orderbook = pyupbit.get_orderbook(coin_type + '-' + coin_name)
            bids_asks = orderbook[0]['orderbook_units']
            down_price = bids_asks[0]['bid_price']
            up_price = bids_asks[0]['ask_price']
            future_yield = coinTool.price_yield(now_price,
                                                self.future_price_LSTM[i])
            limit_count = coinTool.limit_deal_count(now_price)
            coin_yield = coinTool.sell_event_yield(float(up_price),
                                                   float(up_price),
                                                   float(coin_avg_price))

            self.coin_yields.append(coin_yield)
            self.up_prices.append(float(up_price))
            self.down_prices.append(float(down_price))
            self.future_yields.append(float(future_yield))
            self.now_coin_names.append(coin_type + '-' + coin_name)
            self.now_coin_counts.append(float(coin_count))
            self.now_avg_buy_prices.append(float(coin_avg_price))
            self.now_prices.append(float(now_price))
            self.limit_deal_counts.append(float(limit_count))
def retry_sell(ticker, unit, retry_cnt=10):
    '''
    retry count ๋งŒํผ ๋งค๋„ ์‹œ๋„
    :param ticker: ํ‹ฐ์ปค
    :param unit: ๋งค๋„ ์ˆ˜๋Ÿ‰
    :param retry_cnt: ์ตœ๋Œ€ ๋งค์ˆ˜ ์‹œ๋„ ํšŸ์ˆ˜
    :return:
    '''
    try:
        ret = None
        while ret is None and retry_cnt > 0:
            orderbook = pyupbit.get_orderbook(ticker)[0]['orderbook_units'][0]
            buy_price = int(orderbook['bid_price'])  # ์ตœ์šฐ์„  ๋งค์ˆ˜๊ฐ€
            buy_unit = orderbook['bid_size']  # ์ตœ์šฐ์„  ๋งค์ˆ˜์ˆ˜๋Ÿ‰
            min_unit = min(unit, buy_unit)

            if DEBUG is False:
                ret = upbit.sell_limit_order(ticker, buy_price, min_unit)
                time.sleep(INTERVAL)
            else:
                print("SELL API CALLED", ticker, buy_price, min_unit)

            retry_cnt = retry_cnt - 1
    except:
        print("retry sell error")
def try_sell(tickers):
    '''
    ๋ณด์œ ํ•˜๊ณ  ์žˆ๋Š” ๋ชจ๋“  ์ฝ”์ธ์— ๋Œ€ํ•ด ์ „๋Ÿ‰ ๋งค๋„
    :param tickers: ๋น—์ธ์—์„œ ์ง€์›ํ•˜๋Š” ์•”ํ˜ธํ™”ํ์˜ ํ‹ฐ์ปค ๋ชฉ๋ก
    :return:
    '''
    try:
        # ์ž”๊ณ ์กฐํšŒ
        units = get_blance_unit(tickers)

        for ticker in tickers:
            short_ticker = ticker.split('-')[1]
            unit = units.get(ticker, 0)  # ๋ณด์œ  ์ˆ˜๋Ÿ‰

            if unit > 0:
                orderbook = pyupbit.get_orderbook(
                    ticker)[0]['orderbook_units'][0]
                buy_price = int(orderbook['bid_price'])  # ์ตœ์šฐ์„  ๋งค์ˆ˜๊ฐ€
                buy_unit = orderbook['bid_size']  # ์ตœ์šฐ์„  ๋งค์ˆ˜์ˆ˜๋Ÿ‰
                min_unit = min(unit, buy_unit)

                if DEBUG is False:
                    ret = upbit.sell_limit_order(ticker, buy_price, min_unit)
                    time.sleep(INTERVAL)

                    if ret is None:
                        retry_sell(ticker, unit, 10)
                else:
                    print("SELL API CALLED", ticker, buy_price, min_unit)
    except:
        print("try sell error")
Ejemplo n.ยบ 6
0
def buy_crypto_currency(ticker):
    krw = upbit.get_balance() * 0.999
    orderbook = pyupbit.get_orderbook(ticker)
    sell_price = orderbook[0]["orderbook_units"][0]["ask_price"]
    unit = krw / float(sell_price)
    upbit.buy_limit_order(ticker, sell_price, unit)

    print(f"BUYING: {sell_price}")
Ejemplo n.ยบ 7
0
def sell_crypto_currency(ticker):
    orderbook = pyupbit.get_orderbook(ticker)
    bid_price = orderbook[0]["orderbook_units"][0]["bid_price"]
    unit = upbit.get_balances()[-1]["balance"]

    upbit.sell_limit_order(ticker, bid_price, unit)

    print(f"SELL: {bid_price}")
def sell_crypto_currency(ticker):
    bal = upbit.get_balance(ticker.split('-')[1])
    orderbook = pyupbit.get_orderbook(ticker)
    lowest_ask = orderbook[0]['orderbook_units'][0]['ask_price']
    # unit = 100
    print("๋งค๋„ ํ•จ์ˆ˜ ์‹คํ–‰!")
    sell_UID = upbit.sell_limit_order(ticker, lowest_ask, bal - 100)
    print(sell_UID)
    # print(upbit.sell_market_order(ticker, bal-300))
    return lowest_ask
Ejemplo n.ยบ 9
0
def buy_crypto_currency(upbit, ticker):
    # ์›ํ™” ๋ณด์œ ์ˆ˜๋Ÿ‰์„ krw์— ๋ฐ”์ธ๋”ฉ
    krw = upbit.get_balance("KRW")
    # ticker์˜ ํ˜ธ๊ฐ€์ •๋ณด๋ฅผ orderbook์— ๋ฐ”์ธ๋”ฉ
    orderbook = pyupbit.get_orderbook(ticker)
    # orderbook์˜ 0๋ฒˆ์งธ ํ˜ธ๊ฐ€์ •๋ณด๋ฅผ ๊ฐ€์ ธ์™€๋ผ
    sell_price = orderbook[0]['orderbook_units'][0]['ask_price']
    # ๊ตฌ๋งค ๋‹จ์œ„
    unit = krw / float(sell_price) * 0.7
    # ์‹œ์žฅ๊ฐ€ ๋งค์ˆ˜
    return upbit.buy_market_order(ticker, unit)
Ejemplo n.ยบ 10
0
def try_trailling_stop(tickers, prices, targets, noises, holdings,
                       high_prices):
    '''
    trailling stop
    :param tickers: tickers
    :param prices: ํ˜„์žฌ๊ฐ€ ๋ฆฌ์ŠคํŠธ
    :param targets: ๋ชฉํ‘œ๊ฐ€ ๋ฆฌ์ŠคํŠธ
    :param holdings: ๋ณด์œ  ์—ฌ๋ถ€ ๋ฆฌ์ŠคํŠธ
    :param high_prices: ๊ฐ ์ฝ”์ธ์— ๋Œ€ํ•œ ๋‹น์ผ ์ตœ๊ณ ๊ฐ€ ๋ฆฌ์ŠคํŠธ
    :return:
    '''
    try:
        # ์ž”๊ณ  ์กฐํšŒ
        units = get_blance_unit(tickers)

        for ticker in tickers:
            price = prices[ticker]  # ํ˜„์žฌ๊ฐ€
            target = targets[ticker]  # ๋งค์ˆ˜๊ฐ€
            noise = noises[ticker]  # noise
            high_price = high_prices[ticker]  # ๋‹น์ผ ์ตœ๊ณ ๊ฐ€
            unit = units.get(ticker, 0)  # ๋ณด์œ  ์ˆ˜๋Ÿ‰

            gain = (price - target) / target  # ์ด์ต๋ฅ 
            gap_from_high = 1 - (price / high_price)  # ๊ณ ์ ๊ณผ ํ˜„์žฌ๊ฐ€ ์‚ฌ์ด์˜ ๊ฐญ

            # ๋ณด์œ ํ•˜๊ณ  ์žˆ๊ณ  ์ž”๊ณ ๊ฐ€ 0 ์ด์ƒ์ด๊ณ 
            if holdings[ticker] is True and unit > 0:
                # noise๊ฐ€ 0.65 ๋ณด๋‹ค ์ ์€ ์ข…๋ชฉ์€ trailing stop
                # noise๊ฐ€ 0.65 ์ด์ƒ์ธ ์ข…๋ชฉ์€ 10% ์ต์ ˆ, 5% ์†์ ˆ
                if (noise < DUAL_NOISE_LIMIT2
                        and gain >= TRAILLING_STOP_MIN_PROOFIT
                        and gap_from_high >= TRAILLING_STOP_GAP) or (
                            noise >= DUAL_NOISE_LIMIT2 and
                            (gain >= MIN_PROFIT or gain <= -MAX_LOSS)):
                    orderbook = pyupbit.get_orderbook(
                        ticker)[0]['orderbook_units'][0]
                    buy_price = int(orderbook['bid_price'])  # ์ตœ์šฐ์„  ๋งค์ˆ˜๊ฐ€
                    buy_unit = orderbook['bid_size']  # ์ตœ์šฐ์„  ๋งค์ˆ˜์ˆ˜๋Ÿ‰
                    min_unit = min(unit, buy_unit)

                    if DEBUG is False:
                        ret = upbit.sell_limit_order(ticker, buy_price,
                                                     min_unit)
                        time.sleep(INTERVAL)

                        if ret is None:
                            retry_sell(ticker, unit, 10)
                    else:
                        print("trailing stop", ticker, buy_price, min_unit)

                    holdings[ticker] = False
    except:
        print("try trailing stop error")
Ejemplo n.ยบ 11
0
def buy_crypto_currency(ticker):
    cur_wallet = upbit.get_balances()[0]  # ๋ณด์œ ์ค‘์ธ ์›ํ™” GET - ๋ฐฐ์—ด์•ˆ์— ๋”•์…”๋„ˆ๋ฆฌ๋กœ ๋“ค์–ด์˜ด.
    cur_balance = cur_wallet['balance']

    orderbook = pyupbit.get_orderbook(ticker)[0]['orderbook_units']
    sell_price = orderbook[0]['ask_price']  # ์ตœ์šฐ์„  ๋งค๋„ ํ˜ธ๊ฐ€
    unit = math.floor(float(cur_balance) / float(sell_price))
    ret = upbit.buy_limit_order(ticker, sell_price, unit - 1)


    log("current balance : " + str(cur_balance) + " / buy amount : " + str(sell_price * unit) + "won")
    log("buy result : " + str(ret))
Ejemplo n.ยบ 12
0
    def run(self):

        access = "frGzp5hUEaQBNQ1uuO60Dx3QGkSm5ugsEVdfrpnr"
        #secret = lines[1].strip()
        secret = "L4wHqPfrfc7x8NYWHaL8IoUxbV8MBuhoxZG2ZHJa"
        upbit = pyupbit.Upbit(access, secret)

        Ticker = "KRW-DOGE"
        while self.alive:
            orderbook = pyupbit.get_orderbook(Ticker)
            time.sleep(0.1)
            self.dataSent.emit(orderbook)
Ejemplo n.ยบ 13
0
    def get_order_book(self, ticker, position, slippage=2):
        # ticker : ์ฝ”์ธ์‹ฌ๋ณผ๋ช…, postition : ๋งค๋งค๋ฐฉํ–ฅ, slippage : ํ˜ธ๊ฐ€๋ ˆ๋ฒจ์ตœ๋Œ€ํ—ˆ์šฉ์น˜
        # ์Šฌ๋ฆฌํ”ผ์ง€ ๊ธฐ๋ณธ๊ฐ’์€ ์ตœ๋Œ€ 2ํ‹ฑ

        orderbook_list = pyupbit.get_orderbook(ticker)
        bids_asks = orderbook_list[0]['orderbook_units']

        if position == "BUY":
            return float(bids_asks[slippage-1]['ask_price'])

        elif position == "SELL":
            return float(bids_asks[slippage-1]['bid_price'])
Ejemplo n.ยบ 14
0
def buy_crypto_currency(ticker):
    krw = upbit.get_balance("KRW")
    orderbook = pyupbit.get_orderbook(ticker)
    highest_bid = orderbook[0]['orderbook_units'][0]['bid_price']
    #unit = krw/float(sell_price)
    print("๋งค์ˆ˜ ํ•จ์ˆ˜ ์‹คํ–‰!")
    # ๋งค์ˆ˜ ๋ชฉํ‘œ๊ฐ€๋ณด๋‹ค ๋ฐ”๋กœ ์•„๋ž˜ ๊ฐ€๊ฒฉ์— ๋ฆฌ๋ฐ‹ ๋งค์ˆ˜์ฃผ๋ฌธ
    buy_UID = upbit.buy_limit_order(ticker, highest_bid,
                                    (krw / highest_bid) - 100)
    # ์‹œ์žฅ๊ฐ€์— ์ฆ‰์‹œ ๋งค์ˆ˜
    # buy_UID = upbit.buy_market_order(ticker, krw-50000)
    print(buy_UID)
    return highest_bid
Ejemplo n.ยบ 15
0
    def run(self):

        global global_ticker

        while self.alive:

            self.GlobalTicker.emit(global_ticker)
            orderbook = pyupbit.get_orderbook(str(global_ticker))
            
            time.sleep(0.1)
            try:
                self.dataSent.emit(orderbook)
            except:
                print("None type orderbook")
Ejemplo n.ยบ 16
0
def try_trailling_stop(portfolio, prices, targets, holdings, high_prices):
    '''
    trailling stop
    :param portfolio: ํฌํŠธํด๋ฆฌ์˜ค
    :param prices: ํ˜„์žฌ๊ฐ€ ๋ฆฌ์ŠคํŠธ
    :param targets: ๋ชฉํ‘œ๊ฐ€ ๋ฆฌ์ŠคํŠธ
    :param holdings: ๋ณด์œ  ์—ฌ๋ถ€ ๋ฆฌ์ŠคํŠธ
    :param high_prices: ๊ฐ ์ฝ”์ธ์— ๋Œ€ํ•œ ๋‹น์ผ ์ตœ๊ณ ๊ฐ€ ๋ฆฌ์ŠคํŠธ
    :return:
    '''
    try:
        # ์ž”๊ณ  ์กฐํšŒ
        units = get_blance_unit(portfolio)

        for ticker in portfolio:
            price = prices[ticker]                          # ํ˜„์žฌ๊ฐ€
            target = targets[ticker]                        # ๋งค์ˆ˜๊ฐ€
            high_price = high_prices[ticker]                # ๋‹น์ผ ์ตœ๊ณ ๊ฐ€
            unit = units.get(ticker, 0)                     # ๋ณด์œ  ์ˆ˜๋Ÿ‰

            gain = (price - target) / target                # ์ด์ต๋ฅ 
            gap_from_high = 1 - (price/high_price)          # ๊ณ ์ ๊ณผ ํ˜„์žฌ๊ฐ€ ์‚ฌ์ด์˜ ๊ฐญ

            if gain >= TRAILLING_STOP_MIN_PROOFIT and gap_from_high >= TRAILLING_STOP_GAP and holdings[ticker] is True:
                if unit > 0:
                    orderbook = pyupbit.get_orderbook(
                        ticker)[0]['orderbook_units'][0]
                    # ์ตœ์šฐ์„  ๋งค์ˆ˜๊ฐ€
                    buy_price = int(orderbook['bid_price'])
                    # ์ตœ์šฐ์„  ๋งค์ˆ˜์ˆ˜๋Ÿ‰
                    buy_unit = orderbook['bid_size']
                    min_unit = min(unit, buy_unit)

                    if DEBUG is False:
                        ret = upbit.sell_limit_order(
                            ticker, buy_price, min_unit)
                        time.sleep(INTERVAL)

                        if ret is None:
                            retry_sell(ticker, unit, 10)
                    else:
                        print("trailing stop", ticker, buy_price, min_unit)

                    holdings[ticker] = False
    except:
        print("try trailing stop error")
Ejemplo n.ยบ 17
0
def try_buy(tickers, prices, targets, noises, ma5s, budget_per_coin, holdings,
            high_prices):
    '''
    ๋งค์ˆ˜ ์กฐ๊ฑด ํ™•์ธ ๋ฐ ๋งค์ˆ˜ ์‹œ๋„
    :param tickers: ์›ํ™” ํ‹ฐ์ปค
    :param prices: ๊ฐ ์ฝ”์ธ์— ๋Œ€ํ•œ ํ˜„์žฌ๊ฐ€
    :param targets: ๊ฐ ์ฝ”์ธ์— ๋Œ€ํ•œ ๋ชฉํ‘œ๊ฐ€
    :param ma5s: 5์ผ ์ด๋™ํ‰๊ท 
    :param budget_per_coin: ์ฝ”์ธ๋ณ„ ์ตœ๋Œ€ ํˆฌ์ž ๊ธˆ์•ก
    :param holdings: ๋ณด์œ  ์—ฌ๋ถ€
    :return:
    '''
    try:
        for ticker in tickers:
            price = prices[ticker]  # ํ˜„์žฌ๊ฐ€
            target = targets[ticker]  # ๋ชฉํ‘œ๊ฐ€
            noise = noises[ticker]  # ๋…ธ์ด์ฆˆ
            ma5 = ma5s[ticker]  # 5์ผ ์ด๋™ํ‰๊ท 
            high = high_prices[ticker]

            # ๋งค์ˆ˜ ์กฐ๊ฑด
            # 0) noise๊ฐ€ 0.8 ์ดํ•˜์ด๊ณ 
            # 1) ํ˜„์žฌ๊ฐ€๊ฐ€ ๋ชฉํ‘œ๊ฐ€ ์ด์ƒ์ด๊ณ 
            # 2) ๋‹น์ผ ๊ณ ๊ฐ€๊ฐ€ ๋ชฉํ‘œ๊ฐ€ ๋Œ€๋น„ 2% ์ด์ƒ ์˜ค๋ฅด์ง€ ์•Š์•˜์œผ๋ฉฐ (ํ”„๋กœ๊ทธ๋žจ์„ ์žฅ์ค‘์— ์‹คํ–‰ํ–ˆ์„ ๋•Œ ๊ณ ์ ์ฐ๊ณ  ํ•˜๋ฝ์ค‘์ธ ์ข…๋ชฉ์„ ์‚ฌ์ง€ ์•Š๊ธฐ ์œ„ํ•ด)
            # 3) ํ˜„์žฌ๊ฐ€๊ฐ€ 5์ผ ์ด๋™ํ‰๊ท  ์ด์ƒ์ด๊ณ 
            # 4) ํ•ด๋‹น ์ฝ”์ธ์„ ๋ณด์œ ํ•˜์ง€ ์•Š์•˜์„ ๋•Œ
            if noise <= DUAL_NOISE_LIMIT1 and price >= target and high <= target * 1.02 and price >= ma5 and holdings[
                    ticker] is False:
                orderbook = pyupbit.get_orderbook(
                    ticker)[0]['orderbook_units'][0]
                sell_price = int(orderbook['ask_price'])
                sell_unit = orderbook['ask_size']
                unit = budget_per_coin / float(sell_price)
                min_unit = min(unit, sell_unit)

                if DEBUG is False:
                    upbit.buy_limit_order(ticker, sell_price, min_unit)
                else:
                    print("BUY API CALLED", ticker, sell_price, min_unit)

                time.sleep(INTERVAL)
                holdings[ticker] = True
    except:
        print("try buy error")
Ejemplo n.ยบ 18
0
    def uncollected(self):

        if uuid_count == 0:
            pass

        else:
            print('๋ฏธ์ฑ„๊ฒฐ ๊ฑด์ˆ˜ ๋ฐœ์ƒ')

            for i in self.uuid:

                upbit_info.cancel_order(i)
                print('๋ฏธ์ฒด๊ฒฐ ๊ฑด์ˆ˜ ์ฒ˜๋ฆฌ ์™„๋ฃŒ')
                del self.uuid[:]  # ์ฃผ๋ฌธID

        coin_count = len(user_info) - 1  #์ฝ”์ธ ๋ณด์œ  ๊ฐฏ์ˆ˜์ˆ˜

        for i in range(coin_count):
            coin_info = user_info[i + 1]  # ๋ณด์œ ํ•˜๊ณ  ์žˆ๋Š” ์ฝ”์ธ ์ •๋ณด๋ฅผ 1๊ฐœ์”ฉ ๊ฐ€์ ธ์˜จ๋‹ค.

            coin_name = coin_info['currency']
            coin_count = coin_info['balance']
            coin_avg_price = coin_info['avg_buy_price']
            coin_type = coin_info['unit_currency']
            now_price = pyupbit.get_current_price(coin_type + '-' + coin_name)
            orderbook = pyupbit.get_orderbook(coin_type + '-' + coin_name)
            bids_asks = orderbook[0]['orderbook_units']
            down_price = bids_asks[0]['bid_price']
            up_price = bids_asks[0]['ask_price']
            future_yield = coinTool.price_yield(now_price,
                                                self.future_prices[i])
            limit_count = coinTool.limit_deal_count(now_price)

            self.up_prices.append(up_price)
            self.down_prices.append(down_price)
            self.future_yields.append(future_yield)
            self.now_coin_names.append(coin_type + '-' + coin_name)
            self.now_coin_counts.append(coin_count)
            self.now_avg_buy_prices.append(coin_avg_price)
            self.now_prices.append(now_price)
            self.limit_deal_counts.append(limit_count)

        print('ํ˜„์žฌ ๋ณด์œ  ์ฝ”์ธ ๊ฐœ์ˆ˜:', len(self.now_coin_names))
Ejemplo n.ยบ 19
0
    def base_data_info(self):

        base_count = len(self.base_coin_name)

        for i in range(base_count):

            base_now_price = pyupbit.get_current_price(self.base_coin_name[i])
            self.base_coin_now_price.append(base_now_price)

            future_yield = coinTool.price_yield(base_now_price,
                                                self.base_future_price_LSTM[i])
            self.base_futuer_yield.append(future_yield)

            limit_count = coinTool.limit_deal_count(base_now_price)
            self.base_limit_deal_counts.append(float(limit_count))

            a = pyupbit.get_orderbook(tickers=self.base_coin_name[i])
            a1 = a[0]['orderbook_units']
            down_price = a1[0]['bid_price']
            up_price = a1[0]['ask_price']
            self.base_up_prices.append(float(up_price))
            self.base_down_prices.append(float(down_price))
Ejemplo n.ยบ 20
0
def buy_order(ticker, ticker_name):
    a = pyupbit.get_current_price(ticker_name)  # ํ˜„์žฌ๊ฐ€
    b = 0.5 * get_ATR(ticker) + day_ago(2, 'close',
                                        ticker).values  # ์ „์ผ์ข…๊ฐ€ + 0.5ATR
    if a > b:
        f = open(str(os.getcwd()) + '/money', 'r')
        krw = float(f.readline())
        f.close
        orderbook = pyupbit.get_orderbook(ticker_name)  #ํ•ด๋‹น ์ฝ”์ธ ํ˜ธ๊ฐ€ ์กฐํšŒ
        sell_price = orderbook[0]['orderbook_units'][0][
            'ask_price']  #์ตœ์šฐ์„  ๋งค๋„ ํ˜ธ๊ฐ€ ๊ณ„์‚ฐ
        unit = krw * 0.1 / sell_price  #๋งค์ˆ˜ ์ˆ˜๋Ÿ‰
        print("๋งค์ˆ˜:" + ticker_name + ", ๋‹จ๊ฐ€ :", sell_price, '์ˆ˜๋Ÿ‰:', unit)
        f = open('money', 'w')
        money = str(float(krw) - (sell_price * unit))
        f.write(money)
        f.close
        print(datetime.datetime.now())
        with open(str(os.getcwd()) + '/data.pickle', 'rb') as f:
            data = pickle.load(f)
        data[ticker_name] = unit
        with open(str(os.getcwd()) + '/data.pickle', 'wb') as f:
            pickle.dump(data, f, pickle.HIGHEST_PROTOCOL)
Ejemplo n.ยบ 21
0
def get_current_price(ticker):
    """ํ˜„์žฌ๊ฐ€ ์กฐํšŒ"""
   #post_message(myToken,"#stock", "now pay : " +  str(pyupbit.get_orderbook(tickers=ticker)[0]["orderbook_units"][0]["ask_price"]))
    return pyupbit.get_orderbook(tickers=ticker)[0]["orderbook_units"][0]["ask_price"]
Ejemplo n.ยบ 22
0
        # ์ผ์ • ํ…€์„ ๋‘๊ณ  ๋กœ๊ทธ์ธ
        if(repeat_count==2000) :
            upbit = pyupbit.Upbit(access,secret)
            repeat_count=-1
        repeat_count+=1

        # ํ˜ธ๊ฐ€ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

        

        
        # ์ฝ”์ธ ํ•˜๋‚˜์”ฉ ๋ฐ˜๋ณต
        index=0;
        print(keyList)
        for i in coins :
            orderbook = pyupbit.get_orderbook(keyList)
            bids_price=float(orderbook[index]['orderbook_units'][0]['bid_price'])
            asks_price=float(orderbook[index]['orderbook_units'][0]['ask_price'])
            index+=1

            
            # ๋งค์ˆ˜
            if i['order']==0 and bids_price<=i['inputs']['buy_price']*1.005 :
                try:
                    i['order']=upbit.buy_limit_order(i['inputs']['key'], round_price(i['inputs']['buy_price']), buy_amount/i['inputs']['buy_price'])
                finally:
                    print(i['inputs']['key'], '\t', i['order'], '\t' + now)
                    
            # ๋งค๋„
            if(bids_price<i['inputs']['buy_price']) :
                upbit.sell_limit_order(i['inputs']['key'], round_price(i['inputs']['buy_price']*yeild), upbit.get_balance(i['inputs']['key']))
Ejemplo n.ยบ 23
0
<<<<<<< Updated upstream
    buy_list = buy_coin_list()
    print(buy_list)

    # ์ฝ”์ธ ๊ตฌ๋งค
    n = len(buy_list)
    buy_money = round(upbit.get_balance("KRW") / n) * 0.998
    for item in buy_list:
      upbit.buy_market_order(item[0], buy_money)
      time.sleep(0.21)
  except Exception as e:
    print(e)
    time.sleep(1)
=======

# tickers = pyupbit.get_tickers(fiat = 'KRW')
# print(tickers)

df = pyupbit.get_ohlcv("KRW-BTC")
print(df)

n = len(pyupbit.get_orderbook(coin_name)['orderbook_units'])
tmp = pyupbit.get_orderbook(coin_name)['orderbook_units']
ask = [(tmp[i]['ask_size'], tmp[i]['bid_size']) for i in range(n)]
# bid = [pyupbit.get_orderbook(coin_name)['orderbook_units'][i]['bid_size'] for i in range(14)]
print('๋งค์ˆ˜์ž”๋Ÿ‰', ask)
# print('๋งค๋„์ž”๋Ÿ‰', bid)
# print(pyupbit.get_orderbook(coin_name)['orderbook_units'][14]['bid_size'])

>>>>>>> Stashed changes
Ejemplo n.ยบ 24
0
def trade(upbit, position, ticker):

    orderbook = pyupbit.get_orderbook(ticker)

    if position == 'buy':
        balance = float(upbit.get_balances()[0]['balance'])
        bids_asks = orderbook[0]['orderbook_units']
        bid_price = bids_asks[0]['bid_price']
        price = bid_price
        volume = balance / price*0.9994
        ret = upbit.buy_limit_order(ticker, price, volume)
    elif position == 'sell':
        balance = float(upbit.get_balances()[1]['balance'])
        bids_asks = orderbook[0]['orderbook_units']
        ask_price = bids_asks[0]['ask_price']
        price = ask_price
        volume = balance
        ret = upbit.sell_limit_order(ticker, price, volume)

    print(ret)
    uid = ret['uuid']
    state = ret['state']
    time.sleep(1)
    counter = 0

    while state == 'wait':

        server_url = 'https://api.upbit.com'

        query = {
            'uuid': uid,
        }
        query_string = urlencode(query).encode()

        m = hashlib.sha512()
        m.update(query_string)
        query_hash = m.hexdigest()

        payload = {
            'access_key': upbit.access,
            'nonce': str(uuid.uuid4()),
            'query_hash': query_hash,
            'query_hash_alg': 'SHA512',
        }

        jwt_token = jwt.encode(payload, upbit.secret)
        authorize_token = 'Bearer {}'.format(jwt_token)
        headers = {"Authorization": authorize_token}
        res = requests.get(server_url + "/v1/order", params=query, headers=headers)
        state = res.json()['state']

        if state == 'done' or state == 'cancel':
            print(state)
            break
        if counter >= 30:
            ret = upbit.cancel_order(uid)
            state = ret['state']

        counter += 1
        time.sleep(1)

    if position == 'buy':
        balance = float(upbit.get_balances()[1]['balance'])
    elif position == 'sell':
        balance = round(float(upbit.get_balances()[0]['balance']), 2)

    return price, balance
Ejemplo n.ยบ 25
0
def get_current_price(ticker):
    """ํ˜„์žฌ๊ฐ€ ์กฐํšŒ"""
    return pyupbit.get_orderbook(tickers=ticker)[0]["orderbook_units"][0]["ask_price"]
Ejemplo n.ยบ 26
0
import pyupbit
import pprint

orderbooks = pyupbit.get_orderbook("KRW-BTC")
pprint.pprint(orderbooks)
Ejemplo n.ยบ 27
0
            upbit = pyupbit.Upbit(access,secret)
            # ์ตœ๊ทผ nday์ผ๊ฐ„ 24์‹œ๊ฐ„ ๊ณ ๊ฐ€ ์ค‘ ์ตœ์ €๊ฐ€ ์ฐพ๊ธฐ
            if repeat_count == 21600 :
                for i in coins :
                    history = pyupbit.get_ohlcv(i['key'], interval="day", count=nday)['high']
                    history_high = float(history[0])
                    for a in history :
                        if history_high > float(a) :
                            history_high = float(a)
                    history_high=round_price(history_high*1.005)
                    i['price']=history_high
                repeat_count=1
        repeat_count+=1

        # ๊ฑฐ๋ž˜ ์ข…๋ชฉ๋“ค ํ˜ธ๊ฐ€ ๋ถˆ๋Ÿฌ์˜ค๊ธฐ
        orderbook = pyupbit.get_orderbook(inputs)
        
        # ์ฝ”์ธ ํ•˜๋‚˜์”ฉ ๋ฐ˜๋ณต
        index=0;
        for i in coins :
            bids_price=float(orderbook[index]['orderbook_units'][0]['bid_price'])
            asks_price=float(orderbook[index]['orderbook_units'][0]['ask_price'])
            index+=1
            
            # ๋งค์ˆ˜
            if i['order']==0 and bids_price<=i['price']*1.005 :
                try:
                    i['order']=upbit.buy_limit_order(i['key'], i['price'], buy_amount/i['price'])
                finally:
                    print(i['key'], '\t', i['order'], '\t' + now)
                    
Ejemplo n.ยบ 28
0
                "object_type": "text",
                "text": message,
                "link": {
                    "web_url": "www.naver.com"
                }
            })
        }

        requests.post(self.url, headers=self.headers, data=data)


if __name__ == "__main__":
    import pyupbit

    access_key = "Uc7gjRjwxKWtqi3CzE8eBa0GBxKEuvxstqy4VBux"
    secret_key = "BuXKRKaxcPdhL8Htpl1cGsVbqGh0zd10DHVLLxWB"
    upbit = pyupbit.Upbit(access_key, secret_key)

    kakao = Kakao()
    ticker = 'krw-btc'

    orderbook = pyupbit.get_orderbook(ticker)
    bids_asks = orderbook[0]['orderbook_units']
    bid_price = bids_asks[0]['bid_price']

    sellprice = bid_price
    balance = round(float(upbit.get_balances()[0]['balance']), 2)
    ror = 0.98999948
    message = f'{ticker}๋ฅผ {sellprice}์— \n์ „๋Ÿ‰๋งค๋„ ํ–ˆ์Šต๋‹ˆ๋‹ค.\n\n๋งค๋„ ์ฒด๊ฒฐ ํ›„ ์ž”์•ก:\n{balance}์›\n\nํ˜„์žฌ ์ˆ˜์ต๋ฅ : {round((ror-1)*100, 2)}%'
    kakao.send_message2me(message)
Ejemplo n.ยบ 29
0

response = []
sum_prices = []
wait_uuid = 0
#for current_price, orders in zip(y,X):
while True:
    timecount += 1
    df = pyupbit.get_ohlcv(coin, interval="minute1", count=count)
    closes = df['close']
    avg = 0
    for i in closes:
        avg += i
    # ํ‰๊ท  ๊ฐ€๊ฒฉ์„ ๊ตฌํ•จ
    avg /= count
    orderbook = pyupbit.get_orderbook(tickers=coin)
    current_price = pyupbit.get_current_price(coin)
    change = get_change(coin)
    print(change)

    #
    # if timecount <= count:
    #     sum_prices.append(current_price)
    #     try:
    #         sum_price += current_price
    #     except:
    #         count+=1
    #
    #     continue
    # else :
    #     sum_price -= sum_prices[0]
Ejemplo n.ยบ 30
0
def get_current_price(ticker):
    """ํ˜„์žฌ๊ฐ€ ์กฐํšŒ"""
    geckoLogger.info(" ํ˜„์žฌ๊ฐ€ >> " + str(ticker))
    return pyupbit.get_orderbook(
        tickers=ticker)[0]["orderbook_units"][0]["ask_price"]