테더(USDT) 코인의 김치프리미엄이 특정 퍼센트를 초과할 때 이메일로 알림을 보내는 파이썬 프로그램을 만들어보겠습니다.
🔹 개발 과정
- 김치프리미엄 계산
- 한국(KRW) 거래소와 해외(USD) 거래소의 USDT 가격을 비교
- 김치프리미엄 공식: 김치 프리미엄(%)=(한국 USDT 가격−해외 USDT 가격×환율해외 USDT 가격×환율)×100\text{김치 프리미엄} (\%) = \left( \frac{\text{한국 USDT 가격} - \text{해외 USDT 가격} \times \text{환율}}{\text{해외 USDT 가격} \times \text{환율}} \right) \times 100
 
- 환율 정보 가져오기
- 네이버 금융 API 또는 환율 API 활용
 
- 이메일 전송
- smtplib 모듈을 사용하여 특정 조건 충족 시 알림 메일 전송
 
- 자동 실행
- schedule 모듈을 사용하여 주기적으로 확인
 
필요한 라이브러리 설치
- 
- 
bashCopyEditpip install requests schedule smtplib
 
- 
🔹 코드 구현
- 
- 
import requests
 import schedule
 import smtplib
 from email.mime.text import MIMEText
 from time import sleep
 # 🔹 1. 거래소 API를 통해 가격 가져오기
 def get_usdt_price():
 try:
 # 업비트 USDT/KRW 가격 가져오기
 upbit_url = "https://api.upbit.com/v1/ticker?markets=USDT-KRW"
 upbit_price = requests.get(upbit_url).json()[0]["trade_price"]
 # 바이낸스 USDT/USD 가격 가져오기
 binance_url = "https://api.binance.com/api/v3/ticker/price?symbol=USDTUSDT"
 binance_price = requests.get(binance_url).json()["price"]
 binance_price = float(binance_price)
 return upbit_price, binance_price
 except Exception as e:
 print(f"데이터 가져오기 오류: {e}")
 return None, None
 # 🔹 2. 환율 정보 가져오기
 def get_exchange_rate():
 try:
 url = "https://api.exchangerate-api.com/v4/latest/USD"
 response = requests.get(url).json()
 return response["rates"]["KRW"]
 except Exception as e:
 print(f"환율 가져오기 오류: {e}")
 return None
 # 🔹 3. 김치 프리미엄 계산
 def calculate_premium():
 upbit_price, binance_price = get_usdt_price()
 exchange_rate = get_exchange_rate()
 if None in (upbit_price, binance_price, exchange_rate):
 return None
 premium = ((upbit_price - (binance_price * exchange_rate)) / (binance_price * exchange_rate)) * 100
 return premium
 # 🔹 4. 이메일 전송
 def send_email(premium):
 sender_email = "your_email@gmail.com"
 sender_password = "your_app_password"
 recipient_email = "recipient_email@gmail.com"
 subject = "🚨 김치 프리미엄 알림!"
 message = f"현재 김치 프리미엄이 {premium:.2f}%를 초과했습니다! 거래를 고려해보세요."
 msg = MIMEText(message)
 msg["Subject"] = subject
 msg["From"] = sender_email
 msg["To"] = recipient_email
 try:
 server = smtplib.SMTP_SSL("smtp.gmail.com", 465)
 server.login(sender_email, sender_password)
 server.sendmail(sender_email, recipient_email, msg.as_string())
 server.quit()
 print("📧 이메일 전송 완료!")
 except Exception as e:
 print(f"이메일 전송 실패: {e}")
 # 🔹 5. 특정 김치 프리미엄 이상일 때 이메일 알림
 def check_premium():
 premium = calculate_premium()
 if premium is not None:
 print(f"현재 김치 프리미엄: {premium:.2f}%")
 if premium > 5: # 5% 이상이면 이메일 전송
 send_email(premium)
 # 🔹 6. 10분마다 체크하도록 스케줄링
 schedule.every(10).minutes.do(check_premium)
 print("🔄 김치 프리미엄 모니터링 시작!")
 while True:
 schedule.run_pending()
 sleep(60)
 
- 
🔹 실행 방법
- 
- 
- 이메일 발신을 위해 구글 앱 비밀번호를 생성해야 합니다.
- Google 계정 보안 설정 → "앱 비밀번호"에서 생성 후 사용
 
- your_email@gmail.com 및 recipient_email@gmail.com을 본인의 이메일로 변경
- 특정 퍼센트(예: 5%) 초과 시 자동 이메일 발송
 
- 이메일 발신을 위해 구글 앱 비밀번호를 생성해야 합니다.
 
- 
🔹 기능 요약
✅ 실시간 김치 프리미엄 계산
✅ 특정 퍼센트 초과 시 이메일 자동 전송
✅ 10분마다 자동 체크
이제 실행하면 김치 프리미엄이 일정 퍼센트를 넘을 때 이메일로 자동 알림을 받게 됩니다!