这几天对量化交易颇感兴趣,所以就鼓捣了一下,网上搜索一波发现,Tushare是一个开源的股票信息来源,可以轻松地获取股票信息,Tushare主页:http://tushare.org/ ,目前主要是通过Tushare的实时分笔来获取当前时间的股票信息,主要是用来实时监控特定股票出现日内暴跌和日内较开盘价大幅下跌,后期还会添加更多内容。废话不多说,直接上代码。
import tushare as ts#导入tushare模块
import datetime
import time
#导入纯文本邮件发送模块
import my_email as me
#实时监测函数,code为6位数字代码字符串组成的数组,监测在10分钟内跌幅大于5%和实时跌幅较开盘价大于10%时,发送邮件通知
#time_mins为跌速时间,change_mins_max为跌速深度,change_max为较开盘跌幅
def monitor(code,time_mins = 10,change_mins_max = 5,change_max = 10):
data_today = []#储存采集回来的数据
n = 1#记录从循环次数
while 1:
try:
now_time = datetime.datetime.strptime(datetime.datetime.strftime(datetime.datetime.now(),'%H:%M:%S'),'%H:%M:%S')
#now_time为记录当前时间,由于从Tushare取回的实时分笔数据只有时间,
#没有日期,所以用上面的操作把现在的时间的日期换成1900:1:1日,方便计算时间差
rest_time = now_time - datetime.datetime.strptime('11:30:00','%H:%M:%S')
#用来计算当前时间和中午11:30休市时间的差值
if rest_time.days == 0 and rest_time.seconds > 0 and rest_time.seconds < 5400:
#中午11:30~13:00为中午休市时间,时长5400 seconds
print('中午休市时间')
while r