Files
stock_system/README.md

94 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# A股历史数据获取系统
获取所有A股从2010年至今的历史行情数据。
## 环境配置
```bash
# 创建conda环境
conda create -n stock_system python=3.10 -y
conda activate stock_system
# 安装依赖
pip install -r requirements.txt
```
## Tushare Token
**必须先设置Token才能运行**
需要在 tushare.pro 注册并获取token。
设置方式(三选一):
### 方式1环境变量推荐
```bash
export TUSHARE_TOKEN=your_token_here
python fetch_history.py
```
### 方式2配置文件
```bash
echo 'your_token_here' > config.txt
python fetch_history.py
```
### 方式3代码中直接设置
```python
# 编辑 fetch_history.py在 main() 函数中修改
pro = setup_tushare(token='your_token_here')
```
**注册地址**https://tushare.pro/register
## 运行
```bash
# 方式1直接运行
python fetch_history.py
# 方式2使用脚本
bash run.sh
```
## 数据说明
- 数据来源Tushare Pro API
- 时间范围2010-01-01 至今
- 数据格式:
- parquet高效压缩格式推荐
- CSV通用格式
## 输出字段
| 字段 | 说明 |
|------|------|
| ts_code | 股票代码 |
| trade_date | 交易日期 |
| open | 开盘价 |
| high | 最高价 |
| low | 最低价 |
| close | 收盘价 |
| pre_close | 昨收价 |
| change | 涨跌额 |
| pct_chg | 涨跌幅(%) |
| vol | 成交量(手) |
| amount | 成交额(千元) |
## 目录结构
```
stock_system/
├── A股股票列表.csv # 股票列表
├── fetch_history.py # 数据获取脚本
├── requirements.txt # Python依赖
├── run.sh # 运行脚本
├── data/ # 数据保存目录
└── logs/ # 日志目录
```
## 注意事项
1. Tushare有请求频率限制代码中设置了间隔
2. 全量获取约5000只股票数据需要较长时间
3. 建议在网络稳定的环境下运行