Files
auto-stock/backend/insert_test_data.py
2025-11-14 11:05:31 +09:00

58 lines
2.2 KiB
Python

"""
테스트용 샘플 분석 데이터 생성 스크립트
실제 배치 대신 테스트용 데이터를 DB에 넣습니다.
"""
import psycopg2
from datetime import date
# DB 연결
conn = psycopg2.connect(
host="shium.net",
port=55432,
database="stock",
user="stock_admin",
password="stock_pass"
)
cur = conn.cursor()
# 테스트 데이터
test_data = [
('005930', '삼성전자', 58100, -1.11, 20000000, 22.5, 61200, 65400, 68200, 14.5, 18.2, 72000, 58000, 64500, ['RSI 과매도', '스토캐스틱 과매도'], 3),
('122630', 'KODEX 레버리지', 41140, -3.52, 40000000, 25.9, 43200, 45100, 47800, 21.9, 24.1, 49000, 39000, 44000, ['RSI 과매도', '스토캐스틱 과매도'], 3),
('462330', 'KODEX 2차전지산업레버리지', 1690, -6.63, 50000000, 20.5, 1850, 1920, 2100, 29.4, 32.1, 2200, 1600, 1900, ['RSI 과매도', '볼린저밴드 하단'], 3),
('000660', 'SK하이닉스', 179000, -2.15, 15000000, 28.3, 185000, 192000, 198000, 18.5, 22.3, 205000, 172000, 188500, ['RSI 과매도'], 2),
('035720', '카카오', 42500, 1.43, 8000000, 52.1, 41800, 40200, 38500, 65.2, 68.1, 46000, 38000, 42000, ['RSI 중립-상승', '골든크로스'], 2),
]
today = date.today()
print(f"🚀 Inserting test data for {today}...")
for stock in test_data:
cur.execute("""
INSERT INTO stock_analysis (
stock_code, stock_name, analysis_date, current_price, change_rate, volume,
rsi, ma5, ma20, ma60, stochastic_k, stochastic_d,
bollinger_upper, bollinger_lower, bollinger_middle,
signals, score
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
ON CONFLICT DO NOTHING
""", (
stock[0], stock[1], today, stock[2], stock[3], stock[4],
stock[5], stock[6], stock[7], stock[8], stock[9], stock[10],
stock[11], stock[12], stock[13], stock[14], stock[15]
))
print(f" ✅ {stock[0]} ({stock[1]})")
conn.commit()
cur.close()
conn.close()
print(f"\n✅ Test data inserted successfully!")
print(f"📊 Total: {len(test_data)} stocks")
print(f"\nNow test the API:")
print(f" GET http://localhost:8000/api/v1/recommendations/rule-based")