python实现1分钟内股价波动邮件提示

本文介绍了如何使用Python结合tushare库实时监控股票价格,通过计算1分钟内的股价波动,并利用SMTP发送邮件进行自动提示。教程涵盖了设置邮箱信息、定时函数的编写以及交易时间内的脚本运行策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、通过tushare接口实时监控股票价格

1. 通过get_realtime_quotes获得股票的开盘价与实时价格

def get_open_price(code): #获得开盘价
    df = ts.get_realtime_quotes(code)
    open_price=df['open'][0]
    return float(open_price)
def get_price(code): #获得股票实时价格
    df = ts.get_realtime_quotes(code)
    price=df['price'][0]
    return float(price)

2. 计算1min时间内的股价波动

def cal_fluctuation(price_1min_ago,cur_price): #计算股票每分钟浮动比例
    fluctuation=float((cur_price-price_1min_ago)/price_1min_ago)
    return fluctuation

3. 编写自动定时函数实现固定1min间隔循环

def runTask(code,name,day=0, hour=0, min=0, second=0):
    # Init time
    now = datetime.now()#获取当前时间
    strnow = now.strftime('%Y-%m-%d %H:%M:%S')
    #print("now:", strnow)
    # First next run time
    period = timedelta(days=day, hours=hour, minutes=min, seconds=second)#获取时间间隔
    next_time = now + period
    strnext_time = next_time.strftime('%Y-%m-%d %H:%M:%S')
    #print("next run:", strnext_time)
    price_1min_ago=get_price(code)
    price_2min_ago = get_price(code)
    open_price=get_open_price(code)
    if open_price==0
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值