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_bar
# 初始化
init_source("tushare")
# 查询股票列表
df = get_stock_list(list_status="L")
print(f"当前上市股票数量: {len(df)}")
# 查询日线数据 (symbol 格式: "代码.交易所")
df = get_stock_bar("600000.SH", frequency="1day", start_date="20260401", end_date="20260402")
print(df.head())
# 查询指数日线数据
df = get_index_bar("000300.SH", start_date="20260401", end_date="20260402")
print(df.head())
测试
pytest tests/ -v
pytest tests/test_tushare.py::TestTushareIntegration::test_get_stock_bar # 运行单个测试
输入参数格式说明
股票代码
symbol 参数统一使用 代码.交易所 格式:
| 交易所 | 代码 | 示例 |
|---|---|---|
| 上交所 | SH | 600000.SH |
| 深交所 | SZ | 000001.SZ |
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.4.tar.gz
(10.1 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
File details
Details for the file hqdata-0.1.4.tar.gz.
File metadata
- Download URL: hqdata-0.1.4.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d36e43dc5edf9ca62ac5fa1eb3941f0595f9fca5b9672672f15b7bd81cc5d0d0
|
|
| MD5 |
46f2e55bcc147fd83b4a163acafa3d3d
|
|
| BLAKE2b-256 |
118b6f1bbfb8e96b7b54b75b735ea8da6cc67bd359830775d32d5cd7522e2ec2
|
File details
Details for the file hqdata-0.1.4-py3-none-any.whl.
File metadata
- Download URL: hqdata-0.1.4-py3-none-any.whl
- Upload date:
- Size: 8.9 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 |
d5d982cb66f2f90f6a0123b17f9b579240d71b369b3df13faa9d63975544ca2f
|
|
| MD5 |
f089872f2c1ff3c57b232acf8aeca4a7
|
|
| BLAKE2b-256 |
767411bd0481d1f5e8676201304c9a9fb01e216c7c7870db2f69b36e25bc71e0
|