def main_process():
    # 시작시간
    start_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # 당일
    now_time = datetime.today().strftime("%Y%m%d%H%M%S")
    today = now_time[0:8]

    # DB 모듈선언
    db_class = dbModule.Database()

    # 당일 기 수행된 데이타가 있다면 clear
    sql = "DELETE from stock_search.stock_captured WHERE capture_tcd = '01'AND substring(capture_dttm, 1, 8) = '%s'" % today
    db_class.execute(sql)
    db_class.commit()

    # 대상건 조회
    sql = "SELECT stc_id, stc_name, num_of_circulation from stock_search.stock_basic where substring(bin(filter_bcd), -1, 1) = '1'"
    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 판별 및 송신
    for row in rows:
        try:
            # 판별대상 데이터
            stc_id = row['stc_id']
            stc_name = row['stc_name']

            # 판별 및 전송 (decision_possible_stock 은 조건에 맞으면 종가를 리턴하고 조건에 안맞으면 0을 리턴한다.)
            deal_info = decision_possible_stock(stc_id)
            price = float(deal_info['cls_price'])
            low_price = float(deal_info['low_price'])
            opn_price = float(deal_info['opn_price'])
            hig_price = float(deal_info['hig_price'])

            deal_qnt = deal_info['dealQnt']
            roq = round((deal_qnt / float(row['num_of_circulation'])) * 100, 2)

            if price > 0:
                # 결과저장
                sql = "insert into stock_search.stock_captured " \
                      "(capture_dttm, stc_id, price, low_price, opn_price, hig_price, rate_of_quant, capture_tcd, msg ) values" \
                      "('%s', '%s', '%d', '%d', '%d', '%d', '%f', '01', '%s')" % \
                      (now_time, stc_id, price, low_price, opn_price, hig_price, roq, '상승가능성 종목확인!!')
                db_class.execute(sql)
                db_class.commit()

        except Exception as ex:
            print("에러: " + stc_id + " [" + stc_name + "]")
            traceback.print_exc()

    # commit
    db_class.commit()

    # 종료 시간
    end_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # 종료메시지
    print("상승예상 가능성 종목 메시지 저장 완료")
    print("시작시각: ", start_time)
    print("종료시각: ", end_time)
Exemple #2
0
def set_headers():
    # 토큰조회
    db_class = dbModule.Database()
    sql = "SELECT access_token from stock_search.kakao_token where msger_tcd = 'kakao'"
    row = db_class.executeOne(sql)

    # 헤더세팅
    headers = {"Authorization": "Bearer " + row['access_token']}
    return headers
def send_message_to_friends(data):
    # 토큰조회
    db_class = dbModule.Database()
    sql = "SELECT code, access_token from stock_search.kakao_token where msger_tcd = 'telegram'"
    row = db_class.executeOne(sql)

    telegram_token = row['access_token']
    chat_id = row['code']
    bot = telegram.Bot(token=telegram_token)
    bot.sendMessage(chat_id=chat_id, text=data)
    print('친구에게 메시지를 성공적으로 보냈습니다.')
def stock_values_delete():

    try:
        db_class = dbModule.Database()
        sql = "DELETE from stock_search.stock_basic"
        db_class.execute(sql)
        db_class.commit()

        return
    except Exception as ex:
        logger.error("ERROR!!!!: stock_values_delete")
        logger.error(ex)
def main_process(input_stc_id=None):
    # 시작시간
    start_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # db 모듈선언
    db_class = dbModule.Database()

    # 대상건 조회(우선주/스펙주제외)
    sql = "SELECT stc_id, stc_name from stock_search.stock_basic " \
          "WHERE tot_value > 500000000000 and face_price > 0 " \
          "and preferred_stc_yn = 'N' " \
          "and stc_name not like '%%스팩%%'"

    # 특정종목번호 들어온 경우는 이를 수행
    if input_stc_id is not None:
        sql = "SELECT stc_id, stc_name from stock_search.stock_basic " \
              "WHERE stc_id = '%s'" % input_stc_id

    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 판별 및 송신
    for i, row in enumerate(rows):
        try:
            if i % 10 == 0:
                print("대형주 우량여부 판단중(우선주/스펙주제외).... 전체:", len(rows), "건, 현재: ",
                      i, "건")

            # 판별대상 데이터
            stc_id = row['stc_id']

            # 판별 및 DB 값 수정
            if screen(stc_id):

                # db 값 변경
                update_stock_fin_info(db_class, stc_id)

        except Exception as ex:
            error_result_dict = {"companyCode": stc_id}
            logger.error(error_result_dict)
            logger.error("ERROR!!!!: main_process")
            logger.error(ex)

    # commit
    db_class.commit()

    # 종료 시간
    end_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # 최종 종료메시지
    print("시작시각: ", start_time)
    print("종료시각: ", end_time)
Exemple #6
0
def decision_capture_stock(stc_id,
                           opn_price=0,
                           hig_price=0,
                           low_price=0,
                           cls_price=0):
    # DB 모듈선언
    db_class = dbModule.Database()

    # 이평선 정보 조회
    sql = "select a.stc_id, a.ma5, a.ma20, a.ma60, a.ma120, a.ma240 " \
          "from stock_search.stock_move_avg a, stock_search.stock_basic b " \
          "where a.stc_id = b.stc_id and a.stc_id = '%s'" % stc_id
    row = db_class.executeOne(sql)

    # 전달값 저장
    tdy_prices_info = daily_stock_price_info(stc_id)[0]
    tdy_cls_price = float(tdy_prices_info['cls_price'])
    tdy_opn_price = float(tdy_prices_info['opn_price'])
    tdy_hig_price = float(tdy_prices_info['hig_price'])
    tdy_low_price = float(tdy_prices_info['low_price'])

    # DB 조회값
    ma20 = float(row['ma20'])

    # 종가가 20 이평선보다 위에 있으면 0 리턴
    if tdy_cls_price > ma20:
        return 0

    # 저가가 20 이평선보다 위에 있으면 0 리턴
    if tdy_low_price > ma20:
        return 0

    # 종가와 20이평선 차이가 2% 초과이면 0 리턴
    if (tdy_cls_price / ma20) > 1.03:
        return 0

    # 저가와 20이평선 차이가 1% 초과이면 0 리턴
    if (tdy_low_price / ma20) > 1.02:
        return 0

    # 종가가 가능성 판별일 종가보다 3% 초과인 경우 현재가 리턴
    if (tdy_cls_price / cls_price) > 1.03:
        return 0

    # 종가가 가능성 판별일 종가보다 3% 미달인 경우 현재가 리턴
    if (tdy_cls_price / cls_price) < 0.97:
        return 0

    # 끝까지 모든 조건 미충족시 0 리턴
    return tdy_cls_price
def preferred_stock_values_update():

    try:
        db_class = dbModule.Database()
        sql = "UPDATE stock_search.stock_basic set preferred_stc_yn = 'Y'" \
              "WHERE substr(stc_name,-1) in ('우', 'B', 'C')" \
              "and stc_name like '%우%'" \
              "and stc_name not in ('미래에셋대우', '연우', '나우IB', '이오플로우')"
        db_class.execute(sql)
        db_class.commit()

        return
    except Exception as ex:
        logger.error("ERROR!!!!: preferred_stock_values_update")
        logger.error(ex)
Exemple #8
0
def oauth():
    code = str(request.args.get('code'))
    resToken = getAccessToken("c1889aaa44f7ace2b5e149d9e6c1433d", str(code))
    result = getUserInfo(resToken)

    # owner가 아니면 리턴
    if result['id'] != 1535632259:
        return '로그인 및 약관동의 완료!! \n 이제 카카오톡에서 findstockgogo 친구추가 해주세요.'

    # 기존 owner 계정 토큰 제거
    db_class = dbModule.Database()
    sql = "DELETE from stock_search.kakao_token where msger_tcd = 'kakao'"
    db_class.execute(sql)

    # 신규 owner 계정 토큰 저장
    sql = "INSERT INTO stock_search.kakao_token(" \
          "msger_tcd, " \
          "code, " \
          "access_token, " \
          "token_type, " \
          "refresh_token, " \
          "expires_in, " \
          "scope, " \
          "refresh_token_expires_in) " \
          "VALUES('kakao', '%s', '%s', '%s', '%s', '%s', '%s', '%s')" % \
          (str(code),  str(resToken['access_token']),  str(resToken['token_type']),
           str(resToken['refresh_token']),  str(resToken['expires_in']),
           str(resToken['scope']),  str(resToken['refresh_token_expires_in']))
    db_class.execute(sql)
    db_class.commit()

    return '토큰발급 완료!!' + \
           '<br/>code=' + str(code) + \
           '<br/>access_token=' + str(resToken['access_token']) + \
           '<br/>token_type=' + str(resToken['token_type']) + \
           '<br/>refresh_token=' + str(resToken['refresh_token']) + \
           '<br/>expires_in=' + str(resToken['expires_in']) + \
           '<br/>scope=' + str(resToken['scope']) + \
           '<br/>refresh_token_expires_in=' + str(resToken['refresh_token_expires_in'])
def stock_values_insert_to_db(insert_value):
    stc_id = insert_value['stcId']
    stc_name = insert_value['stcNm']
    stc_dvsn = insert_value['stcDvsn']
    now_price = insert_value['nowPrice']
    face_price = insert_value['facePrice']
    tot_value = insert_value['totValue']
    deal_amt = insert_value['dealAmt']

    try:
        db_class = dbModule.Database()
        sql = "INSERT INTO stock_search.stock_basic(" \
              "stc_id, " \
              "stc_name, " \
              "stc_dvsn, " \
              "now_price, " \
              "face_price, " \
              "tot_value, " \
              "deal_amt, " \
              "filter_bcd) " \
              "VALUES('%s', '%s', '%s', '%d', '%d', '%d', '%d', '%d')" % \
              (stc_id, stc_name, stc_dvsn,
               now_price, face_price, tot_value, deal_amt, 0)
        db_class.execute(sql)
        db_class.commit()
        return
    except Exception as ex:
        error_result_dict = {
            "companyCode": insert_value['stcId'],
            "sosok": insert_value['sosok'],
            "page": insert_value['page'],
            "stockOrder": insert_value['stockOrder']
        }
        logger.error(error_result_dict)
        logger.error("ERROR!!!!: stock_values_insert_to_db")
        logger.error(ex)
def main_process(term):
    # 시작시간
    start_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # DB 모듈선언
    db_class = dbModule.Database()

    # 대상건 조회
    sql = "SELECT stc_id, stc_dvsn, now_price " \
          "from stock_search.stock_basic " \
          "where substring(bin(filter_bcd), -1, 1) = '1'"
    # sql = "SELECT stc_id, stc_dvsn, now_price from stock_search.stock_basic where stc_id = '005930'"
    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 전고점 추출
    for i, row in enumerate(rows):
        try:
            # 대상 데이터
            stc_id = row['stc_id']
            stc_dvsn = row['stc_dvsn']
            now_price = row['now_price']

            # 과거 고가, 저가 추출
            priceList = crawlPrice(stc_id, term)

            # 가격정보중 고가/저가만 추출하여 저장
            extractList = []
            for priceInfo in priceList:
                extractList.append(int(priceInfo['hig_price']))
                extractList.append(int(priceInfo['low_price']))

            # 전고점 계산
            resistance_price = crp(stc_dvsn, now_price, extractList)
            resistance_price_str = listToString(resistance_price)

            # 과거 종가 추출(3개월)
            priceList = crawlPrice(stc_id, 3)

            # 가격정보중 종가만 추출하여 저장
            extractList = []
            for priceInfo in priceList:
                extractList.append(int(priceInfo['cls_price']))

            # 변이계수 계산
            cv = calcModule.coefficient_of_variation(extractList)['cv']

            # 결과저장
            sql = "UPDATE stock_search.stock_basic " \
                  "set resistance_price = '%s' , coef_variation = '%f'" \
                  "where stc_id = '%s'" \
                  % (resistance_price_str, cv, stc_id)
            db_class.execute(sql)
            db_class.commit()

            # 진행상황
            if i % 10 == 0:
                print("총 %d건 중 %d건 완료" % (len(rows), i))
        except Exception as ex:
            logger.error("ERROR!!!!: main_process")
            logger.error(ex)

    # commit
    db_class.commit()

    # 종료 시간
    end_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # 종료메시지
    print("지지선 저항선 설정 완료")
    print("시작시각: ", start_time)
    print("종료시각: ", end_time)
Exemple #11
0
def set_ma(in_stc_id=None):
    # DB 모듈선언
    db_class = dbModule.Database()

    # 데이타 clear
    if in_stc_id is not None:
        sql = "DELETE from stock_search.stock_move_avg WHERE stc_id = '%s'" % in_stc_id
    else:
        if len(sys.argv) > 1:
            if sys.argv[1] == 'other_day':
                sql = "DELETE from stock_search.stock_move_avg a where exists ( " \
                      "select 'x' from stock_search.stock_basic z where z.stc_id = a.stc_id and bin(z.filter_bcd) > 0)"
            elif sys.argv[1] == 'friday':
                sql = "DELETE from stock_search.stock_move_avg"
        else:
            sql = "DELETE from stock_search.stock_move_avg"
    db_class.execute(sql)
    db_class.commit()

    # 대상건 조회
    if in_stc_id is not None:
        sql = "SELECT stc_id FROM stock_search.stock_basic WHERE stc_id = '%s'" % in_stc_id
    else:
        if len(sys.argv) > 1:
            if sys.argv[1] == 'other_day':
                sql = "SELECT stc_id FROM stock_search.stock_basic where bin(filter_bcd) > 0"
            elif sys.argv[1] == 'friday':
                sql = "SELECT stc_id FROM stock_search.stock_basic "
        else:
            sql = "SELECT stc_id FROM stock_search.stock_basic "
    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 data 세팅
    for i, row in enumerate(rows):
        try:
            if i % 10 == 0:
                print("이평선정보 계산중.... 전체:", len(rows), "건, 현재: ", i, "건")

            # 대상 데이터
            stc_id = row['stc_id']

            # 현재가 및 이동평균가격
            price_info = cal_move_avg_values(stc_id)
            now_price = price_info['now_price']
            ma5 = price_info['ma5']
            ma20 = price_info['ma20']
            ma60 = price_info['ma60']
            ma120 = price_info['ma120']
            ma240 = price_info['ma240']

            # 이평선정보 저장
            sql = "insert into stock_search.stock_move_avg (stc_id ,now_price, ma5, ma20, ma60, ma120, ma240) " \
                  "values( '%s','%d','%d','%d','%d','%d','%d')" % (stc_id, now_price, ma5, ma20, ma60, ma120, ma240)
            db_class.execute(sql)
            db_class.commit()
        except Exception as ex:
            traceback.print_exc()

    db_class.commit()
    print("이평선정보 재설정 완료")
    return
def main_process():
    # 시작시간
    start_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # db 모듈선언
    db_class = dbModule.Database()

    # # 초기화
    # sql = "UPDATE stock_search.stock_basic SET filter_bcd = 0"
    # db_class.execute(sql)
    # db_class.commit()

    # 대상건 조회(우선주/스펙주제외)
    sql = "SELECT stc_id, stc_name from stock_search.stock_basic " \
          "WHERE tot_value < 500000000000 and face_price > 0 " \
          "and preferred_stc_yn = 'N' " \
          "and stc_name not like '%%스팩%%'"
    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 판별 및 송신
    for i, row in enumerate(rows):
        try:
            if i % 10 == 0:
                print("판단중(우선주/스펙주제외).... 전체:", len(rows), "건, 현재: ", i, "건")

            # 판별대상 데이터
            stc_id = row['stc_id']

            # 판별 및 DB 값 수정
            if screen(stc_id):

                # db 값 변경
                update_stock_fin_info(db_class, stc_id)

        except Exception as ex:
            error_result_dict = {"companyCode": stc_id}
            logger.error(error_result_dict)
            logger.error("ERROR!!!!: main_process")
            logger.error(ex)

    # 종료 메시지
    db_class.commit()
    print("재무 가격 정보 판단완료!!!!")

    # 대상건 조회(우선주 only)
    sql = "SELECT stc_id, stc_name from stock_search.stock_basic " \
          "WHERE preferred_stc_yn = 'Y' "
    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 판별 및 송신
    for i, row in enumerate(rows):
        try:
            if i % 10 == 0:
                print("판단중(우선주).... 전체:", len(rows), "건, 현재: ", i, "건")

            # 처리대상 데이터
            stc_id = row['stc_id']

            # db 값 변경
            update_stock_cap_info(db_class, stc_id)

        except Exception as ex:
            error_result_dict = {"companyCode": stc_id}
            logger.error(error_result_dict)
            logger.error("ERROR!!!!: main_process")
            logger.error(ex)

    # 종료 메시지
    db_class.commit()
    print("우선주 상장 주식수 정보 획득완료!!!!")

    # 종료 시간
    end_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # 최종 종료메시지
    print("전체 프로세스 종료!!!")
    print("시작시각: ", start_time)
    print("종료시각: ", end_time)
Exemple #13
0
def main_process():
    # 시작시간
    start_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # 당일
    now_time = datetime.today().strftime("%Y%m%d%H%M%S")
    today = now_time[0:8]

    # 조회 기준일
    base_time = (datetime.today() - timedelta(days=30)).strftime("%Y%m%d%H%M%S")
    base_dt = base_time[0:8]

    # 제외 기준일
    except_time = (datetime.today() - timedelta(days=7)).strftime("%Y%m%d%H%M%S")
    except_dt = except_time[0:8]

    # DB 모듈선언
    db_class = dbModule.Database()

    # 당일 기 수행된 데이타가 있다면 clear
    sql = "DELETE from stock_search.stock_captured WHERE capture_tcd = '04' AND substring(capture_dttm, 1, 8) = '%s'" % today
    db_class.execute(sql)
    db_class.commit()

    # 대상건 조회
    # 30일 이내에 상승 가능성 예측된 종목 중에서 유통주식수 대비 거래량이 0% 이상인 것 추출
    # 그 중에서 7일 이내에 상승예상 종목 확인으로 알림 준것은 제외 한다.
    sql = "SELECT distinct a.stc_id, a.stc_name " \
          "from stock_search.stock_basic a, stock_search.stock_captured b " \
          "where a.stc_id = b.stc_id and b.capture_tcd = '01' " \
          "and b.rate_of_quant > %d " \
          "AND substring(b.capture_dttm, 1, 8) >= '%s'" \
          "AND (a.stc_id, a.stc_name) NOT IN(" \
          "SELECT a.stc_id, a.stc_name " \
          "from stock_search.stock_basic a, stock_search.stock_captured b " \
          "where a.stc_id = b.stc_id and b.capture_tcd = '04' " \
          "AND substring(b.capture_dttm, 1, 8) >= '%s')" % (0, base_dt, except_dt)
    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 판별 및 송신
    for row in rows:
        try:
            # 판별대상 데이터
            stc_id = row['stc_id']
            stc_name = row['stc_name']

            # 가능성 식별시점 가격 조회
            inner_sql = "select price, low_price, hig_price, opn_price " \
                        "from stock_search.stock_captured " \
                        "where stc_id = '%s' and capture_tcd = '01' " \
                        "order by capture_dttm desc" % stc_id
            inner_row = db_class.executeOne(inner_sql)

            opn_price = float(inner_row['opn_price'])
            hig_price = float(inner_row['hig_price'])
            low_price = float(inner_row['low_price'])
            cls_price = float(inner_row['price'])

            # 판별 및 전송 (capture_stock 은 조건에 맞으면 종가를 리턴하고 조건에 안맞으면 0을 리턴한다.)
            price = decision_capture_stock(stc_id, opn_price, hig_price, low_price, cls_price)
            if price > 0:

                # 데이터 세팅 및 텔레그램 메시지 송신
                msg = telegramModule.set_data(stc_id, stc_name, '상승예상 종목확인!!')
                telegramModule.send_message_to_friends(msg)

                # 결과저장
                sql = "insert into stock_search.stock_captured (capture_dttm, stc_id, price, capture_tcd, msg ) " \
                      "values('%s', '%s', '%d', '04', '%s')" % (now_time, stc_id, price, '상승예상 종목확인!!')
                db_class.execute(sql)
                db_class.commit()

        except Exception as ex:
            traceback.print_exc()

    # commit
    db_class.commit()

    # 종료 시간
    end_time = datetime.today().strftime("%Y-%m-%d %H:%M:%S")

    # 종료메시지
    print("급등임박 종목 메시지 송신 완료")
    print("시작시각: ", start_time)
    print("종료시각: ", end_time)
Exemple #14
0
def get_ma_and_send_message(in_stc_id=None):
    # DB 모듈선언
    db_class = dbModule.Database()

    # 당일
    now_time = datetime.today().strftime("%Y%m%d%H%M%S")

    # 대상건 조회
    sql = "select a.stc_id, b.stc_name, a.now_price, a.ma5, a.ma20, a.ma60, a.ma120, a.ma240 " \
          "from stock_search.stock_move_avg a, stock_search.stock_basic b " \
          "where a.stc_id = b.stc_id and substring(bin(b.filter_bcd), -2, 1) = '1'"

    if in_stc_id is not None:
        sql = "select a.stc_id, b.stc_name, a.now_price, a.ma5, a.ma20, a.ma60, a.ma120, a.ma240 " \
              "from stock_search.stock_move_avg a, stock_search.stock_basic b " \
              "where a.stc_id = b.stc_id and a.stc_id = '%s'" % in_stc_id

    rows = db_class.executeAll(sql)

    # 조회된 건수 바탕으로 data 세팅 및 메시지 송신
    for row in rows:
        try:
            # 대상 데이터
            stc_id = row['stc_id']
            stc_name = row['stc_name']

            # 기존값
            old_now_price = row['now_price']
            old_ma5 = row['ma5']
            old_ma20 = row['ma20']
            old_ma60 = row['ma60']
            old_ma120 = row['ma120']
            old_ma240 = row['ma240']

            # 현재가 및 이동평균가격
            price_info = cal_move_avg_values(stc_id)
            now_price = price_info['now_price']
            ma5 = price_info['ma5']
            ma20 = price_info['ma20']
            ma60 = price_info['ma60']
            ma120 = price_info['ma120']
            ma240 = price_info['ma240']

            # 새로운 값 DB저장
            sql = "update stock_search.stock_move_avg " \
                  "set now_price = '%d', ma5 = '%d', ma20 = '%d', ma60= '%d', ma120 = '%d', ma240 = '%d'" \
                  "where stc_id = '%s'" % (now_price, ma5, ma20, ma60, ma120, ma240, stc_id)
            db_class.execute(sql)
            db_class.commit()

            # 메시지조합
            yn_now = False
            yn_5 = False
            yn_20 = False
            yn_60 = False
            yn_120 = False

            msg_temp = ""
            msg_now = ""
            msg_5 = ""
            msg_20 = ""
            msg_60 = ""
            msg_120 = ""

            # 현재가 5일선돌파
            if old_now_price <= old_ma5 and now_price > ma5:
                msg_temp = msg_temp + "5 "
                yn_now = True

            # 현재가 20일선돌파
            if old_now_price <= old_ma20 and now_price > ma20:
                msg_temp = msg_temp + "20 "
                yn_now = True

            # 현재가 60일선돌파
            if old_now_price <= old_ma60 and now_price > ma60:
                msg_temp = msg_temp + "60 "
                yn_now = True

            # 현재가 120일선돌파
            if old_now_price <= old_ma120 and now_price > ma120:
                msg_temp = msg_temp + "120 "
                yn_now = True

            # 현재가 240일선돌파
            if old_now_price <= old_ma240 and now_price > ma240:
                msg_temp = msg_temp + "240 "
                yn_now = True

            # 메시지 조립
            if yn_now:
                msg_now = "현재가: " + msg_temp + "일선 돌파! \n"
            msg_temp = ""

            # 5일선 20일선돌파
            if old_ma5 <= old_ma20 and ma5 > ma20:
                msg_temp = msg_temp + "20 "
                yn_5 = True

            # 5일선 60일선돌파
            if old_ma5 <= old_ma60 and ma5 > ma60:
                msg_temp = msg_temp + "60 "
                yn_5 = True

            # 5일선 120일선돌파
            if old_ma5 <= old_ma120 and ma5 > ma120:
                msg_temp = msg_temp + "120 "
                yn_5 = True

            # 5일선 240일선돌파
            if old_ma5 <= old_ma240 and ma5 > ma240:
                msg_temp = msg_temp + "240 "
                yn_5 = True

            # 메시지 조립
            if yn_5:
                msg_5 = "5일선: " + msg_temp + "일선 돌파! \n"
            msg_temp = ""

            # # 20일선 60일선돌파
            # if old_ma20 <= old_ma60 and ma20 > ma60:
            #     msg_temp = msg_temp+"60 "
            #     yn_20 = True

            # 20일선 120일선돌파
            if old_ma20 <= old_ma120 and ma20 > ma120:
                msg_temp = msg_temp + "120 "
                yn_20 = True

            # # 20일선 240일선돌파
            # if old_ma20 <= old_ma240 and ma20 > ma240:
            #     msg_temp = msg_temp+"240 "
            #     yn_20 = True

            # 메시지 조립
            if yn_20:
                msg_20 = "20일선: " + msg_temp + "일선 돌파! \n"
            msg_temp = ""

            # 60일선 120일선돌파
            if old_ma60 <= old_ma120 and ma60 > ma120:
                msg_temp = msg_temp + "120 "
                yn_60 = True

            # 60일선 240일선돌파
            if old_ma60 <= old_ma240 and ma60 > ma240:
                msg_temp = msg_temp + "240 "
                yn_60 = True

            # 메시지 조립
            if yn_60:
                msg_60 = "60일선: " + msg_temp + "일선 돌파! \n"
            msg_temp = ""

            # 120일선 240일선돌파
            if old_ma120 <= old_ma240 and ma120 > ma240:
                msg_temp = msg_temp + "240 "
                yn_120 = True

            # 메시지 조립
            if yn_120:
                msg_120 = "120일선: " + msg_temp + "일선 돌파! \n"

            # 최종 메시지 조립
            msg_final = msg_now + msg_5 + msg_20 + msg_60 + msg_120
            msg_final = msg_20

            # 메시지 송신
            # if yn_now or yn_5 or yn_20 or yn_60 or yn_120:
            if yn_20:

                # 데이터 세팅 및 텔레그램 메시지 송신
                msg = telegramModule.set_data(stc_id, stc_name, msg_final)
                telegramModule.send_message_to_friends(msg)

                # 결과저장
                sql = "insert into stock_search.stock_captured (capture_dttm, stc_id, price, capture_tcd, msg ) " \
                      "values('%s', '%s', '%d', '03', '%s')" % (now_time, stc_id, now_price, msg_final)
                db_class.execute(sql)
                db_class.commit()

        except Exception as ex:
            traceback.print_exc()

    db_class.commit()
    print("이평선 돌파 메시지 송신 완료")
    return