|
阅读:124回复:0
python使用yahoo的API获取股票数及预警
import yfinance as yf
import smtplib from email.mime.text import MIMEText # 获取股票数据 stock = yf.Ticker("AAPL") current_price = stock.history(period="1d")['Close'][0] # 预设的预警条件 warning_price = 150 # 例如当苹果股价超过150美元时触发预警 # 比对和发出警报 if current_price > warning_price: # 发送邮件作为警报 msg = MIMEText('Apple stock price has exceeded $150.') msg['Subject'] = 'Stock Price Alert' msg['From'] = 'your_email@example.com' msg['To'] = 'recipient_email@example.com' server = smtplib.SMTP('smtp.example.com') server.send_message(msg) server.quit() |
|
|