A股历史与实时行情数据统一接入、清洗与存储
Project description
hqdata - A股历史与实时行情数据统一接入、清洗与存储
定位
hqdata 是 HonestQuant 量化系统的数据基础层,职责边界清晰:
- 对下:封装各数据源 SDK,屏蔽接口差异
- 对上:提供统一的查询接口
- 上层策略和引擎只调用
hqdata.api,不直接接触任何数据源
支持的数据源
| 数据源 | 状态 | 说明 |
|---|---|---|
| AKShare | 计划中 | 免费,实时数据 |
| Tushare | 已接入 | 需满足账户积分要求,支持股票&指数的历史日线 |
| 米筐 | 已接入 | 需license,支持日线/分钟线(不支持月线/暂时不支持tick) |
| 迅投 | 计划中 | 需迅投终端 |
| iTick | 计划中 | 需注册 |
安装
方式一:通过pip安装
# 基础安装(仅包含核心功能)
pip install hqdata
# 按需安装数据源依赖
pip install hqdata[tushare] # Tushare 支持
pip install hqdata[ricequant] # 米筐支持
pip install hqdata[tushare,ricequant] # 同时安装两者
# 复制模板并自行填入所需字段
cp .env.example .env # 放在你运行 Python 代码的当前目录(优先)/包安装目录
方式二:本地开发
# 创建虚拟环境
python -m venv .venv
source .venv/bin/activate
# 安装依赖 (editable 模式,改代码直接生效)
pip install -e .
# 复制模板并自行填入所需字段
cp .env.example .env # 放在你运行 Python 代码的当前目录(优先)/包安装目录
使用
以 Tushare 为例:
from hqdata import init_source, get_stock_list, get_stock_bar, get_index_list, get_index_bar
# 初始化 Tushare
init_source("tushare")
# 查询股票列表 (支持4种过滤参数,只返回当天上市状态的股票)
get_stock_list()
get_stock_list(symbol="000001.SZ")
get_stock_list(symbol="000001.SZ,600000.SH")
get_stock_list(exchange="SSE")
get_stock_list(exchange="SSE,SZSE")
get_stock_list(market="MB")
get_stock_list(market="MB,GEM,STAR")
# 查询股票日线数据
get_stock_bar("000001.SZ", frequency="day", start_date="20260101", end_date="20260401")
get_stock_bar("000001.SZ,600000.SH", frequency="day", start_date="20260101", end_date="20260401")
# 查询指数列表
get_index_list(symbol="000300.SH")
get_index_list(symbol="000300.SH,000905.SH")
get_index_list(market="SSE")
get_index_list(market="SSE,SZSE")
get_index_list(symbol="000300.SH", market="SZSE") # 同时传入symbol和market, 只有symbol字段会生效
# 查询指数日线数据
get_index_bar("000300.SH", start_date="20260101", end_date="20260401")
get_index_bar("000300.SH,000905.SH", start_date="20260330", end_date="20260401")
以 米筐 为例:
from hqdata import init_source, get_stock_list, get_stock_bar, get_index_list, get_index_bar
# 初始化米筐(推荐 license key 方式)
init_source("ricequant", license_key="your_license_key")
# 或用户名密码方式
init_source("ricequant", username="your_email", password="your_password")
# 查询股票列表(只返回当天上市状态的股票,不支持 BJ 板块)
get_stock_list()
get_stock_list(symbol="000001.SZ,600000.SH")
get_stock_list(exchange="SSE")
get_stock_list(market="MB,GEM,STAR")
# 查询股票行情(支持日线/分钟线/周线,不支持月线和tick)
get_stock_bar("000001.SZ", frequency="day", start_date="20260101", end_date="20260401")
get_stock_bar("000001.SZ,600000.SH", frequency="5m", start_date="20260101", end_date="20260401")
# 查询指数列表(market 仅支持 SSE/SZSE)
get_index_list(symbol="000300.SH")
get_index_list(market="SSE")
# 查询指数日线数据
get_index_bar("000300.SH", start_date="20260101", end_date="20260401")
get_index_bar("000300.SH,000905.SH", start_date="20260330", end_date="20260401")
测试
pytest tests/ -v # 运行全部测试
pytest tests/test_tushare.py::TestTushareIntegration::test_get_stock_bar_single_symbol # 运行单个测试
输入参数说明
symbol(股票代码)
symbol 参数统一使用 交易所简写代码 作为后缀:
| 交易所 | 交易所简写代码 | 示例 |
|---|---|---|
| 上交所 | SH | 600000.SH |
| 深交所 | SZ | 000001.SZ |
start_date / end_date(日期区间)
日期格式为 YYYYMMDD,如 20260401 表示 2026年4月1日。
start_date:开始日期(包含)end_date:结束日期(包含)
frequency(频率)
| 值 | 说明 |
|---|---|
tick |
实时 |
1m |
1分钟线 |
5m |
5分钟线 |
15m |
15分钟线 |
30m |
30分钟线 |
60m |
60分钟线 |
day |
日线(默认) |
week |
周线 |
month |
月线 |
exchange(交易所)
| 交易所 | 代码 | 说明 |
|---|---|---|
| 上交所 | SSE | 上海证券交易所 |
| 深交所 | SZSE | 深圳证券交易所 |
| 北交所 | BSE | 北京证券交易所 |
market(市场板块)
market 参数需根据具体接口确定,参见各接口说明。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hqdata-0.1.9.tar.gz
(16.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
hqdata-0.1.9-py3-none-any.whl
(14.2 kB
view details)
File details
Details for the file hqdata-0.1.9.tar.gz.
File metadata
- Download URL: hqdata-0.1.9.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c24855953c182d9ab41f02dd9d9e131918983eb8a0335060e3748f61101e4f6c
|
|
| MD5 |
eaa8d606daccb208b33eb99158ee26a8
|
|
| BLAKE2b-256 |
4e720a03013e3313aad6e7389bfaa7415ab43f21f43bb37dfdb57b3eb3a4af0b
|
File details
Details for the file hqdata-0.1.9-py3-none-any.whl.
File metadata
- Download URL: hqdata-0.1.9-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
009e35cb30ec4de88dd71abfdef25c1e5708484852b53886a571c29467377647
|
|
| MD5 |
16940338c44a21857f98d64d8c71a634
|
|
| BLAKE2b-256 |
48b959756f6edb30319ea62b3c8b319e8f4da3e2461f141e8859e8e42031728d
|