import os as _os, sys as _sys _sys.path.insert(0, _os.path.dirname(_os.path.dirname(_os.path.abspath(__file__)))) import os from dotenv import load_dotenv load_dotenv() import oracledb conn = oracledb.connect(user=os.getenv('ORACLE_USER'), password=os.getenv('ORACLE_PASSWORD'), dsn=os.getenv('ORACLE_DSN'), config_dir=os.getenv('ORACLE_WALLET')) cur = conn.cursor() for ticker in ['KRW-DKA', 'KRW-LAYER', 'KRW-SIGN']: cur.execute(""" SELECT price, recorded_at FROM price_history WHERE ticker = :t AND recorded_at >= TIMESTAMP '2026-02-28 20:00:00' ORDER BY recorded_at """, t=ticker) rows = cur.fetchall() lookback = 12 # 10분봉 * 12 = 2h gains = [] for i in range(lookback, len(rows)): curr = rows[i][0] past = rows[i - lookback][0] if past > 0: gains.append((curr - past) / past * 100) if not gains: continue above_5 = sum(1 for g in gains if g >= 5.0) above_3 = sum(1 for g in gains if g >= 3.0) above_0 = sum(1 for g in gains if g >= 0.0) negative = sum(1 for g in gains if g < 0.0) print(f"[{ticker}] 2h 등락률 분포 ({len(gains)}개 틱)") print(f" 평균={sum(gains)/len(gains):+.2f}% 최고={max(gains):+.2f}% 최저={min(gains):+.2f}%") print(f" +5% 이상(신호): {above_5}건 ({above_5/len(gains)*100:.0f}%)") print(f" +3%~+5%: {above_3-above_5}건 ({(above_3-above_5)/len(gains)*100:.0f}%)") print(f" 0%~+3%: {above_0-above_3}건 ({(above_0-above_3)/len(gains)*100:.0f}%)") print(f" 음전(하락): {negative}건 ({negative/len(gains)*100:.0f}%)") print() conn.close()