Exemplo n.º 1
0
def test_init():
    print('init test')
    order_money = 20_000
    my_coin_dict = pyupbit.get_my_coin_info()
    coin_name = ''
    for key, value in my_coin_dict.items():
        coin_name = key
    unit_price = my_coin_dict[coin_name][0]
    quantity = my_coin_dict[coin_name][1]
    coin_value = float(unit_price) * float(quantity)
    print(
        f'코인 단가 : {unit_price}, 수량 : {quantity}, 가치 : {round(float(unit_price) * float(quantity), 2)}'
    )
    # 분단위 캔들
    coin_info = pyupbit.view_candle_min(coin_name)
    # 내가 매수 한 코인 단가
    buy_unit_price = pyupbit.get_my_coin_unit_price(my_coin_dict)
    # 현재 코인 단가
    current_unit_price = pyupbit.get_current_coin_price(coin_info)
    # 수익률(100%가 매수 시점 단가)
    profit_rate = pyupbit.get_profit_rate(current_unit_price, buy_unit_price)
    print(
        f'매수시 코인 단가 : {buy_unit_price}, 현재코인단가 : {current_unit_price}, 수익률 : {profit_rate}'
    )
    if profit_rate > 100:
        print('팔기')
    else:
        print('버티기')
Exemplo n.º 2
0
def sell_all():
    # config.json 자동 매도 기능 허용 여부 확인
    if pyupbit.get_auto_sell() == 'YES':
        myinfo_map = pyupbit.get_my_coin_info()

        if myinfo_map is not None:
            # 코인명
            market = pyupbit.get_my_coin_name(myinfo_map)
            # 내가 구매 한 코인 수
            my_coin_amount = pyupbit.get_my_coin_total_amount(myinfo_map)
            # 분단위 캔들
            coin_info = pyupbit.view_candle_min(market)
            # 코인의 현재 단가(분단위 캔들로 조회)
            current_my_coin_price = pyupbit.get_current_coin_price(coin_info)

            order_price = current_my_coin_price
            order_volume = my_coin_amount
            order_type = 'ask'

            # 전량 매도!
            order_coin(market_name=market,
                       order_money=order_price,
                       order_volume=order_volume,
                       type=order_type)
    else:
        pyupbit.send_message(
            pyupbit.get_slack_channel(),
            '자동 매도 기능을 허용하지 않았습니다. \ninvest_helper에게 요청 하세요.')
Exemplo n.º 3
0
def test_profit_rate():
    print('test start')
    my_investment = pyupbit.get_my_coin_info()
    current_coin = pyupbit.view_candle_min(list(my_investment.keys())[0])
    current_coin_price = pyupbit.get_current_coin_price(current_coin)
    print(
        f'my_investment ::: {my_investment} / current_coin_info ::: {current_coin_price}'
    )
Exemplo n.º 4
0
def order_10000(market_name="KRW-BTC", order_volume=0, order_type='bid'):
    if order_type == 'bid':
        order_money = 10000 / order_volume
    else:
        print(f'대상코인현재정보 ::: {pyupbit.view_candle_min(market_name)}')
        order_money = pyupbit.get_current_coin_price(
            pyupbit.view_candle_min(market_name))
    return order_coin(market_name, order_money, order_volume, order_type)
Exemplo n.º 5
0
def working(market='', my_investment={}, prev_profit_rate=100, score=0, has_minus_exp=False):
    # 해당 코인의 현재 상태(분 캔들) 조회
    coin_candle = pyupbit.view_candle_min(market)
    # 내가 매수 한 코인 단가
    buy_unit_price = pyupbit.get_my_coin_unit_price(my_investment)
    # 내 계좌에 남은 현금
    #krw_balance = pyupbit.get_my_krw_balance(my_investment)
    # 내 계좌에 남은 코인 수
    #my_coin_balance = pyupbit.get_my_coin_total_amount(my_investment)
    # 현재 코인 단가
    current_unit_price = pyupbit.get_current_coin_price(coin_candle)
    # 수익률(100%가 매수 시점 단가)
    profit_rate = pyupbit.get_profit_rate(current_unit_price, buy_unit_price)
    # 스코어(매도시점용)
    score = calc_profit_score(score, prev_profit_rate, profit_rate)
    slack_message1 = f"코인명 ::: {market}(현재빡침점수 : {round(score, 2)}), 매수단가 ::: {buy_unit_price}, 현재단가 ::: {current_unit_price}, 수익률 ::: {str(profit_rate)}%"
    print(slack_message1)
    if profit_rate < 100:
        has_minus_exp = True
    # 수익률 한번이라도 100% 미만인 경우 수익률 기준으로 매도 결정
    if has_minus_exp and profit_rate >= 100:
        pyupbit.sell_all()
        pyupbit.send_message(pyupbit.get_slack_channel(), f'[구사일생으로 팔았음.-{str(datetime.today())}]' + slack_message1)
        print('sell!!')
    else:
        # 매수할 만 하고 코인 단가가 내가 샀을때 보다 살짝 떨어져 있을 때 추가 매수 -> 일단 막기!!
        # if target_price >= current_unit_price and 99 >= profit_rate >= 97:
        # if krw_balance >= 10000:
        # 추가 매수 기능 막음
        # available_coin_amount = pyupbit.get_possible_order_volume(coin_candle, 10000)
        # pyupbit.order_10000(market, available_coin_amount, 'bid')
        # pyupbit.send_message('#myinvestment', f'[Buying!!-{str(datetime.today())}]' + slack_message1)
        #    print('buy!!')
        # 매도 매수 시점 판단 빡침 스코어 기준으로 변경!
        if score > 5:
            pyupbit.sell_all()
            pyupbit.send_message(pyupbit.get_slack_channel(), f'[빡쳐서 팔았음!!-{str(datetime.today())}]' + slack_message1)
            print('sell!!')
        # 수익률이 너무 떨어질 것 같을때 매도
        elif profit_rate < 99:
            pyupbit.sell_all()
            pyupbit.send_message(pyupbit.get_slack_channel(), f'[하락해서 팔았음... -{str(datetime.today())}]' + slack_message1)
            print('sell...')
        # 그 외 상태일 경우
        else:
            print('thinking...')
    # 수익률, 스코어 반환
    return [profit_rate, score, has_minus_exp]
Exemplo n.º 6
0
def check_my_investment():
    profit_rate = 0
    myinfo_map = pyupbit.get_my_coin_info()

    if myinfo_map is not None:
        # 코인명
        market = pyupbit.get_my_coin_name(myinfo_map)
        # 내가 매수 한 코인 단가
        buy_unit_price = pyupbit.get_my_coin_unit_price(myinfo_map)
        # 분단위 캔들
        coin_info = pyupbit.view_candle_min(market)
        # 코인의 현재 단가(분단위 캔들로 조회)
        current_my_coin_price = pyupbit.get_current_coin_price(coin_info)
        # 현재 수익률
        profit_rate = pyupbit.get_profit_rate(current_my_coin_price, buy_unit_price)
    return profit_rate <= 100
Exemplo n.º 7
0
def get_rocketboosting_coins(candle_data, market_name):
    d = candle_data
    # 코인 코드
    market = pyupbit.get_market(d)
    # 목표 코인 단가( 오늘 시작가 + (어제 고가 - 어제 저가) * 0.5 )
    target_price = pyupbit.get_target_price_to_buy(market)
    # 코인 현재 단가
    current_price = pyupbit.get_current_coin_price(d)
    # 전날 대비 변동 률
    change_rate = pyupbit.get_change_rate(d)
    coin_info = pyupbit.get_coin_info_with_candle(d, market_name)
    # 현재 코인 단가가 목표가 보다 높고 단가가 1원 이상인 코인만 필터
    if current_price >= target_price and pyupbit.get_today_opening_price(d) > 1:
        print(f'대상 : {coin_info}')
        pyupbit.send_message(pyupbit.get_slack_channel(), coin_info)
        return {market: change_rate}
    else:
        #print(f'비대상 ::: {coin_info}')
        return None
Exemplo n.º 8
0
def get_investable_coins(market, market_name):
    d = pyupbit.get_candle_data(market)
    # 코인 현재 단가
    current_price = pyupbit.get_current_coin_price(d)
    # 오늘 시가
    today_open_price = pyupbit.get_today_opening_price(d)
    # 어제 고가
    prev_high_price = pyupbit.get_yesterday_high_price(d)
    # 어제 저가
    prev_low_price = pyupbit.get_yesterday_low_price(d)
    # 기준선
    standard_price = pyupbit.calc_standard_line(prev_high_price,
                                                prev_low_price,
                                                today_open_price)
    # 1차 지지선
    first_low_price = pyupbit.first_lower_line(standard_price, prev_high_price)
    # 2차 지지선
    second_low_price = pyupbit.second_lower_line(standard_price,
                                                 prev_high_price,
                                                 prev_low_price)
    # 1차 저항선
    first_high_price = pyupbit.first_higher_line(standard_price,
                                                 prev_low_price)
    # 2차 저항선
    second_high_price = pyupbit.second_higher_line(standard_price,
                                                   prev_high_price,
                                                   prev_low_price)
    # 1차 저항선과 현재 가격 차이
    change_rate = round(current_price / first_high_price * 100, 2)
    # 코인 정보
    coin_info = pyupbit.get_coin_info_with_candle(d, market_name)
    # 1차 저항선을 넘은 코인을 대상으로 한다.
    if second_high_price > current_price > first_high_price and pyupbit.get_today_opening_price(
            d) > 1:
        slack_message = f'1차 저항선을 넘은 코인 : {coin_info}'
        print(slack_message)
        #pyupbit.send_message(pyupbit.get_slack_channel(), slack_message)
        return {market: change_rate}
    else:
        #print(f'비대상 ::: {coin_info}')
        return None
Exemplo n.º 9
0
def get_coin_info_with_candle(d, market_name):
    # 코인 코드
    market = pyupbit.get_market(d)
    # 목표 코인 단가( 오늘 시작가 + (어제 고가 - 어제 저가) * 0.5 )
    target_price = pyupbit.get_target_price_to_buy(market)
    # 코인 현재 단가
    current_price = pyupbit.get_current_coin_price(d)
    # 오늘 시가
    today_open_price = pyupbit.get_today_opening_price(d)
    # 어제 고가
    prev_high_price = pyupbit.get_yesterday_high_price(d)
    # 어제 저가
    prev_low_price = pyupbit.get_yesterday_low_price(d)
    # 기준선
    standard_price = pyupbit.calc_standard_line(prev_high_price, prev_low_price, today_open_price)
    # 1차 지지선
    first_low_price = pyupbit.first_lower_line(standard_price, prev_high_price)
    # 2차 지지선
    second_low_price = pyupbit.second_lower_line(standard_price, prev_high_price, prev_low_price)
    # 1차 저항선
    first_high_price = pyupbit.first_higher_line(standard_price, prev_low_price)
    # 2차 저항선
    second_high_price = pyupbit.second_higher_line(standard_price, prev_high_price, prev_low_price)
    coin_info = f"""
    현재시간 : {datetime.today()}
    코인명: {market} ({market_name}:{str(pyupbit.get_change_rate(d))}%) 
    opening_p:{str(pyupbit.get_today_opening_price(d))} 
    high_p(오늘[어제]):{str(pyupbit.get_today_high_price(d))}[{str(pyupbit.get_yesterday_high_price(d))}] 
    low_p(오늘[어제]):{str(pyupbit.get_today_low_price(d))}[{str(pyupbit.get_yesterday_low_price(d))}] 
    prev_p:{str(pyupbit.get_yesterday_close_price(d))} 
    change_p:{str(pyupbit.get_change_price(d))}
    기준선 : {standard_price}
    1차 지지선 : {first_low_price}
    2차 지지선 : {second_low_price}
    1차 저항선 : {first_high_price}
    2차 저항선 : {second_high_price}
    목표가 : {first_high_price}
    현재가 : {current_price}
    """
    return coin_info
Exemplo n.º 10
0
def new_working(market,
                my_investment={},
                prev_profit_rate=100,
                score=0,
                has_minus_exp=False):
    # 일 캔들 조회
    d = pyupbit.get_candle_data(market)
    # 내가 매수 한 코인 단가
    buy_unit_price = pyupbit.get_my_coin_unit_price(my_investment)
    # 현재 코인 단가
    current_unit_price = pyupbit.get_current_coin_price(d)
    # 수익률(100%가 매수 시점 단가)
    profit_rate = pyupbit.get_profit_rate(current_unit_price, buy_unit_price)
    # 코인 현재 단가
    current_price = pyupbit.get_current_coin_price(d)
    # 오늘 시가
    today_open_price = pyupbit.get_today_opening_price(d)
    # 어제 고가
    prev_high_price = pyupbit.get_yesterday_high_price(d)
    # 어제 저가
    prev_low_price = pyupbit.get_yesterday_low_price(d)
    # 기준선
    standard_price = pyupbit.calc_standard_line(prev_high_price,
                                                prev_low_price,
                                                today_open_price)
    # 1차 지지선
    first_low_price = pyupbit.first_lower_line(standard_price, prev_high_price)
    # 2차 지지선
    second_low_price = pyupbit.second_lower_line(standard_price,
                                                 prev_high_price,
                                                 prev_low_price)
    # 1차 저항선
    first_high_price = pyupbit.first_higher_line(standard_price,
                                                 prev_low_price)
    # 2차 저항선
    second_high_price = pyupbit.second_higher_line(standard_price,
                                                   prev_high_price,
                                                   prev_low_price)
    slack_message1 = f"코인명 ::: {market}(현재 스코어 : {round(score, 2)}), 매수단가 ::: {buy_unit_price}, 현재단가 ::: {current_unit_price}, 수익률 ::: {str(profit_rate)}%"
    print(slack_message1)
    # 매도 시점 판단 로직
    """
    스코어 기준 판단? -> 원래 로직임
    지지선, 저항선 기준 판단 -> 신규 로직
    지지선을 넘었다 -> 망함 -> 버티기?
    저항선을 넘었다 -> 좋음 -> 스코어 기준으로 계산 하기
    """
    # 한번이라도 마이너스 수익률이었으면 has_minus_exp 값 변경해 주기
    if profit_rate < 100:
        has_minus_exp = True
    # 비교 로직
    if current_price > first_high_price:
        # 스코어(매도시점용)
        score = pyupbit.new_calc_profit_score(score, prev_profit_rate,
                                              profit_rate)
        # 스코어 기준 계산 하기(상승시에만 계산하니까 1로 변경)
        if score >= 1:
            pyupbit.sell_all()
            pyupbit.send_message(
                pyupbit.get_slack_channel(),
                f':aaw_yeah: [벌었음!!-1분 뒤 다시 투자 시작 합니다.]' + slack_message1)
            print('sell!!')
            time.sleep(60)
    else:
        # 버티기 -> 손절 포인트 -10% (테스트) -> 손절 시 1시간 생각할 시간을 가지게 하고 다시 들어가기.
        if profit_rate <= pyupbit.get_force_cell_percecnt():
            pyupbit.sell_all()
            slack_message1 = f"""
            ':ahhhhhhhhh: [손절하였습니다...]'
            {slack_message1}
            1시간 뒤 자동투자를 다시 시작 합니다.
            """
            pyupbit.send_message(pyupbit.get_slack_channel(), slack_message1)
            # 손절 매도 시 1시간 휴식
            time.sleep(3600)
        else:
            print('thinking...')
    return [profit_rate, score, has_minus_exp]