python 股票盯盤原始碼
這里需要填寫自己的郵件地址和客戶端授權碼,
#tushare股票價格自動監控
#需求:
#1.設定股票的賣出價
#2.買入的價格
#3.程式對價格進行監控
#4.當價格達到預定值時發送郵件提醒
import tushare #使用股票檢測模塊
import time #使用時間模塊
import smtplib #smtp 協議包
from email.mime.text import MIMEText #用于構建郵箱內容
def gupiao(msg):
msg_from="" #發件人
password="" #客戶端授權碼
msg_to="" #收件人
#構建郵箱內容
if msg==1:
subject="買入"
content="趕緊買入"
elif msg==2:
subject="賣出"
content="趕緊賣出"
#構建msg郵件內容物件
msg=MIMEText(content)
msg["Subject"]=subject
msg["From"]=msg_from
msg["To"]=msg_to
#發送郵件
#smtplib.SMTP_SSL("發件人郵件服務器地址",埠號)
smtpObj=smtplib.SMTP_SSL("smtp.163.com",465)
smtpObj.login(msg_from,password)
smtpObj.sendmail(msg_from,msg_to,str(msg))
print("發送成功")
smtpObj.quit()
def jiege():
hao=input("請輸入股票號:")
data=tushare.get_realtime_quotes(hao) #股票號
name=data.loc[0][0]#股票名稱
pre_close=float(data.loc[0][2])#昨日收盤價
price=float(data.loc[0][3])#現價
change=round((price-pre_close)/pre_close,4)#今日漲幅
msg="股票名稱:"+name+",當前價格:"+str(price)+"元,漲幅:"+str(change*100)+"%"
print(msg)
return price
price=jiege()
buyPoint=float(input("請輸入買入價格:")) #模擬買入價格
salePoint=float(input("請輸入賣出價格:")) #模擬賣出價格
se=int(input("請輸入提醒間隔時間(秒):")) #提醒間隔時間
while 1==1:
if price<=buyPoint:
msg=1
print("價格達到買點,可以買入!!")
gupiao(msg)
elif price>=salePoint:
msg=2
print("價格達到買點,請及時賣出!!")
gupiao(msg)
else:
print("不要做操作")
time.sleep(se)#睡眠時間單位為秒,這里建議調成3秒
python打包成exe
安裝打包模塊
pip install pyinstaller
打開Windows powershell

進入python檔案目錄
pyinstaller -F 檔案名

打開dist檔案夾

達到買點或賣點會發送郵件提醒

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/296955.html
標籤:其他
