本文介绍如何为博客添加自动更新基金持仓盈亏的页面。通过使用天天基金的API接口,实现分散持仓的统一查看。方案包含三个文件:
1. **update_funds.php**:PHP脚本,用于定期从天天基金API获取最新净值并更新本地数据文件。
2. **funds.json**:JSON格式的数据文件,存储基金名称、代码、成本价、份额等手动配置信息,脚本会自动更新最新净值和更新时间。
3. **前端模板文件**:用于展示持仓信息,读取funds.json计算收益和收益率。
使用方法:将脚本部署到支持PHP的服务器,配置funds.json中的持仓信息,可设置计划任务定期执行更新。新增`update_enabled`字段可控制是否跳过某只基金的更新(如清仓后)。前端通过读取JSON文件动态展示持仓盈亏情况。
阅读更多Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick Start
Create a new post
1 | $ hexo new "My New Post" |
More info: Writing
Run server
1 | $ hexo server |
More info: Server
Generate static files
1 | $ hexo generate |
More info: Generating
Deploy to remote sites
1 | $ hexo deploy |
More info: Deployment