基于tushare实现股票实时价格变动的监控并用itchat实现微信消息提醒
1.实时检查股票价格的函数
首先定义一个check函数用来检查指定股票code(例如格力电器000651)的股价是否低于或者高于设定的low值和high值,使用了ts的get_realtime_quotes的实时行情接口,如果突破相应的价格会返回相应的值,比如,低于low会返回0和当前股价。
import tushare as ts
import itchat
from datetime import *
def check(code, low, high):
df = ts.get_realtime_quotes(code)
e = df[['code', 'name', 'price', 'time']]
p = df[u'price']
if float(p[0]) < low:
return 0,float(p[0])
elif