影刀RPA 基金净值定时抓取与定投提醒

📅 2026/7/14 18:23:24
影刀RPA 基金净值定时抓取与定投提醒
影刀RPA 基金净值定时抓取与定投提醒作者林焱基金定投是很多人的理财方式但手动查净值、算收益很麻烦。这篇讲用影刀定时抓取基金净值帮你自动监控定投状态。免费获取基金净值天天基金有免费接口同样不需要注册importrequestsdefget_fund_info(code):获取基金净值信息urlfhttps://fundgz.1234567.com.cn/js/{code}.jsheaders{Referer:https://fund.eastmoney.com/}resprequests.get(url,headersheaders)# 返回格式jsonpgz({fundcode:000001,name:...,gszzl:...});# 需要截取JSON部分importjson json_strresp.text[8:-2]# 去掉 jsonpgz( 和 );datajson.loads(json_str)[video(video-6XdZb0Fk-1784018910703)(type-csdn)(url-https://live.csdn.net/v/embed/526818)(image-https://v-blog.csdnimg.cn/asset/582d14c3bd0451c5399cd990b56e2a0d/cover/Cover0.jpg)(title-拼多多店群自动化报活动上架)]return{code:data[fundcode],name:data[name],nav:float(data[dwjz]),# 单位净值est_nav:float(data[gsz]),# 估算净值est_change:data[gszzl],# 估算涨跌幅date:data[jzrq],# 净值日期}infoget_fund_info(000001)print(f{info[name]}: 净值{info[nav]}估算{info[est_nav]}({info[est_change]}%))定投收益计算# 模拟定投记录影刀从Excel读取records[{date:2024-01-15,amount:1000,nav_buy:1.250},{date:2024-02-15,amount:1000,nav_buy:1.180},{date:2024-03-15,amount:1000,nav_buy:1.320},]total_investsum(r[amount]forrinrecords)total_sharessum(r[amount]/r[nav_buy]forrinrecords)![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/6eedb94220884a4b83ecda8616a727d7.png#pic_center)current_navget_fund_info(000001)[nav]current_valuetotal_shares*current_nav profitcurrent_value-total_invest profit_rate(profit/total_invest)*100print(f投入: ¥{total_invest})print(f市值: ¥{current_value:.2f})print(f盈亏: ¥{profit:.2f}({profit_rate:.2f}%))定投日提醒fromdatetimeimportdatetimedefis_dingtou_day():判断今天是否是定投日每月15号遇周末顺延todaydatetime.now()target_day15iftoday.daytarget_dayandtoday.weekday()5:returnTrue# 工作日# 15号是周末的话顺延到周一# 简化处理这里只做基础判断returnFalseifis_dingtou_day():# 推送提醒到微信/钉钉msg 今天是定投日记得操作send_notification(msg)踩坑实录坑1净值是T日确认基金的净值是按照T日交易日15:00前或T1日15:00后确认的。你看到的最新净值可能是昨天的。估算净值gsz只在交易时段有参考意义。坑2天天基金接口偶尔改格式天天基金这个jsonpgz(...)包装格式可能会变。代码里的[8:-2]切片依赖于固定长度。更安全的方式是用正则提取importre json_strre.search(rjsonpgz\((.*)\),resp.text).group(1)坑3估值和实际净值有偏差估算净值是基金公司公布的盘中估值和晚上公布的实际净值经常有偏差特别是持仓调整期间。不要把估值当实际净值做决策。TEMU店群矩阵自动化运营核价报活动坑4QDII基金延时问题QDII投资海外基金的净值确认有T2甚至T3的延时。你查到的净值可能是几天前的。扩展基金对比表影刀定时采集多只基金净值生成对比表funds[000001,005827,110011]# 3只基金comparison[]forcodeinfunds:infoget_fund_info(code)comparison.append({名称:info[name],净值:info[nav],![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/11bdbe9f65c94c8db6c6d8ebf0610a2b.png#pic_center)估算涨幅:info[est_change]%,})# comparison写入Excel# 自动生成对比图表写在最后基金监控的自动化比股票简单——不需要实时盯盘每天跑一次就够了。影刀定时触发 → 查净值 → 算收益 → 推送提醒就是一套完整的个人理财自动化系统。省钱的关键是知道了就执行定投日到了自动提醒而不是知道但不做。